WIN32汇编为按钮添加处理过程
来源:互联网 发布:sap 物料主数据 编辑:程序博客网 时间:2024/05/19 17:47
由于笔者也是初学者,学到哪,也就写到哪,望各位大神见谅哈,本博文呢,主要是在主窗体中添加了一个button,但是该Button是动态添加的,也就是说使用了
CreateWindowEx API函数,同时为该按钮的点击事件添加处理过程:
先说下原理,其实呢,很简单,就是先检查uMsg是否是WM_COMMAND,然后呢,就看看,触发事件的控件的ID是否使我们要处理的控件的ID,就这两样,但是呢由于我们使用
的是CreateWindowEx API,动态创建的按钮,其ID我们并不清楚,但是一点,就是CreateWindowEx中的HMENU可以作为控件的ID传递进来,而后我们根据该ID,我们进行处理!
.386.Model Flat,stdcalloption casemap:none;头文件包含include windows.incinclude kernel32.incincludelib kernel32.libinclude user32.incincludelib user32.libinclude gdi32.incincludelib gdi32.lib;数据段定义.datahInstance dd ?hWinMain dd ?hButton dd ?;常量定义.constszClassName db "MyClass",0szCaption db "My FirstWindow",0szText db "这是我的第二个程序",0szButton db "Button",0;szButtonText db "ButtonText",0szBuffer db "点击了按钮",0;代码段定义.code;窗口的消息处理函数WinProc proc uses ebx edi esi,hWnd,uMsg,wParam,lParam;局部变量的定义local @stPs:PAINTSTRUCTlocal @stRect:RECT;local @hDc;mov eax,uMsg;.if eax == WM_PAINT invoke BeginPaint,hWnd,addr @stPs; mov @hDc,eax; invoke GetClientRect,hWnd,addr @stRect; invoke DrawText,@hDc,addr szText,-1,addr @stRect,\ DT_SINGLELINE or DT_CENTER or DT_VCENTER; invoke EndPaint,hWnd,addr @stPs;.elseif eax == WM_CLOSE invoke DestroyWindow,hWinMain; invoke PostQuitMessage,NULL;.elseif eax==WM_CREATE invoke CreateWindowEx,NULL,\ offset szButton,offset szButtonText,WS_CHILD or WS_VISIBLE,10,10,65,22,hWnd,1001,hInstance,NULL; mov hButton,eax.elseif eax==WM_COMMAND mov eax,wParam .if ax==1001invoke MessageBox,NULL,addr szBuffer,NULL,NULL; .endif.else invoke DefWindowProc,hWnd,uMsg,wParam,lParam; ret;该ret非常重要,如果没有ret,就相当于多数消息没有正确的返回值,则,窗口不能正常工作.endif xor eax,eax retWinProc endp;;主函数_WinMain proc local @stWndClass:WNDCLASSEX; local @stMsg:MSG; invoke GetModuleHandle,NULL; mov hInstance,eax invoke RtlZeroMemory,addr @stWndClass,sizeof @stWndClass;;注册窗口类 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 WinProc; mov @stWndClass.hbrBackground,COLOR_WINDOW+1; mov @stWndClass.lpszClassName,offset szClassName; invoke RegisterClassEx,addr @stWndClass;;建立便显示窗口 invoke CreateWindowEx,WS_EX_CLIENTEDGE,\ offset szClassName,offset szCaption,\ WS_OVERLAPPED,100,100,600,400,\ NULL,NULL,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;start: call _WinMain;invoke ExitProcess,0;.while TRUE.endwend start嗯,就是这样了,不过我在学习过程中遇到了一点小小的问题,就是.if的嵌套使用,
在.elseif eax==WM_COMMAND
mov eax,wParam;
.if ax,1001;过程中遇到了问题,就是不能正确的编译成功,如果要嵌套使用if语句,要注意还要有.if的闭合语句.endif
- WIN32汇编为按钮添加处理过程
- win32 application 添加按钮
- Win32 汇编子过程总结
- 为按钮添加图标
- WIN32汇编: 6.处理键盘消息
- WIN32汇编: 7.处理鼠标输入消息
- 【Android 开发入门】为按钮添加Click单击事件处理程序,显示/隐藏另一个按钮
- Win32编程---在窗体添加一个按钮
- win32,按钮处理鼠标滑过消息
- WIN32汇编-单选按钮组的设置
- QT用信号和处理机制为事件添加处理动作(点击按钮显示helloworld)
- WPF 为按钮添加Tooltip
- 为导航条添加按钮
- VC++为工具栏添加按钮
- 为SM30 视图添加按钮
- MFC为按钮添加BITMAP
- 为网站添加分享按钮
- 为按钮控件添加提示
- c++ union的使用
- java网络编程
- Linux 下常用的 19 条命令
- 获取某路径的所有目录名 获取某路径的所有文件名(要么只有文件名,要么只有目录名)
- 网站特殊字体处理
- WIN32汇编为按钮添加处理过程
- 用python写了一个简单的模拟浏览器抓取网页的库webclient
- 任务并行的几种方式
- iOS ftp上传
- 利用outline固定执行计划
- hdu 4742 Pinball Game 3D 分治+树状数组
- 获取Feature版本
- 获取盘符
- 函数通用性之重载与(导出模板概念)