Você está na página 1de 12

td_win32asm_010.

asm
;==============================================================================
;
Test Department's WINDOWS 32 BIT x86 ASSEMBLY EXAMPLE'S
010
;==============================================================================
;==============================================================================
; ==> Part 010 : child windows with a predefined class name ( BUTTON )
;-----------------------------------------------------------------------------; In this easy tutorial 010 we create child windows ( API=CreateWindowEx ) with
; a predefined window class ( BUTTON, LISTBOX, EDITBOX... ), here BUTTON.
; We create our child windows in the window procedure ( WP1 ) "lpfnWndProc"
; reacting to a WM_CREATE message.
; "lpfnWndProc" is a pointer to the subroutine label "WindowProc" ( WP1 ) where
; all the action code for this main window resist.
; "lpfnWndProc" is part of WndClassEx structure used by API RegisterClassEx.
;==============================================================================
; Assembler directives
;-----------------------------------------------------------------------------.386
; specifies the processor our program want run on
.Model Flat ,StdCall
; always the same for Win95 (32 Bit)
option casemap:none
; case sensitive !!!
;==============================================================================
; Include all files where API functins resist you want use
; You must set the correct path to the include and library files
;-----------------------------------------------------------------------------include D:\Masm32\include\windows.inc
includelib kernel32.lib
includelib user32.lib
;==============================================================================
; Declaration of used API functions,take a look into WIN32.HLP and *.inc files
; GetModulHandle= example of an API function
; PROTO
= one or more parameter must pushed to the stack before call
; :DWORD
= the parameter, in this case doubleword (32 Bit)
;-----------------------------------------------------------------------------GetModuleHandleA
PROTO :DWORD
LoadIconA
PROTO :DWORD,:DWORD
LoadCursorA
PROTO :DWORD,:DWORD
RegisterClassExA
PROTO :DWORD
CreateWindowExA
PROTO :DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD,
:DWORD,:DWORD,:DWORD,:DWORD,:DWORD
ShowWindow
PROTO :DWORD,:DWORD
UpdateWindow
PROTO :DWORD
GetMessageA
PROTO :DWORD,:DWORD,:DWORD,:DWORD
TranslateMessage
PROTO :DWORD
DispatchMessageA
PROTO :DWORD
PostQuitMessage
PROTO :DWORD
DefWindowProcA
PROTO :DWORD,:DWORD,:DWORD,:DWORD
ExitProcess
PROTO :DWORD
MessageBoxA
PROTO :DWORD,:DWORD,:DWORD,:DWORD
DestroyWindow
PROTO :DWORD
SendMessageA
PROTO :DWORD,:DWORD,:DWORD,:DWORD
Page 1

td_win32asm_010.asm
;==============================================================================
; .const
= the constants area starts here,constants are defined & fixed
; example_const = the constant name
; equ
= the value for this constant name follows
; 0Ah
= the value in hexadezimal
;-----------------------------------------------------------------------------.const
example_const
equ 0Ah
;not used, example only
; - Parameter MAIN WINDOW CallBack Procedure ( API=RegisterClassExA ) WP1_CallBack
equ [ebp+4]
;return address
WP1_hWnd
equ [ebp+8]
;handle of window who receives message
WP1_uMsg
equ [ebp+12]
;the message number
WP1_wParam
equ [ebp+16]
;extra info about the message
WP1_lParam
equ [ebp+20]
;extra info about the message
;==============================================================================
; .Data
= the data area starts here, datas are defined but not fixed
; db
= byte
1 Byte ( 8 Bit)
; dw
= word
2 Byte (16 Bit)
; dd
= doubleword
4 Byte (32 Bit)
; Textstrings are databyte and must be terminated by ,0
; ,13,10 means control and line feed
; db 41h dup (0)= reserved 41 hexadezimal databytes initialized to 0
;-----------------------------------------------------------------------------.Data
example_text
db "First row",13,10
;not used,example only
db "Second row",0
;
IconName
db "TDIcon",0
;icon name in rc file
MenuName
db "TDMenu",0
;menu name in rc file
ClassName
db "TDWinClass",0
;name of windows class
WindowName
db "Test Department",0
;window name titel bar
Bu00_ClassName
db "BUTTON",0
;predefined ClassName !!!
Bu00_WindowName
db "PUSHBUTTON",0
;button text
Bu01_WindowName
db "DEFPUSHBUTTON",0
;button text
Bu08_WindowName
db "USERBUTTON",0
;button text
Bu02_WindowName
db "CHECKBOX",0
;button text
Bu03_WindowName
db "AUTOCHECKBOX",0
;button text
Bu04_WindowName
db "RADIOBUTTON",0
;button text
Bu09_WindowName
db "AUTORADIOBUTTON",0
;button text
Bu05_WindowName
db "3STATE",0
;button text
Bu06_WindowName
db "AUTO3STATE",0
;button text
Bu07_WindowName
db "GROUPBOX",0
;button text
MB1Titel
db "Realy Exit ?",0
;message box titel
MB1Text
db "Your choice ...",0
;message box text
MB2Titel
db "Message Box",0
;message box titel
MB2Text
db "BUTTON clicked",0
;message box text
defpushbutton0100_hWnd dd 0h
;handle's
pushbutton0200_hWnd
dd 0h
userbutton0300_hWnd
dd 0h
checkbox0400_hWnd
dd 0h
autocheckbox0500_hWnd
dd 0h
radiobutton0600_hWnd
dd 0h
Page 2

