gt;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ; 主窗口程序 ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> _WinMain proc local @stWcMain:WNDCLASSEX local @stMsg:MSG
;******************************************************************** ; 如果已经在运行,则激活已运行的进程 ;******************************************************************** invoke FindWindow,offset szClassName,NULL .if eax != NULL invoke ShowWindow,eax,SW_SHOWNORMAL invoke ExitProcess,NULL .endif
invoke InitCommonControls invoke GetModuleHandle,NULL mov hInstance,eax invoke LoadIcon,hInstance,IDI_MAIN mov hIcon,eax invoke LoadMenu,hInstance,IDM_MAIN mov hMenu,eax ;*************** 注册窗口类 ***************************************** invoke LoadCursor,0,IDC_ARROW mov @stWcMain.hCursor,eax mov @stWcMain.cbSize,sizeof WNDCLASSEX mov @stWcMain.hIconSm,0 mov @stWcMain.style,CS_HREDRAW or CS_VREDRAW mov @stWcMain.lpfnWndProc,offset WndMainProc mov @stWcMain.cbClsExtra,0 mov @stWcMain.cbWndExtra,0 mov eax,hInstance mov @stWcMain.hInstance,eax mov @stWcMain.hIcon,0 mov @stWcMain.hbrBackground,COLOR_BTNFACE+1 mov @stWcMain.lpszClassName,offset szClassName mov @stWcMain.lpszMenuName,0 invoke RegisterClassEx,addr @stWcMain ;*************** 建立输出窗口 *************************************** invoke CreateWindowEx,NULL,\ ;WS_EX_CLIENTEDGE,\ offset szClassName,offset szCaptionMain,\ WS_OVERLAPPEDWINDOW,\ ; OR WS_VSCROLL OR WS_HSCROLL,\ 50,50,550,350,\ NULL,hMenu,hInstance,NULL
invoke ShowWindow,hWinMain,SW_SHOWNORMAL invoke UpdateWindow,hWinMain ;*************** 消息循环 ******************************************* .while TRUE invoke GetMessage,addr @stMsg,NULL,0,0 .break .if eax == 0 invoke TranslateMessage,addr @stMsg invoke DispatchMessage,addr @stMsg .endw ret
_WinMain endp ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> WndMainProc proc uses ebx edi esi, \ hWnd:DWORD,uMsg:DWORD,wParam:DWORD,lParam:DWORD
mov eax,uMsg .if eax == WM_CREATE mov eax,hWnd mov hWinMain,eax call _Init ;******************************************************************** .elseif eax == WM_SIZE invoke SendMessage,hStatusbar,uMsg,wParam,lParam invoke SendMessage,hToolbar,uMsg,wParam,lParam ;******************************************************************** .elseif eax == WM_COMMAND mov eax,wParam movzx eax,ax .if eax == IDM_EXIT call _Quit .elseif eax == IDM_TOOLBAR xor dwFlag,F_TOOLBAR call _ArrangeWindow .elseif eax == IDM_STATUSBAR xor dwFlag,F_STATUSBAR call _ArrangeWindow .else _Debug "菜单和工具栏命令","命令ID",eax .endif ;******************************************************************** .elseif eax == WM_CLOSE call _Quit ;******************************************************************** .else invoke DefWindowProc,hWnd,uMsg,wParam,lParam ret .endif ;******************************************************************** ; 注意:WndProc 处理 Windows 消息后,必须在 Eax 中返回 0 ; 但是由 DefWindowProc 处理后的返回值不能改变,否则窗口 ; 将无法显示! ;******************************************************************** xor eax,eax ret
WndMainProc endp
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ; 主窗口控制子程序 ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> _Init proc
invoke SendMessage,hWinMain,WM_SETICON,ICON_SMALL,hIcon invoke CreateToolbarEx,hWinMain,\ WS_VISIBLE or WS_CHILD or TBSTYLE_FLAT or WS_BORDER,\ 1,0,HINST_COMMCTRL,IDB_STD_SMALL_COLOR,offset stToolbar,\ NUM_BUTTONS,0,0,0,0,sizeof TBBUTTON mov hToolbar,eax
invoke CreateStatusWindow,WS_CHILD or WS_VISIBLE,NULL,hWinMain,2 mov hStatusbar,eax call _ArrangeWindow
ret
_Init endp ;******************************************************************** _Quit proc
invoke DestroyWindow,hWinMain invoke PostQuitMessage,NULL ret
_Quit endp ;******************************************************************** _ArrangeWindow proc local @stRect:RECT local @stRectTemp:RECT local @dwWidth:DWORD
test dwFlag,F_TOOLBAR .if ZERO? invoke ShowWindow,hToolbar,SW_HIDE invoke CheckMenuItem,hMenu,IDM_TOOLBAR,MF_UNCHECKED .else invoke ShowWindow,hToolbar,SW_SHOW invoke CheckMenuItem,hMenu,IDM_TOOLBAR,MF_CHECKED .endif test dwFlag,F_STATUSBAR .if ZERO? invoke ShowWindow,hStatusbar,SW_HIDE invoke CheckMenuItem,hMenu,IDM_STATUSBAR,MF_UNCHECKED .else invoke ShowWindow,hStatusbar,SW_SHOW invoke CheckMenuItem,hMenu,IDM_STATUSBAR,MF_CHECKED .endif
ret
_ArrangeWindow endp ;******************************************************************** end start 程序的分析和要点
在工具栏和状态栏编程中,要注意的就是工具栏和状态栏并不会随父窗口的大小变化自己调整位置和大小,所以要在父窗口的 WM_SIZE 消息中来移动和调整它们,这可以简单的把 WM_SIZE 消息传给它们就行了。不必自己再去计算。
.elseif eax == WM_SIZE invoke SendMessage,hStatusbar,uMsg,wParam,lParam invoke SendMessage,hToolbar,uMsg,wParam,lParam 另外,工具栏和状态栏也是一种子窗口,所以如果想把它们隐藏或显示的话,可以用标准的 ShowWindow 来处理。 上一页 [1] [2] |