WIN32汇编语言教程:第09章 通用控件 · 9.3 使用工具栏(2)

                   .code
;####################################################################
_Resize        proc
                   local  @stRect:RECT,@stRect1:RECT
 
                   invoke SendMessage,hWinToolbar,TB_AUTOSIZE,0,0
                   invoke GetClientRect,hWinMain,addr @stRect
                   invoke GetWindowRect,hWinToolbar,addr @stRect1
                   mov    eax,@stRect1.bottom
                   sub    eax,@stRect1.top
                   mov    ecx,@stRect.bottom
                   sub    ecx,eax
                   invoke MoveWindow,hWinEdit,0,eax,@stRect.right,ecx,TRUE
                   ret
 
_Resize        endp
;####################################################################
_ProcWinMain       proc       uses ebx edi esi hWnd,uMsg,wParam,lParam
                   local  @szBuffer[128]:byte
 
                   mov    eax,uMsg
;********************************************************************
                   .if    eax == WM_CLOSE
                           invoke DestroyWindow,hWinMain
                           invoke PostQuitMessage,NULL
;********************************************************************
                  .elseif eax == WM_CREATE
                           mov    eax,hWnd
                           mov    hWinMain,eax
                                invoke  CreateWindowEx,WS_EX_CLIENTEDGE,addr szClass,\
                                  NULL,WS_CHILD or WS_VISIBLE or ES_MULTILINE \
                                   or ES_WANTRETURN or WS_VSCROLL or\
                                   ES_AUTOHSCROLL,0,0,0,0,\
                                   hWnd,ID_EDIT,hInstance,NULL
                           mov    hWinEdit,eax
                           invoke CreateToolbarEx,hWinMain,WS_VISIBLE or\
                                   WS_CHILD or TBSTYLE_FLAT or TBSTYLE_TOOLTIPS or\
                                         CCS_ADJUSTABLE,ID_TOOLBAR,0,HINST_COMMCTRL,\
                                   IDB_STD_SMALL_COLOR,offset stToolbar,\
                                   NUM_BUTTONS,0,0,0,0,sizeof TBBUTTON
                           Mov    hWinToolbar,eax
                           Call       _Resize
;********************************************************************
                   .elseif eax == WM_COMMAND
                           mov    eax,wParam
                           .if    ax ==  IDM_EXIT
                                   invoke EndDialog,hWnd,NULL
                           .elseif ax !=  ID_EDIT
                                   invoke wsprintf,addr @szBuffer,\
                                           addr szFormat,wParam
                                   invoke MessageBox,hWnd,addr @szBuffer,\
                                           addr szCaption,\
                                           MB_OK or MB_ICONINFORMATION
                           .endif
;********************************************************************
                       .elseif eax == WM_SIZE
                               call       _Resize
;********************************************************************
; 处理用户定制工具栏消息
;********************************************************************
                       .elseif eax == WM_NOTIFY
                               mov    ebx,lParam
					.if    [ebx + NMHDR.code] == TTN_NEEDTEXT
					         assume ebx:ptr TOOLTIPTEXT
					          mov    eax,[ebx].hdr.idFrom
					          mov    [ebx].lpszText,eax
					          push       hInstance
					          pop    [ebx].hinst
					          assume ebx:nothing
					.elseif ([ebx + NMHDR.code] == TBN_QUERYINSERT) || \
					          ([ebx + NMHDR.code] == TBN_QUERYDELETE)
					          mov    eax,TRUE
					          ret
					.elseif [ebx + NMHDR.code] == TBN_GETBUTTONINFO
					          assume ebx:ptr TBNOTIFY
					          mov    eax,[ebx].iItem
					          .if    eax < NUM_BUTTONS
					                  mov    ecx,sizeof TBBUTTON
					                  mul    ecx
					                  add    eax,offset stToolbar
					                  invoke RtlMoveMemory,addr [ebx].tbButton,eax,sizeof TBBUTTON
					                  invoke LoadString,hInstance,[ebx].tbButton.idCommand,\
					                         addr @szBuffer,sizeof @szBuffer
					                  lea    eax,@szBuffer
					                  mov    [ebx].pszText,eax
					                 invoke lstrlen,addr @szBuffer
					                  mov    [ebx].cchText,eax
					                  assume ebx:nothing
					                 mov    eax,TRUE
					                 ret
					          .endif
					.endif
;********************************************************************
                 .else
                         invoke DefWindowProc,hWnd,uMsg,wParam,lParam
                         ret
                 .endif
;********************************************************************
                 xor    eax,eax
                 ret
 
_ProcWinMain       endp
;####################################################################
_WinMain           proc
                 local  @stWndClass:WNDCLASSEX
                   local  @stMsg:MSG
 
                   invoke InitCommonControls
                   invoke GetModuleHandle,NULL
                   mov    hInstance,eax
                 invoke LoadMenu,hInstance,IDM_MAIN
                   mov    hMenu,eax
;********************************************************************
; 注册窗口类
;********************************************************************
                   invoke RtlZeroMemory,addr @stWndClass,sizeof @stWndClass
                   invoke LoadIcon,hInstance,ICO_MAIN
                   mov    @stWndClass.hIcon,eax
                   mov    @stWndClass.hIconSm,eax
                   invoke LoadCursor,0,IDC_ARROW
                   mov    @stWndClass.hCursor,eax
                   push       hInstance
                   pop    @stWndClass.hInstance
                   mov    @stWndClass.cbSize,sizeof WNDCLASSEX
                   mov    @stWndClass.style,CS_HREDRAW or CS_VREDRAW
                   mov    @stWndClass.lpfnWndProc,offset _ProcWinMain
                   mov    @stWndClass.hbrBackground,COLOR_BTNFACE+1
                   mov    @stWndClass.lpszClassName,offset szClassName
                 invoke RegisterClassEx,addr @stWndClass

上页:第09章 通用控件 · 9.3 使用工具栏(1) 下页:第09章 通用控件 · 9.3 使用工具栏(3)

第09章 通用控件

版权所有 © 云南伯恩科技 证书:粤ICP备09170368号