td_win32asm_010.asm
autoradiobutton0700_hWnd dd 0h
threestate0800_hWnd
dd 0h
auto3state0900_hWnd
dd 0h
groupbox0A00_hWnd
dd 0h
autoradiobutton0A10_hWnd dd 0h
autoradiobutton0A20_hWnd dd 0h
autoradiobutton0A30_hWnd dd 0h
align 4
; - WndClassEx Structure ( API=RegisterClassExA ) cbSize
dd 0h
;size in bytes of this structure
style
dd 0h
;window style
lpfnWndProc
dd 0h
;address of user proc function
cbclsExtra
dd 0h
;extra bytes to allocate set to 0
cbWndExtra
dd 0h
;extra bytes class directive, rc file
hInstance
dd 0h
;program handle(API=GetModuleHandleA)
hIcon
dd 0h
;handle of icon (API=LoadIconA)
hcursor
dd 0h
;handle of cursor (API=LoadCursor)
hbrBackground
dd 0h
;background color, 0=transparent
lpszMenuName
dd 0h
;name of menu class in resource file
lpszClassName
dd 0h
;name of windows this window class
hIconSm
dd 0h
;iconhandle 0=search in resource file
align 4
; - Msg Structure ( API=GetMessageA ) - member POINT = POINT structure
hWnd
dd 0h
;handle of window who receives message
message
dd 0h
;the message number
wParam
dd 0h
;extra info about the message
lParam
dd 0h
;extra info about the message
time
dd 0h
;time the message was posted
xpt
dd 0h
;cursor x-position, POINT struc
ypt
dd 0h
;cursor x-position, POINT struc
;==============================================================================
; .Data? = the data? area starts here, not defined and not fixed
;-----------------------------------------------------------------------------.data?
;==============================================================================
; .CODE = our code area starts here
Main = label of our program code
;-----------------------------------------------------------------------------.Code
Main:
;==============================================================================
; Always get your program ID first (API=GetModuleHandleA)
;-----------------------------------------------------------------------------push
0h
;lpModuleHandle, 0=get program handle
call
GetModuleHandleA
;- API Function mov
hInstance,eax
;return value in eax=handle of program
;==============================================================================
; The API function "RegisterClassExA" registers a window class
Page 3

