You are on page 1of 12

td_win32asm_020.

asm
;==============================================================================
;
Test Department's WINDOWS 32 BIT x86 ASSEMBLY TUTORIAL'S
020
;==============================================================================
;==============================================================================
; ==> Part 020 : creating a toolbar with bitmaps, inclusive tooltiptext
;-----------------------------------------------------------------------------; In this tut 020 we create a child window named toolbar( API=CreateToolbarEx )
; You can also use API=CreateWindowEx but API=CreateToolbarEx works fine.
; We create our toolbar in the window procedure ( WP1 ) "lpfnWndProc"
; reacting to a WM_CREATE message.
; For API CreateToolbarEx we need a TBBUTTON structure, we create an ARRAY !
; This ARRAY is defined in the .DATA area.
; On event, for example a toolbar button is clicked, a WM_COMMAND message with
; the button ID in wParam is send to the window procedure !
; We react with a message box.
; We also react to WM_COMMAND / WM_NOTIFY message, to a NMHDR structure and
; a TOOLTIPTEXT structure, given by Windows in lParam as a pointer to this
; structure(s)... one more time: look into WIN32.HLP and Windows.inc !
; This is interesting part of this tut, here we create the toolbar button text
; "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 files where API functins resist you want use, set the correct path
;-----------------------------------------------------------------------------include \masm32\include\windows.inc
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\user32.lib
includelib \masm32\lib\comctl32.lib
;==============================================================================
; Declaration of used API functions,take a look into WIN32.HLP and *.inc files
;-----------------------------------------------------------------------------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
Page 1

PostQuitMessage
DefWindowProcA
ExitProcess
MessageBoxA
DestroyWindow
SendMessageA
InitCommonControls
CreateToolbarEx

PROTO
PROTO
PROTO
PROTO
PROTO
PROTO
PROTO
PROTO

td_win32asm_020.asm
:DWORD
:DWORD,:DWORD,:DWORD,:DWORD
:DWORD
:DWORD,:DWORD,:DWORD,:DWORD
:DWORD
:DWORD,:DWORD,:DWORD,:DWORD
:DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD,
:DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD

;==============================================================================
; .const = the constants area starts here,constants are defined and fixed
;-----------------------------------------------------------------------------.const
; - 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
;-----------------------------------------------------------------------------.Data
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
MB1Titel
db "Realy Exit ?",0
;message box name
MB1Text
db "Your choice ...",0
;message box text
MB2Titel
db "Message Box",0
;message box name
MB2Text
db "Toolbar Button clicked",0;message box text
toolbar00_str_00
db "Separator",0
;toolbar separator
toolbar00_str_01
db "Stoned",0
;toolbar button text
toolbar00_str_02
db "World",0
;
toolbar00_str_03
db "van Gogh",0
;
toolbar00_str_04
db "Apple",0
;
toolbar00_str_05
db "Ball",0
;
toolbar00_str_06
db "Sandra",0
;
toolbar00_str_07
db "Separator",0
;toolbar sparator
toolbar00_str_08
db "Pamela",0
;toolbar button text
toolbar00_hWnd
dd 0h
;handle of the toolbar
align 4
; - TBBUTTON structure ( API=CreateToolbarEx ) - ARRAY !!!
iBitmap
dd 0h
;zero-based index of button image
idCommand
dd 0h
;ID or, if fsStyle=TBSTYLE_SEP, zero
fsState
db 4h
;state flags,4h=TBSTATE_ENABLED
fsStyle
db 1h
;button style,1h=TBSTYLE_SEP
bReserved
db 2h dup (0)
;reserved byte,error in WIN32.HLP ?
dwData
dd 0h
;application-defined value
iString
dd 0h
;zero-based index of button string
Page 2

td_win32asm_020.asm
iBitmap_01
idCommand_01
fsState_01
fsStyle_01
bReserved_01
dwData_01
iString_01

dd
dd
db
db
db
dd
dd

1h
0C1h
4h
0h
2h dup (0)
0h
0h

iBitmap_02
idCommand_02
fsState_02
fsStyle_02
bReserved_02
dwData_02
iString_02

dd
dd
db
db
db
dd
dd

2h
0C2h
4h
0h
2h dup (0)
0h
0h

iBitmap_03
idCommand_03
fsState_03
fsStyle_03
bReserved_03
dwData_03
iString_03

dd
dd
db
db
db
dd
dd

3h
0C3h
4h
0h
2h dup (0)
0h
0h

iBitmap_04
idCommand_04
fsState_04
fsStyle_04
bReserved_04
dwData_04
iString_04

dd
dd
db
db
db
dd
dd

4h
0C4h
4h
0h
2h dup (0)
0h
0h

iBitmap_05
idCommand_05
fsState_05
fsStyle_05
bReserved_05
dwData_05
iString_05

