Win32汇编--加载菜单资源

基本上的窗口都会有一个菜单,现在就来看看Win32汇编中是如何加载菜单的:

1>在工程中添加新的菜单资源

2>双击新添加的菜单资源进行编辑

3>菜单栏:Make->Compile RC来编译资源文件

4>导出资源中的ID号并写到数据段的.const中

5>下面是完整的源代码供参考:(工程下载地址)

.386 .model flat,stdcall option casemap:none include windows.inc include kernel32.inc include user32.inc include debug.inc includelib kernel32.lib includelib user32.lib includelib debug.lib .data? hInstance dd ? hWinMain dd ? hMenu dd ? .const szClassName db 'MyClass',0 szCaption db 'My Window',0 ;---------------------------------------- IDR_MENU equ 10000 IDM_FILE equ 10001 IDM_OPEN equ 10003 IDM_EXIT equ 10002 IDM_EDIT equ 10004 IDM_COPY equ 10005 .code _WinMain proc LOCAL @stWndClass:WNDCLASSEX LOCAL @stMsg:MSG ;-------------------------- invoke RtlZeroMemory,addr @stWndClass,sizeof @stWndClass ;-------------------------- invoke GetModuleHandle,NULL mov hInstance,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_WINDOW+1 mov @stWndClass.lpszClassName,offset szClassName invoke LoadCursor,0,IDC_ARROW mov @stWndClass.hCursor,eax ;-------------[Regist Window]------------- invoke RegisterClassEx,addr @stWndClass ;------------[Load Menu]------------------ invoke LoadMenu,hInstance,IDR_MENU mov hMenu,eax ;-------------[Create Window]------------- invoke CreateWindowEx,WS_EX_CLIENTEDGE,offset szClassName,\ offset szCaption,WS_OVERLAPPEDWINDOW,100,100,600,400,\ NULL,hMenu,hInstance,NULL mov hWinMain,eax ;-------------------------- 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 ;==================================================== _ProcWinMain proc uses ebx esi edi hWnd,uMsg,wParam,lParam mov eax,uMsg .if eax==WM_CREATE .elseif eax==WM_CLOSE invoke DestroyWindow,hWinMain invoke PostQuitMessage,NULL .elseif eax==WM_COMMAND mov eax,wParam .if ax==IDM_EXIT invoke DestroyWindow,hWinMain invoke PostQuitMessage,NULL .endif .elseif invoke DefWindowProc,hWnd,uMsg,wParam,lParam ret .endif xor eax,eax ret _ProcWinMain endp ;==================================================== start: call _WinMain invoke ExitProcess,NULL end start

转载于:https://www.cnblogs.com/wbbice/archive/2012/09/03/2668400.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值