td_win32asm_010.asm
; This API needs a "WNDCLASSEX" structure so we fill it with correct values
;-----------------------------------------------------------------------------mov
cbSize,30h
;size in bytes of WNDCLASSEX structure
mov
style,3h
;window style
mov
lpfnWndProc,OFFSET WP1
;address of user lpfnWndProc function
mov
cbclsExtra,0h
;extra bytes to allocate set to 0
mov
cbWndExtra,0h
;class directive in rc file
mov
hbrBackground,10h
;background,1=background(parameter+1)
mov
lpszMenuName,OFFSET MenuName
;menu name in resource file
mov
lpszClassName,OFFSET ClassName ;name of windows class
mov
hIconSm,0h
;iconhandle 0=search in rc file
;-----------------------------------------------------------------------------; API "LoadIconA" loads an icon defined in the resource file and store the
; handle in the "WNDCLASSEX" structure
;-----------------------------------------------------------------------------push
OFFSET IconName
;icon-string or icon resource id
push
hInstance
;our program handle
call
LoadIconA
;- API Function mov
hIcon,eax
;handle of newly loaded icon
;-----------------------------------------------------------------------------; API "LoadCursorA" loads a default system cursor, in this case we must set
; hInstance to 0 and lpCursorName to a default system cursor value, here 32512
; Then we store the cursor handle in the "WNDCLASSEX" structure
;-----------------------------------------------------------------------------push
32512
;lpCursorName,default value in dezimal
push
0h
;hInstance, 0=default system cursor
call
LoadCursorA
;- API Function mov
hcursor,eax
;handle of the cursor
;-----------------------------------------------------------------------------; Now, after filled the "WNDCLASSEX" structure we call API "RegisterClassEx"
;-----------------------------------------------------------------------------push
OFFSET cbSize
;pointer to WNDCLASSEX structure
call
RegisterClassExA
;- API Function ;==============================================================================
; API "CreateWindowExA" creates an overlapped, pop-up, or child window with an
; extended style. The return value in EAX is the handle of the new window.
; This API sends a WM_CREATE message to the window procedure (WP1).
;-----------------------------------------------------------------------------push
0h
;lpParam, extra pointer data 0=no data
push
hInstance
;hInstance, handle of our program
push
0h
;hMenu, handle window menu 0=class menu
push
0h
;hWndParent, handle parent window 0=no
push
000000F8h
;intnHeight, window height pixel
push
0000020Ah
;intnWidth, window width pixel
push
000000A0h
;inty, vertical position window
push
000000B0h
;intx, horizontal position window
push
04CA0000h
;dwStyle, 0=no sysmenu/close buttons
push
OFFSET WindowName
;lpWindowName, pointer to window name
push
OFFSET ClassName
;lpClassName, pointer to class name
push
0300h
;dwExStyle, extra window style 0=no
call
CreateWindowExA
;- API Function mov
hWnd,eax
;hwnd,return value=handle of window
Page 4

td_win32asm_010.asm
;==============================================================================
; API "ShowWindow" function sets the specified window's show state.
;-----------------------------------------------------------------------------push
1h
;nCmdShow, show state 1=SW_SHOWNORMAL
push
hWnd
;hwnd, handle of window
call
ShowWindow
;- API Function ;==============================================================================
; API "UpdateWindow" updates the area of the specified window by sending a
; WM_PAINT message to the window if the window's update region is not empty.
;-----------------------------------------------------------------------------push
hWnd
;hwnd, handle of window
call
UpdateWindow
;- API Function ;==============================================================================
; API "GetMessageA" retrieves a message & places it in the specified structure.
;-----------------------------------------------------------------------------LoopGetMessage:
push
0h
;wMsgFilterMax, highest message value
push
0h
;wMsgFilterMin, lowest message value
push
0h
;hWnd, handle of window who gets msg.
push
OFFSET hWnd
;lpMsg, pointer to MSG structure
call
GetMessageA
;- API Function cmp
eax,0h
;check if return value=0 (exit)
je
ExitPrg
;if return value is 0 goto LABEL
;==============================================================================
; API "TranslateMessage" translates key code into ASCII character messages
;-----------------------------------------------------------------------------push
OFFSET hWnd
;lpMSG, pointer to msg structure
call
TranslateMessage
;- API Function - keyboard code
;==============================================================================
; API "DispatchMessageA" function dispatches a message to a window procedure.
;-----------------------------------------------------------------------------push
OFFSET hWnd
;lpMSG, pointer to msg structure
call
DispatchMessageA
;- API Function jmp
LoopGetMessage
;check for message again, goto LABEL
;==============================================================================
; Next we terminate our program (API=ExitProcess)
;-----------------------------------------------------------------------------ExitPrg:
push
hInstance
;push our programm handle to exit
call
ExitProcess
;- API Function ;##############################################################################
; This is the Window Procedure lpfnWndProc (API=RegisterClassExA) for this
; registered window.
; The WindowProc function is an application-defined callback function that
; processes messages sent to a window.
; Here our code for checking the receiving messages resist.
Page 5

