Win32 ASM 菜单编程Demo以及Win32 ASM 为什么需要等值定义
使用Win32 ASM制作一個(gè)窗口菜單;
資源文件;
#define ICO_MAIN 0x1000 //圖標(biāo) #define IDM_MAIN 0x2000 //菜單#define IDM_HELP 0x4301 #define IDM_ABOUT 0x4302 #define IDM_ADDWZ 0x5001 #define IDM_UPDATEWZ 0x5002 #define IDM_DELWZ 0x5003 #define IDM_QUERYWZ 0x5004 #define IDM_ADDCK 0x6001 #define IDM_UPDATECK 0x6002 #define IDM_DELCK 0x6003 #define IDM_QUERYCK 0x6004ICO_MAIN ICON "Main.ico"IDM_MAIN menu discardableBEGINpopup "物資信息"BEGINmenuitem "添加物資", IDM_ADDWZmenuitem "更新物資", IDM_UPDATEWZmenuitem "刪除物資", IDM_DELWZmenuitem separatormenuitem "查詢物資", IDM_QUERYWZENDpopup "倉庫信息"BEGINmenuitem "添加倉庫", IDM_ADDCKmenuitem "更新倉庫", IDM_UPDATECKmenuitem "刪除倉庫", IDM_DELCKmenuitem separatormenuitem "查詢倉庫", IDM_QUERYCKENDpopup "幫助" ,HELPBEGINmenuitem "幫助主題", IDM_HELPmenuitem separatormenuitem "關(guān)于本程序...",IDM_ABOUTENDENDasm文件;
; Win32 菜單 Demo,by bobo.386.model flat, stdcalloption casemap :noneinclude \masm32\include\windows.inc include \masm32\include\user32.inc include \masm32\include\kernel32.inc includelib \masm32\lib\user32.lib includelib \masm32\lib\kernel32.lib; Equ 等值定義 ICO_MAIN equ 1000h ;圖標(biāo) IDM_MAIN equ 2000h ;菜單 IDM_HELP equ 4301h IDM_ABOUT equ 4302h IDM_ADDWZ equ 0x5001 IDM_UPDATEWZ equ 0x5002 IDM_DELWZ equ 0x5003 IDM_QUERYWZ equ 0x5004 IDM_ADDCK equ 0x6001 IDM_UPDATECK equ 0x6002 IDM_DELCK equ 0x6003 IDM_QUERYCK equ 0x6004; 數(shù)據(jù)段.data? hInstance dd ? hWinMain dd ? hMenu dd ?; 數(shù)據(jù)段.const szClassName db 'MIS Menu Demo',0 szCaptionMain db 'MIS Menu ',0 szMenuHelp db '幫助主題',0 szMenuAbout db '關(guān)于本程序...',0 szCaption db '菜單選擇',0 szFormat db '您選擇了菜單命令:%08x',0; 代碼段.code _DisplayMenuItem proc _dwCommandIDlocal @szBuffer[256]:bytepushadinvoke wsprintf,addr @szBuffer,addr szFormat,_dwCommandIDinvoke MessageBox,hWinMain,addr @szBuffer,offset szCaption,MB_OKpopadret_DisplayMenuItem endp_Quit procinvoke DestroyWindow,hWinMaininvoke PostQuitMessage,NULLret_Quit endp_ProcWinMain proc uses ebx edi esi hWnd,uMsg,wParam,lParammov eax,uMsg.if eax == WM_CREATE.elseif eax == WM_COMMANDinvoke _DisplayMenuItem,wParam.elseif eax == WM_CLOSEcall _Quit.elseinvoke DefWindowProc,hWnd,uMsg,wParam,lParamret.endif ;********************************************************************xor eax,eaxret_ProcWinMain endp ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> _WinMain proclocal @stWndClass:WNDCLASSEXlocal @stMsg:MSGlocal @hAcceleratorinvoke GetModuleHandle,NULLmov hInstance,eaxinvoke LoadMenu,hInstance,IDM_MAINmov hMenu,eax;******************************************************************** ; 注冊窗口類 ;********************************************************************invoke RtlZeroMemory,addr @stWndClass,sizeof @stWndClassinvoke LoadIcon,hInstance,ICO_MAINmov @stWndClass.hIcon,eaxmov @stWndClass.hIconSm,eaxinvoke LoadCursor,0,IDC_ARROWmov @stWndClass.hCursor,eaxpush hInstancepop @stWndClass.hInstancemov @stWndClass.cbSize,sizeof WNDCLASSEXmov @stWndClass.style,CS_HREDRAW or CS_VREDRAWmov @stWndClass.lpfnWndProc,offset _ProcWinMainmov @stWndClass.hbrBackground,COLOR_WINDOW + 1mov @stWndClass.lpszClassName,offset szClassNameinvoke RegisterClassEx,addr @stWndClass ;******************************************************************** ; 建立并顯示窗口 ;********************************************************************invoke CreateWindowEx,WS_EX_CLIENTEDGE,\offset szClassName,offset szCaptionMain,\WS_OVERLAPPEDWINDOW,\100,100,400,300,\NULL,hMenu,hInstance,NULLmov hWinMain,eaxinvoke ShowWindow,hWinMain,SW_SHOWNORMALinvoke UpdateWindow,hWinMain ;******************************************************************** ; 消息循環(huán) ;********************************************************************.while TRUEinvoke GetMessage,addr @stMsg,NULL,0,0.break .if eax == 0invoke TranslateAccelerator,hWinMain,@hAccelerator,addr @stMsg.if eax == 0invoke TranslateMessage,addr @stMsginvoke DispatchMessage,addr @stMsg.endif.endwret_WinMain endp ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> start:call _WinMaininvoke ExitProcess,NULL ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>end start命令行構(gòu)建:
G:\win32ASM\MISMenuDemo>set include=g:\masm32\include
G:\win32ASM\MISMenuDemo>set lib=g:\masm32\lib
G:\win32ASM\MISMenuDemo>set path=g:\masm32\bin;%path%
G:\win32ASM\MISMenuDemo>ml /c /coff wz.asm
Microsoft (R) Macro Assembler Version 6.14.8444
Copyright (C) Microsoft Corp 1981-1997. ?All rights reserved.
?Assembling: wz.asm
***********
ASCII build
***********
G:\win32ASM\MISMenuDemo>rc wz.rc
G:\win32ASM\MISMenuDemo>Link /subsystem:windows wz.obj wz.res
Microsoft (R) Incremental Linker Version 5.12.8078
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.
G:\win32ASM\MISMenuDemo>
結(jié)果;
?
資源文件里使用popup定義一個(gè)下拉出來的菜單項(xiàng),下拉出來的菜單項(xiàng)包含在BEGIN...END里面,使用menuitem定義一個(gè)菜單項(xiàng);
?
匯編代碼有2個(gè)子過程;_DisplayMenuItem,顯示單擊的菜單標(biāo)識(shí)值;_Quit,退出;
在主對話框過程里啥也沒干;當(dāng)單擊菜單,收到WM_COMMAND消息,執(zhí)行
invoke?? ?_DisplayMenuItem,wParam
顯示單擊的菜單標(biāo)識(shí)值;
?
在資源文件里面定義了各菜單標(biāo)識(shí)的值;在asm文件里面又定義了等值equ定義;這是啥情況;為什么要定義2次呢;云彬兄的Win32匯編程序里面也都包含這個(gè)equ等值定義;
搞C的時(shí)候,一般在resource.h文件里定義資源標(biāo)識(shí)的值,然后包含resource.h就可以了;
因?yàn)閰R編的時(shí)候各是各的,使用ml命令把a(bǔ)sm匯編為obj文件時(shí)需要資源標(biāo)識(shí)的值;rc文件是單獨(dú)編譯;使用rc命令把.rc文件編譯為.RES文件的時(shí)候,也需要資源標(biāo)識(shí)的值;這兩次各是各的;
所以需要等值定義;只是在asm集成開發(fā)環(huán)境里,ml和rc它一次幫你執(zhí)行了;代碼里是需要equ定義的;
?
此處,消息循環(huán)里,
invoke?? ?TranslateAccelerator,hWinMain,@hAccelerator,addr @stMsg
這句不能刪除;
?
總結(jié)
以上是生活随笔為你收集整理的Win32 ASM 菜单编程Demo以及Win32 ASM 为什么需要等值定义的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Win32 ASM 简单对话框编程Dem
- 下一篇: 一些SqlServer常见和入门操作