Win32 Assembly – Part-3

w32

Note: Visit Win32 Assembly – Part 2 before proceeding.

Tools of trade:  Masm32 & WinAsm

Output: 

3

Template: ( from Part-2 )

.386
.model flat, stdcall
option casemap:none

include    windows.inc
include    kernel32.inc
include    user32.inc
includelib kernel32.lib
includelib user32.lib

DialogProc Proto :DWORD, :DWORD, :DWORD, :DWORD

.data?
hInstance HINSTANCE ?

.code
Start:

invoke GetModuleHandle,NULL
mov hInstance,eax
invoke DialogBoxParam,hInstance,1001,NULL,Addr DialogProc,NULL
invoke ExitProcess,0



DialogProc Proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM

.if uMsg == WM_COMMAND


.elseif uMsg == WM_CLOSE
 invoke EndDialog,hWnd,NULL

.else
 mov eax,FALSE
 ret

.endif
 mov eax, TRUE
 Ret
DialogProc endp

End Start

Code:

.386
.model flat, stdcall
option casemap:none

include    windows.inc
include    kernel32.inc
include    user32.inc
includelib kernel32.lib
includelib user32.lib
include    gdi32.inc
includelib gdi32.lib

DialogProc Proto :DWORD, :DWORD, :DWORD, :DWORD

.data
WindowTitle db "Win32 ASM Part-3",0
MessageText1 db "What is FUN?",0
MessageText2 db "Learning Assembly is FUN",0

.data?
hInstance HINSTANCE ?

.code
Start:

invoke GetModuleHandle,NULL
mov hInstance,eax
invoke DialogBoxParam,hInstance,1001,NULL,Addr DialogProc,NULL
invoke ExitProcess,0



DialogProc Proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM

.if uMsg == WM_COMMAND
 
    mov eax, wParam
 
    .if eax == 1003
 
       invoke SetDlgItemText,hWnd,1002,Addr MessageText2
 
    .elseif eax == 1004
 
       invoke SendMessage,hWnd,WM_CLOSE,NULL,NULL
 
    .endif
 

.elseif uMsg == WM_INITDIALOG
 
    invoke SetWindowText,hWnd,Addr WindowTitle
    invoke SetDlgItemText,hWnd,1002,Addr MessageText1

.elseif uMsg == WM_CLOSE
    invoke EndDialog,hWnd,NULL

.else
    mov eax,FALSE
    ret

.endif
    mov eax, TRUE
    Ret
DialogProc endp

End Start

Description:

includelib gdi32.lib
The file gdi contains function for windows graphics device interface.
It is associated with drawing applications and font management.

elseif uMsg == WM_INITDIALOG
WM_INITDIALOG
This msg is sent to the dialog box before dialog box is displayed. 
Typically, Dialog Box use this msg to initialize controls and do 
tasks such as appearance,etc before the dialog box is displayed.

invoke SetWindowText,hWnd,Addr WindowTitle
SetWindowText
This changes the text of specified window title bar if it has any. 
It also changes the text of any control also.

hWnd
We have already discussed in previous tuts. 

Addr WindowTitle
This is the address of the WindowTitle variable which is defined in
data section.

Output till now:
1

invoke SetDlgItemText,hWnd,1002,Addr MessageText1
SetDlgItemText
Sets the text or title of any control in dialog box

1002
It is the ID of the edit/text box.

Addr Messagetext1
This is the address of the Messagetext1 variable which is defined in
data section.

Output till now:
2

invoke SetDlgItemText,hWnd,1002,Addr MessageText2
SetDlgItemText is invoked the change the text in editbox when click
button is pressed.

Final Output:
3


Note: If you have any doubt, ask in the comment section. It will help others also.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s