td_win32asm_010.asm
; In the future it is the main work for us to react to the recieved messages.
; It is also a good idea to PUSHAD all register, because than we are free to
; use all register in this window procedure.
; Before we leave this subroutine we must POPAD them back.
;-----------------------------------------------------------------------------WP1:
push
ebp
;create stack frame
mov
ebp,esp
;
pushad
;push all register to the stack
mov
eax,WP1_uMsg
;move the message number to eax
;==============================================================================
; WM_CREATE (value=01h) message received ?, posted by API - CREATEWINDOWEX
;-----------------------------------------------------------------------------WP1_uMsg_01h:
cmp
eax,1h
;check if WM_CREATE message recieved
jne
WP1_uMsg_02h
;if not goto label
;-----------------------------------------------------------------------------; In this case API "CreateWindowExA" creates a child window with a predefined
; window class name for example BUTTON, LISTBOX, EDITBOX ... ( here BUTTON ! )
; Windows 9x register this child windows automaticly for you !
; Parameter dwStyle defines the button : BS_PUSHBUTTON, BS_GROUPBOX...
; dwStyle defines also WS_VISIBLE ( 10000000h ) or WS_CHILD ( 40000000h )
; Don't forget to take a look into WIN32.HLP ( CreateWindow ) and Windows.inc.
; In hMenu we PUSH the ID of the child window ( a value of your your choice )
; The return value in EAX is the handle ( ID ) of the new child window.
;-----------------------------------------------------------------------------push
0h
;lpParam, extra pointer data 0=no data
push
hInstance
;hInstance, handle of our program
push
0100h
;hMenu, the child-window ID
push
WP1_hWnd
;hWndParent, handle parent window 0=no
push
00000020h
;intnHeight, window height pixel
push
000000A0h
;intnWidth, window width pixel
push
00000010h
;inty, vertical position window
push
00000008h
;intx, horizontal position window
push
50000001h
;dwStyle, style ( BS_DEFPUSHBUTTON )
push
OFFSET Bu01_WindowName
;lpWindowName, pointer to window name
push
OFFSET Bu00_ClassName
;lpClassName, pointer to class name
push
0h
;dwExStyle,
call
CreateWindowExA
;- API Function mov
defpushbutton0100_hWnd,eax
;return value=handle of window
push
push
push
push
push
push
push
push
push
push
push

0h
hInstance
0101h
WP1_hWnd
00000020h
000000A0h
00000010h
000000B0h
50000000h
OFFSET Bu00_WindowName
OFFSET Bu00_ClassName

;lpParam, extra pointer data 0=no data


;hInstance, handle of our program
;hMenu, the child-window ID
;hWndParent, handle parent window 0=no
;intnHeight, window height pixel
;intnWidth, window width pixel
;inty, vertical position window
;intx, horizontal position window
;dwStyle, style ( BS_PUSHBUTTON )
;lpWindowName, pointer to window name
;lpClassName, pointer to class name
Page 6

push
call
mov

0h
CreateWindowExA
pushbutton0200_hWnd,eax

td_win32asm_010.asm
;dwExStyle,
;- API Function ;return value=handle of window

push
push
push
push
push
push
push
push
push
push
push
push
call
mov

0h
hInstance
0102h
WP1_hWnd
00000020h
000000A0h
00000010h
00000158h
50000008h
OFFSET Bu08_WindowName
OFFSET Bu00_ClassName
0h
CreateWindowExA
userbutton0300_hWnd,eax

;lpParam, extra pointer data 0=no data


;hInstance, handle of our program
;hMenu, the child-window ID
;hWndParent, handle parent window 0=no
;intnHeight, window height pixel
;intnWidth, window width pixel
;inty, vertical position window
;intx, horizontal position window
;dwStyle, style ( BS_USERBUTTON )
;lpWindowName, pointer to window name
;lpClassName, pointer to class name
;dwExStyle,
;- API Function ;return value=handle of window

push
push
push
push
push
push
push
push
push
push
push
push
call
mov

0h
hInstance
0400h
WP1_hWnd
00000020h
000000A0h
00000040h
00000008h
50000002h
OFFSET Bu02_WindowName
OFFSET Bu00_ClassName
0h
CreateWindowExA
checkbox0400_hWnd,eax

;lpParam, extra pointer data 0=no data


;hInstance, handle of our program
;hMenu, the child-window ID
;hWndParent, handle parent window 0=no
;intnHeight, window height pixel
;intnWidth, window width pixel
;inty, vertical position window
;intx, horizontal position window
;dwStyle, style ( BS_CHECKBOX )
;lpWindowName, pointer to window name
;lpClassName, pointer to class name
;dwExStyle,
;- API Function ;return value=handle of window