dd
dd
db
db
db
dd
dd

5h
0C5h
4h
0h
2h dup (0)
0h
0h

iBitmap_06
idCommand_06
fsState_06
fsStyle_06
bReserved_06
dwData_06
iString_06

dd
dd
db
db
db
dd
dd

6h
0C6h
4h
0h
2h dup (0)
0h
0h

iBitmap_07
idCommand_07
fsState_07
fsStyle_07

dd
dd
db
db

7h
0h
4h
1h

;zero-based index of button image


;ID of button, WM_COMMAND uMsg/wParam
;state flags,4h=TBSTATE_ENABLED
;button style,0h=TBSTYLE_BUTTON
;reserved byte,error in WIN32.HLP ?
;application-defined value
;zero-based index of button string

;zero-based index of button image


;ID or, if fsStyle=TBSTYLE_SEP, zero
;state flags,4h=TBSTATE_ENABLED
;button style,1h=TBSTYLE_SEP
Page 3

bReserved_07
dwData_07
iString_07

db 2h dup (0)
dd 0h
dd 0h

td_win32asm_020.asm
;reserved byte,error in WIN32.HLP ?
;application-defined value
;zero-based index of button string

iBitmap_08
idCommand_08
fsState_08
fsStyle_08
bReserved_08
dwData_08
iString_08

dd
dd
db
db
db
dd
dd

;zero-based index of button image


;ID of button, WM_COMMAND uMsg/wParam
;state flags,4h=TBSTATE_ENABLED
;button style,0h=TBSTYLE_BUTTON
;reserved byte,error in WIN32.HLP ?
;application-defined value
;zero-based index of button string

8h
0C8h
4h
0h
2h dup (0)
0h
0h

align 4
; - TBADDBITMAP structure ( API=SendMessage ) - add bitmap to toolbar
TBADDBITMAP_hInst
dd 0h
;
TBADDBITMAP_nID
dd 0h
;
;==============================================================================
; .Data? = the data? area starts here, not defined and not fixed
;-----------------------------------------------------------------------------.data?
; - WndClassEx Structure ( API=RegisterClassExA ) cbSize
dd ?
;size in bytes of this structure
style
dd ?
;window style
lpfnWndProc
dd ?
;address of user proc function
cbclsExtra
dd ?
;extra bytes to allocate set to 0
cbWndExtra
dd ?
;extra bytes class directive, rc file
hInstance
dd ?
;program handle(API=GetModuleHandleA)
hIcon
dd ?
;handle of icon (API=LoadIconA)
hcursor
dd ?
;handle of cursor (API=LoadCursor)
hbrBackground
dd ?
;background color, 0=transparent
lpszMenuName
dd ?
;name of menu class in resource file
lpszClassName
dd ?
;name of windows this window class
hIconSm
dd ?
;iconhandle 0=search in resource file
align 4
; - Msg Structure ( API=GetMessageA ) - member POINT = POINT structure
hWnd
dd ?
;handle of window who receives message
message
dd ?
;the message number
wParam
dd ?
;extra info about the message
lParam
dd ?
;extra info about the message
time
dd ?
;time the message was posted
xpt
dd ?
;cursor x-position, POINT struc
ypt
dd ?
;cursor x-position, POINT struc
;==============================================================================
; .CODE = our code area starts here
Main = label of our program code
;-----------------------------------------------------------------------------.Code
Main:
;==============================================================================
; Always get your program ID first (API=GetModuleHandleA)
Page 4

td_win32asm_020.asm
;-----------------------------------------------------------------------------push
0h
;lpModuleHandle, 0=get program handle
call
GetModuleHandleA
;- API Function mov
hInstance,eax
;return value in eax=handle of program
;==============================================================================
; API "CreateToolbarEx" is part of common controls, force to init...
;-----------------------------------------------------------------------------call
InitCommonControls
;- API Function ;==============================================================================
; The API function "RegisterClassExA" registers a window class
; 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,2h
;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
Page 5

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

0h
0h
000000F8h
0000020Ah
000000A0h
000000B0h
04CA0000h
OFFSET WindowName
OFFSET ClassName
0100h
CreateWindowExA
hWnd,eax

td_win32asm_020.asm
;hMenu, handle window menu 0=class menu
;hWndParent, handle parent window 0=no
;intnHeight, window height pixel
;intnWidth, window width pixel
;inty, vertical position window
;intx, horizontal position window
;dwStyle, 0=no sysmenu/close buttons
;lpWindowName, pointer to window name
;lpClassName, pointer to class name
;dwExStyle, extra window style 0=no
;- API Function ;hwnd,return value=handle of window

;==============================================================================
; 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
;==============================================================================
Page 6