push
push
push
push
push
push
push
push
push
push
push
push
call
mov

0h
hInstance
0500h
WP1_hWnd
00000020h
000000A0h
00000040h
000000B0h
50000003h
OFFSET Bu03_WindowName
OFFSET Bu00_ClassName
0h
CreateWindowExA
autocheckbox0500_hWnd,eax

;lpParam, extra pointer data 0=no data


;hInstance, handle of our program
;hMenu, the child-window ID
;hWndParent, handle parent window 0=no
;intnHeight, window height pixel
;intnWidth, window width pixel
;inty, vertical position window
;intx, horizontal position window
;dwStyle, style ( BS_AUTOCHECKBOX )
;lpWindowName, pointer to window name
;lpClassName, pointer to class name
;dwExStyle,
;- API Function ;return value=handle of window

push
push
push
push

0h
hInstance
0600h
WP1_hWnd

;lpParam, extra pointer data 0=no data


;hInstance, handle of our program
;hMenu, the child-window ID
;hWndParent, handle parent window 0=no
Page 7

push
push
push
push
push
push
push
push
call
mov

00000020h
000000A0h
00000070h
00000008h
50000004h
OFFSET Bu04_WindowName
OFFSET Bu00_ClassName
0h
CreateWindowExA
radiobutton0600_hWnd,eax

td_win32asm_010.asm
;intnHeight, window height pixel
;intnWidth, window width pixel
;inty, vertical position window
;intx, horizontal position window
;dwStyle, style ( BS_RADIOBUTTON )
;lpWindowName, pointer to window name
;lpClassName, pointer to class name
;dwExStyle,
;- API Function ;return value=handle of window

push
push
push
push
push
push
push
push
push
push
push
push
call
mov

0h
hInstance
0700h
WP1_hWnd
00000020h
000000A0h
00000070h
000000B0h
50000009h
OFFSET Bu09_WindowName
OFFSET Bu00_ClassName
0h
CreateWindowExA
autoradiobutton0700_hWnd,eax

;lpParam, extra pointer data 0=no data


;hInstance, handle of our program
;hMenu, the child-window ID
;hWndParent, handle parent window 0=no
;intnHeight, window height pixel
;intnWidth, window width pixel
;inty, vertical position window
;intx, horizontal position window
;dwStyle, style ( BS_AUTORADIOBUTTON )
;lpWindowName, pointer to window name
;lpClassName, pointer to class name
;dwExStyle,
;- API Function ;return value=handle of window

push
push
push
push
push
push
push
push
push
push
push
push
call
mov

0h
hInstance
0800h
WP1_hWnd
00000020h
000000A0h
000000A0h
00000008h
50000005h
OFFSET Bu05_WindowName
OFFSET Bu00_ClassName
0h
CreateWindowExA
threestate0800_hWnd,eax

;lpParam, extra pointer data 0=no data


;hInstance, handle of our program
;hMenu, the child-window ID
;hWndParent, handle parent window 0=no
;intnHeight, window height pixel
;intnWidth, window width pixel
;inty, vertical position window
;intx, horizontal position window
;dwStyle, style ( BS_3STATE )
;lpWindowName, pointer to window name
;lpClassName, pointer to class name
;dwExStyle,
;- API Function ;return value=handle of window

push
push
push
push
push
push
push
push
push
push
push
push

0h
hInstance
0900h
WP1_hWnd
00000020h
000000A0h
000000A0h
000000B0h
50000006h
OFFSET Bu06_WindowName
OFFSET Bu00_ClassName
0h

;lpParam, extra pointer data 0=no data


;hInstance, handle of our program
;hMenu, the child-window ID
;hWndParent, handle parent window 0=no
;intnHeight, window height pixel
;intnWidth, window width pixel
;inty, vertical position window
;intx, horizontal position window
;dwStyle, style ( BS_AUTO3STATE )
;lpWindowName, pointer to window name
;lpClassName, pointer to class name
;dwExStyle,
Page 8

call
mov

CreateWindowExA
auto3state0900_hWnd,eax

td_win32asm_010.asm
;- API Function ;return value=handle of window

push
0h
;lpParam, extra pointer data 0=no data
push
hInstance
;hInstance, handle of our program
push
0A00h
;hMenu, the child-window ID
push
WP1_hWnd
;hWndParent, handle parent window 0=no
push
00000080h
;intnHeight, window height pixel
push
000000A0h
;intnWidth, window width pixel
push
00000040h
;inty, vertical position window
push
00000158h
;intx, horizontal position window
push
50000007h
;dwStyle, style ( BS_GROUPBOX )
push
OFFSET Bu07_WindowName
;lpWindowName, pointer to window name
push
OFFSET Bu00_ClassName
;lpClassName, pointer to class name
push
0h
;dwExStyle,
call
CreateWindowExA
;- API Function mov
groupbox0A00_hWnd,eax
;return gvalue=handle of window
;-----------------------------------------------------------------------------; This child windows a part of BS_GROUPBOX, hWndParent=groupbox0A00_hWnd !
;-----------------------------------------------------------------------------push
0h
;lpParam, extra pointer data 0=no data
push
hInstance
;hInstance, handle of our program
push
0A10h
;hMenu, the child-window ID
push
groupbox0A00_hWnd
;hWndParent, handle parent window 0=no
push
00000020h
;intnHeight, window height pixel
push
0000009Ah
;intnWidth, window width pixel
push
00000018h
;inty, vertical position window
push
00000002h
;intx, horizontal position window
push
50000009h
;dwStyle, style ( BS_AUTORADIOBUTTON )
push
OFFSET Bu09_WindowName
;lpWindowName, pointer to window name
push
OFFSET Bu00_ClassName
;lpClassName, pointer to class name
push
0h
;dwExStyle,
call
CreateWindowExA
;- API Function mov
autoradiobutton0A10_hWnd,eax
;return value=handle of window
push
push
push
push
push
push
push
push
push
push
push
push
call
mov

0h
hInstance
0A20h
groupbox0A00_hWnd
00000020h
0000009Ah
00000038h
00000002h
50000009h
OFFSET Bu09_WindowName
OFFSET Bu00_ClassName
0h
CreateWindowExA
autoradiobutton0A20_hWnd,eax

;lpParam, extra pointer data 0=no data


;hInstance, handle of our program
;hMenu, the child-window ID
;hWndParent, handle parent window 0=no
;intnHeight, window height pixel
;intnWidth, window width pixel
;inty, vertical position window
;intx, horizontal position window
;dwStyle, style ( BS_AUTORADIOBUTTON )
;lpWindowName, pointer to window name
;lpClassName, pointer to class name
;dwExStyle,
;- API Function ;return value=handle of window

push
push
push

0h
hInstance
0A30h

;lpParam, extra pointer data 0=no data


;hInstance, handle of our program
;hMenu, the child-window ID
Page 9

push
push
push
push
push
push
push
push
push
call
mov
jmp

groupbox0A00_hWnd
00000020h
0000009Ah
00000058h
00000002h
50000009h
OFFSET Bu09_WindowName
OFFSET Bu00_ClassName
0h
CreateWindowExA
autoradiobutton0A30_hWnd,eax
WP1_return

td_win32asm_010.asm
;hWndParent, handle parent window 0=no
;intnHeight, window height pixel
;intnWidth, window width pixel
;inty, vertical position window
;intx, horizontal position window
;dwStyle, style ( BS_AUTORADIOBUTTON )
;lpWindowName, pointer to window name
;lpClassName, pointer to class name
;dwExStyle,
;- API Function ;return value=handle of window
;

;==============================================================================
; WM_DESTROY (value=02h) message received ?
;-----------------------------------------------------------------------------WP1_uMsg_02h:
cmp
eax,2h
;check if value=2h (WM_DESTROY)
jne
WP1_uMsg_111h
;if not 2h go to LABEL
call
My_CleanSystem
;- SubRoutine ;-----------------------------------------------------------------------------; API "PostQuitMessage" indicates to Windows a request to terminate
;-----------------------------------------------------------------------------push
0h
;nExitCode, exit code=wParam
call
PostQuitMessage
;- API Function popad
;pop all register back from stack
xor
eax,eax
;set eax to 0 to exit our program
mov
esp,ebp
;delete stack frame
pop
ebp
;
ret
10h
;return and clear stack
;==============================================================================
; WM_COMMAND (value=111h) message recieved ?
;-----------------------------------------------------------------------------;
Low word of wParam
High word wParam
lParam
; Menu
- Menu ID
0
0
; Child control - Control ID
Notification code
Child Window Handle
;-----------------------------------------------------------------------------WP1_uMsg_111h:
cmp
eax,111h
;check if WM_COMMAND message recieved
jne
WP1_uMsg_112h
;if not goto label
;-----------------------------------------------------------------------------; Check extra message menu control, "&Exit" item in menu bar,ID=1h clicked
;-----------------------------------------------------------------------------WP1_wParam_01h:
mov
eax,WP1_wParam
;extra info about the message in ax
cmp
ax,1h
;ID of "&Exit" item in rc file
jne
WP1_wParam_0100h
;if not 1h goto LABEL
;-----------------------------------------------------------------------------; API "MessageBoxA" creates a message box, we can choose if we want exit prg.
;-----------------------------------------------------------------------------push
4h
;uType, style, 4=MB_YESNO Button
push
OFFSET MB1Titel
;lpCaption,pointer to title text
Page 10