td_win32asm_020.asm
; 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.
; 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 main API=CREATEWINDOWEX
;-----------------------------------------------------------------------------WP1_uMsg_01h:
cmp
eax,1h
;check if WM_CREATE message recieved
jne
WP1_uMsg_02h
;if not goto label
;-----------------------------------------------------------------------------; API "CreateToolbarExA" creates a child window ( TOOLBAR ).
; Set "uStructSize" to 14h, not 12h because bReserved bytes, bug in WIN32.HLP ?
; Take a look to TBBUTTON structure in the .DATA area above.
; Parameter "ws" defines the child windows style; it also enables tooltiptext.
; In "wID" we PUSH the ID of the child window ( a value of your your choice ).
; Take a look into WIN32.HLP ( CreateToolbarEx ) and Windows.inc.
; The return value in EAX is the handle of the created toolbar.
;-----------------------------------------------------------------------------push
14h
;uStructSize,size TBBUTTON structure
push
14h
;dyBitmap,height pixels of the images
push
14h
;dxBitmap,width pixels of the images
push
0h
;dyButton,height pixels of the buttons
push
0h
;dxButton,width pixels of the buttons
push
8h
;iNumButtons,Number buttons in toolbar
push
OFFSET iBitmap
;lpButtons,pointer TBBUTTON structure
push
80h
;wBMID,ID for the bitmap resource
push
hInstance
;hBMInst,instance bitmap resource
push
8h
;nBitmaps, # of button images in file
push
300h
;wID,control identifier for toolbar
push
54000500h
;ws, windows styles in WIN32.HLP
push
WP1_hWnd
;hwnd,handle owner window 0=no owner
call
CreateToolbarEx
;- API Function mov
toolbar00_hWnd,eax
;handle of toolbar child window
Page 7

td_win32asm_020.asm
;-----------------------------------------------------------------------------; API "ShowWindow" function sets the specified window's show state.
;-----------------------------------------------------------------------------push
5h
;nCmdShow, show state 5h=SW_SHOW
push
toolbar00_hWnd
;hwnd, handle of window
call
ShowWindow
;- API Function ;-----------------------------------------------------------------------------; Here we add one bitmap picture to the toolbar, needs a TBADDBITMAP structure
;-----------------------------------------------------------------------------mov
eax,hInstance
;move module handle into EAX
mov
TBADDBITMAP_hInst,eax
;hInst, handle to module instance
mov
TBADDBITMAP_nID,81h
;nID, bitmap ID in resource file
;-----------------------------------------------------------------------------; API "SendMessageA" sends a message, TB_ADDBITMAP to add a bitmap
;-----------------------------------------------------------------------------push
OFFSET TBADDBITMAP_hInst
;lParam, pointer TBADDBITMAP structure
push
1h
;wParam, number of bitmaps to add
push
413h
;uMsg, send TB_ADDBITMAP message
push
toolbar00_hWnd
;hwnd, handle of destination window
call
SendMessageA
;- API Function ;-----------------------------------------------------------------------------; Here we add one button to the toolbar, needs a TBBUTTON structure
;-----------------------------------------------------------------------------push
OFFSET iBitmap_08
;lParam, pointer TBBUTTON structure
push
1h
;wParam, number of buttons to add
push
414h
;uMsg, send TB_ADDBUTTONS message
push
toolbar00_hWnd
;hWnd, handle of destination window
call
SendMessageA
;- API Function jmp
WP1_return
;==============================================================================
; WM_DESTROY (value=02h) message received ?
;-----------------------------------------------------------------------------WP1_uMsg_02h:
cmp
eax,2h
;check if value=2h (WM_DESTROY)
jne
WP1_uMsg_05h
;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_Size (value=05h) message, used to resize the window area
;-----------------------------------------------------------------------------WP1_uMsg_05h:
cmp
eax,05h
;check if WP_SIZE message recieved
Page 8