td_win32asm_010.asm
push
OFFSET MB1Text
;lpText,pointer to text message box
push
WP1_hWnd
;handle of owner window 0=no owner
call
MessageBoxA
;- API Function cmp
eax,6h
;if return value=6h (IDYES) then exit
jne
WP1_return
;if return value=7h (IDNO) goto LABEL
;-----------------------------------------------------------------------------; API "DestroyWindow" function destroys the given window if we want exit prg.
;-----------------------------------------------------------------------------push
WP1_hWnd
;hwnd, handle of window to destroy
call
DestroyWindow
;- API Function jmp
WP1_return
;
;-----------------------------------------------------------------------------; Check extra message, button (ID=0100h,0200h,0300h) clicked
;-----------------------------------------------------------------------------WP1_wParam_0100h:
cmp
ax,0100h
;ID of button, child window
jb
WP1_return
;if not 0100h goto LABEL
cmp
ax,0102h
;
ja
WP1_return
;if not 0100h goto LABEL
;-----------------------------------------------------------------------------; API "MessageBoxA" creates a message box, we can only click OK
;-----------------------------------------------------------------------------push
0h
;uType, style, 0=MB_OK Button
push
OFFSET MB2Titel
;lpCaption,pointer to title text
push
OFFSET MB2Text
;lpText,pointer to text message box
push
WP1_hWnd
;handle of owner window 0=no owner
call
MessageBoxA
;- API Function jmp
WP1_return
;if return value=0h (IDOK) goto LABEL
;==============================================================================
; WM_SYSCOMMAND (value=112h) message recieved ?
;-----------------------------------------------------------------------------WP1_uMsg_112h:
cmp
eax,112h
;check if WM_COMMAND message recieved
jne
WP1_return
;if not goto label
mov
eax,WP1_wParam
;extra info about the message
cmp
eax,0F060h
;SC_CLOSE=0F060h received ?
jne
WP1_return
;
call
My_CleanSystem
;- SubRoutine jmp
WP1_return
;==============================================================================
; API "DefWindowProcA" calls the window procedure to provide default processing
; for any window messages that an application does not process.
; This function ensures that every message is processed.
; It is called with the same parameters received by the window procedure.
;-----------------------------------------------------------------------------WP1_return:
popad
;pop all register from stack
push
WP1_lParam
;extra info about the message
push
WP1_wParam
;extra info about the message
push
WP1_uMsg
;the message number
push
WP1_hWnd
;handle of window who receives message
Page 11

td_win32asm_010.asm
call
DefWindowProcA
;- API Function mov
esp,ebp
;delete stack frame
pop
ebp
;
ret
10h
;return and clear stack
;##############################################################################
;******************************************************************************
; My own subroutine(s) for a compacter code resist here ...
;-----------------------------------------------------------------------------My_CleanSystem:
ret
;******************************************************************************
;==============================================================================
; end Main = end of our program code
;-----------------------------------------------------------------------------end Main
;end of our program code, entry point
;==============================================================================
; To create the exe file use this commands with your Microsoft Assembler/Linker
;-----------------------------------------------------------------------------; ml.exe /c /coff td_win32asm_010.asm
;asm command
; rc.exe /v rsrc.rc
;rc command
; cvtres.exe /machine:ix86 rsrc.res
; link.exe /subsystem:windows td_win32asm_010.obj rsrc.obj
;link command
;==============================================================================

Page 12

Você também pode gostar