td_win32asm_020.asm
jne
WP1_uMsg_4Eh
;if not goto label
;-----------------------------------------------------------------------------; API "SendMessageA" sends a message, TB_AUTOSIZE to fit toolbar and bitmaps
;-----------------------------------------------------------------------------push
0h
;lParam, second message parameter
push
0h
;wParam, first message parameter (ID)
push
421h
;uMsg, send TB_AUTOSIZE message
push
toolbar00_hWnd
;hwnd, handle of destination window
call
SendMessageA
;- API Function jmp
WP1_return
;
;==============================================================================
; WM_NOTIFY (value=4Eh) message, here used to show the toolbar tip !
; With a WM_NOTIFY message Windows gives you pointer to a NMHDR structure.
;-----------------------------------------------------------------------------WP1_uMsg_4Eh:
cmp
eax,4Eh
;check if WM_NOTIFY message recieved
jne
WP1_uMsg_111h
;if not goto label
;-----------------------------------------------------------------------------; The NMHDR structure contains information about a notification message.
; The TOOLTIPTEXT structure identifies a tool for which text is to be displayed
; and receives the text for the tool.
; We must fill it with the CORRECT values ...
; The POINTER to this structure is specified as lParam member of WM_NOTIFY.
; This POINTER is given to us with the WM_NOTIFY message by Windows.
;-----------------------------------------------------------------------------; - NMHDR structure ; hwndFrom = [WP1_lParam+0]
;handle to control sending message
; idFrom
= [WP1_lParam+4]
;identifier of control sending message
; code
= [WP1_lParam+8]
;notification code
; - TOOLTIPTEXT structure ; hdr
= placeholder for NMHDR
;required for all WM_NOTIFY messages
; lpszText = [WP1_lParam+12]
;Pointer string or resource ID
; szText[80]= [WP1_lParam+16]
;buffer for text, alternate to lpszText
; hinst
= [WP1_lParam+20]
;handle instance, 0 if lpszText=pointer
; uFlags
= [WP1_lParam+24]
;Flag indicates how to interpret idFrom
;-----------------------------------------------------------------------------mov
ebx,WP1_lParam
;pointer to struc, given by windows !
mov
eax,[ebx+8]
;move code ( NMHDR structure ) into eax
cmp
eax,0FFFFFDF8h
;check if code TTN_NEEDTEXT received
jne
WP1_return
;if not goto label
mov
eax,[ebx+4]
;move idFrom ( NMHDR structure ) to eax
cmp
eax,0C1h
;is it toolbar button ID=0C1h
jne
next_01
;if not goto label
mov
[ebx+12],OFFSET toolbar00_str_01;move our text pointer to lpszText
;lpsz is part of TOOLTIPTEXT structure
next_01:
cmp
eax,0C2h
;is it toolbar button ID=0C2
jne
next_02
;if not goto label
mov
[ebx+12],OFFSET toolbar00_str_02;move our text pointer to lpszText
next_02:
cmp
eax,0C3h
;is it toolbar button ID=0C3
jne
next_03
;if not goto label
Page 9

mov
[ebx+12],OFFSET
next_03:
cmp
eax,0C4h
jne
next_04
mov
[ebx+12],OFFSET
next_04:
cmp
eax,0C5h
jne
next_05
mov
[ebx+12],OFFSET
next_05:
cmp
eax,0C6h
jne
next_06
mov
[ebx+12],OFFSET
next_06:
cmp
eax,0C8h
jne
next_08
mov
[ebx+12],OFFSET
next_08:
jmp
WP1_return

td_win32asm_020.asm
toolbar00_str_03;move our text pointer to lpszText
;is it toolbar button ID=0C4
;if not goto label
toolbar00_str_04;move our text pointer to lpszText
;is it toolbar button ID=0C5
;if not goto label
toolbar00_str_05;move our text pointer to lpszText
;is it toolbar button ID=0C6
;if not goto label
toolbar00_str_06;move our text pointer to lpszText
;is it toolbar button ID=0C8
;if not goto label
toolbar00_str_08;move our text pointer to lpszText
;go out of here

;==============================================================================
; WM_COMMAND (value=111h) message recieved ?
;-----------------------------------------------------------------------------WP1_uMsg_111h:
cmp
eax,111h
;check if WM_COMMAND message recieved
jne
WP1_uMsg_112h
;if not goto label
mov
eax,WP1_wParam
;extra info about the message in ax
cmp
ax,1h
;ID of "&Exit" item in rc file
jne
WP1_wParam_00C1h
;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
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
;
;-----------------------------------------------------------------------------; Extra message info toolbar, button (BITMAP BUTTON ID=0C1h - 0C8h) clicked
;-----------------------------------------------------------------------------WP1_wParam_00C1h:
cmp
ax,0C1h
;ID of first toolbar button
jb
WP1_return
;if below 0C1h goto LABEL
cmp
ax,0C8h
;ID of last toolbar button
ja
WP1_return
;if above 0C8h goto LABEL
Page 10

td_win32asm_020.asm
cmp
ax,0C7h
;ID of second toolbar separator
je
WP1_return
;if equall 0C7h goto Label
;-----------------------------------------------------------------------------; API "MessageBoxA" creates one message box for all toolbar buttons
;-----------------------------------------------------------------------------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
;
;==============================================================================
; 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
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
;-----------------------------------------------------------------------------Page 11

end Main

td_win32asm_020.asm
;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_020.asm
;asm command
; rc.exe /v rsrc.rc
;rc command
; cvtres.exe /machine:ix86 rsrc.res
; link.exe /subsystem:windows td_win32asm_020.obj rsrc.obj
;link command
;==============================================================================

Page 12

You might also like