win32汇编环境,窗口程序中单选框的一般操作示例

;运行效果

;win32汇编环境,窗口程序中单选框的一般操作示例

;比如在窗口程序中生成单选框,默认哪项选中,判断当前选中哪一项,让哪项选中,得到选中项的名称等

;直接抄进RadAsm可编译运行。重点部分加备注。

;以下是ASM文件

;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

.386

.model flat,stdcall

option casemap:none

include windows.inc

include user32.inc

include kernel32.inc

include gdi32.inc

includelib kernel32.lib

includelib user32.lib

includelib gdi32.lib

;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

WinMain proto :DWORD,:DWORD,:DWORD,:DWORD

;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

.DATA

ClassName db "SimpleWinClass",0

AppName db "窗口程序的模版",0

szButtonClassName db "button",0 ;单选框属于按钮类名

szTitle db "提示",0

szCheckTitle db "请选一位美女",0

szCheckTitle01 db "西施",0

szCheckTitle02 db "绍婵",0

szCheckTitle03 db "妲已",0

szChecked01 db "当前选中的是: 西施",0

szChecked02 db "当前选中的是: 绍婵",0

szChecked03 db "当前选中的是: 妲已",0

szCheshi_Format01 db "得到的数字是 %d",0

szCheshi_Format02 db "得到的字符串的字节数是 %d",0

szButtonTitle01 db "点击查看当前选定了哪一项",0

szButtonTitle02 db "让所有项都处于未选中状态",0

szButtonTitle03 db "选中第3项",0

szButtonTitle04 db "得到第1项的名称",0

szButtonTitle05 db "得到第2个编辑框的密码",0

.DATA?

hInstance HINSTANCE ?

CommandLine LPSTR ?

hID_GROUP dd ? ;组框控件句柄

hID_CHECK01 dd ? ;单选框控件句柄

hID_CHECK02 dd ?

hID_CHECK03 dd ?

hIDB01 dd ? ;按钮控件句柄

hIDB02 dd ?

hIDB03 dd ?

hIDB04 dd ?

.CONST

;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>; Equ 等值定义;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

ID_CHECK01 equ 11 ;编辑框控件标识符

ID_CHECK02 equ 12

ID_CHECK03 equ 13

IDB01 equ 21 ;按钮控件标识符

IDB02 equ 22

IDB03 equ 23

IDB04 equ 24

;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

.CODE

start:

invoke GetModuleHandle, NULL

mov hInstance,eax

invoke GetCommandLine

mov CommandLine,eax

invoke WinMain, hInstance,NULL,CommandLine, SW_SHOWDEFAULT

invoke ExitProcess, eax

;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

WinMain proc hInst:HINSTANCE,hPrevInst:HINSTANCE,CmdLine:LPSTR,CmdShow:DWORD

LOCAL wc:WNDCLASSEX

LOCAL msg:MSG

LOCAL hwnd:HWND

mov wc.cbSize,SIZEOF WNDCLASSEX

mov wc.style, CS_HREDRAW or CS_VREDRAW

mov wc.lpfnWndProc, OFFSET WndProc

mov wc.cbClsExtra,NULL

mov wc.cbWndExtra,NULL

push hInstance

pop wc.hInstance

mov wc.hbrBackground,COLOR_WINDOW+1

mov wc.lpszMenuName,NULL

mov wc.lpszClassName,OFFSET ClassName

invoke LoadIcon,NULL,IDI_APPLICATION

mov wc.hIcon,eax

mov wc.hIconSm,eax

invoke LoadCursor,NULL,IDC_ARROW

mov wc.hCursor,eax

invoke RegisterClassEx, addr wc

invoke CreateWindowEx,NULL, ADDR ClassName,ADDR AppName,WS_CAPTION or WS_SYSMENU or WS_MINIMIZEBOX ,100,100,250,340, NULL,NULL,hInst, NULL

mov hwnd,eax

invoke ShowWindow, hwnd,CmdShow

invoke UpdateWindow, hwnd

.while TRUE

invoke GetMessage, ADDR msg,NULL,0,0

.break .if (!eax)

invoke TranslateMessage, ADDR msg

invoke DispatchMessage, ADDR msg

.endw

mov eax,msg.wParam

ret

WinMain endp

;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

WndProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM

LOCAL @DEFAULT_GUI_FONT,@OLD_DEFAULT_GUI_FONT

LOCAL @szBuffer[256]:byte

LOCAL @szBuffer01[256]:byte

.if uMsg == WM_CREATE

invoke CreateWindowEx,NULL,ADDR szButtonClassName,ADDR szCheckTitle, WS_TABSTOP OR WS_VISIBLE OR WS_CHILD OR BS_GROUPBOX,10,10,220,105,hWnd,NULL,NULL,NULL ;创建组框控件

mov hID_GROUP,eax

invoke CreateWindowEx,NULL,ADDR szButtonClassName,ADDR szCheckTitle01, WS_TABSTOP OR WS_VISIBLE OR WS_CHILD OR BS_AUTORADIOBUTTON,20,30,200,25,hWnd,ID_CHECK01,NULL,NULL ;创建单选框控件

mov hID_CHECK01,eax

invoke CreateWindowEx,NULL,ADDR szButtonClassName,ADDR szCheckTitle02, WS_TABSTOP OR WS_VISIBLE OR WS_CHILD OR BS_AUTORADIOBUTTON,20,55,200,25,hWnd,ID_CHECK02,NULL,NULL

mov hID_CHECK02,eax

invoke CreateWindowEx,NULL,ADDR szButtonClassName,ADDR szCheckTitle03, WS_TABSTOP OR WS_VISIBLE OR WS_CHILD OR BS_AUTORADIOBUTTON,20,80,200,25,hWnd,ID_CHECK03,NULL,NULL

mov hID_CHECK03,eax

invoke CreateWindowEx,NULL,ADDR szButtonClassName,ADDR szButtonTitle01, WS_TABSTOP OR WS_VISIBLE OR WS_CHILD OR BS_DEFPUSHBUTTON ,20,140,200,25,hWnd,IDB01,NULL,NULL ;创建按钮控件

mov hIDB01,eax

invoke CreateWindowEx,NULL,ADDR szButtonClassName,ADDR szButtonTitle02, WS_TABSTOP OR WS_VISIBLE OR WS_CHILD OR BS_DEFPUSHBUTTON ,20,180,200,25,hWnd,IDB02,NULL,NULL

mov hIDB02,eax

invoke CreateWindowEx,NULL,ADDR szButtonClassName,ADDR szButtonTitle03, WS_TABSTOP OR WS_VISIBLE OR WS_CHILD OR BS_DEFPUSHBUTTON ,20,220,200,25,hWnd,IDB03,NULL,NULL

mov hIDB03,eax

invoke CreateWindowEx,NULL,ADDR szButtonClassName,ADDR szButtonTitle04, WS_TABSTOP OR WS_VISIBLE OR WS_CHILD OR BS_DEFPUSHBUTTON ,20,260,200,25,hWnd,IDB04,NULL,NULL

mov hIDB04,eax

invoke GetStockObject,DEFAULT_GUI_FONT ;调用GetStockObject函数,得到系统默认字体

mov @DEFAULT_GUI_FONT,eax

invoke SendMessage,hID_GROUP,WM_SETFONT,@DEFAULT_GUI_FONT,TRUE ;发送WM_SETFONT消息,设置控件的字体

invoke SendMessage,hID_CHECK01,WM_SETFONT,@DEFAULT_GUI_FONT,TRUE

invoke SendMessage,hID_CHECK02,WM_SETFONT,@DEFAULT_GUI_FONT,TRUE

invoke SendMessage,hID_CHECK03,WM_SETFONT,@DEFAULT_GUI_FONT,TRUE

invoke SendMessage,hIDB01,WM_SETFONT,@DEFAULT_GUI_FONT,TRUE

invoke SendMessage,hIDB02,WM_SETFONT,@DEFAULT_GUI_FONT,TRUE

invoke SendMessage,hIDB03,WM_SETFONT,@DEFAULT_GUI_FONT,TRUE

invoke SendMessage,hIDB04,WM_SETFONT,@DEFAULT_GUI_FONT,TRUE

invoke DeleteObject,@DEFAULT_GUI_FONT ;删除本程序新建的字体

invoke CheckDlgButton,hWnd,ID_CHECK02,BST_CHECKED ;可以先初始化让哪个处于选定状态,初定为第2项

.elseif uMsg == WM_COMMAND

mov eax,wParam

.if lParam != 0

mov edx,wParam

shr edx,16

.if dx == BN_CLICKED

.if ax == IDB01

invoke IsDlgButtonChecked,hWnd,ID_CHECK01 ;检查第1项是否选中

.if eax == BST_CHECKED ;如果选中,则弹出提示

invoke MessageBox,NULL,addr szChecked01,addr szTitle,MB_OK

.endif

invoke IsDlgButtonChecked,hWnd,ID_CHECK02

.if eax == BST_CHECKED

invoke MessageBox,NULL,addr szChecked02,addr szTitle,MB_OK

.endif

invoke IsDlgButtonChecked,hWnd,ID_CHECK03

.if eax == BST_CHECKED

invoke MessageBox,NULL,addr szChecked03,addr szTitle,MB_OK

.endif

.elseif ax == IDB02

invoke CheckDlgButton,hWnd,ID_CHECK01,BST_UNCHECKED ;让3项都未选中

invoke CheckDlgButton,hWnd,ID_CHECK02,BST_UNCHECKED

invoke CheckDlgButton,hWnd,ID_CHECK03,BST_UNCHECKED

.elseif ax == IDB03

invoke CheckDlgButton,hWnd,ID_CHECK03,BST_CHECKED ;选中第3项

invoke CheckDlgButton,hWnd,ID_CHECK01,BST_UNCHECKED

invoke CheckDlgButton,hWnd,ID_CHECK02,BST_UNCHECKED

.elseif ax == IDB04

invoke GetDlgItemText,hWnd,ID_CHECK01,addr @szBuffer,sizeof @szBuffer ;得到第1项的名称

invoke MessageBox,hWnd,addr @szBuffer,addr szTitle,MB_OK or MB_ICONINFORMATION

.endif

.endif

.endif

.elseif uMsg==WM_DESTROY

invoke PostQuitMessage,NULL

.else

invoke DefWindowProc,hWnd,uMsg,wParam,lParam

ret

.endif

xor eax,eax

ret

WndProc endp

;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

end start

相关推荐
hummhumm7 小时前
第32章 汇编语言 - 实践项目:小型操作系统内核(一)
开发语言·汇编·数据库·算法·操作系统·程序设计·高级语言
雪碧透心凉_1 天前
Win32汇编学习笔记11.游戏辅助的实现
汇编·笔记·学习
撬动未来的支点2 天前
【汇编】x86汇编编程寄存器资源心中有数
汇编
贺鹏1234 天前
【Redis源码】 RedisObject结构体
汇编·redis
hummhumm4 天前
第27章 汇编语言--- 设备驱动开发基础
开发语言·汇编·后端·程序设计·设备驱动·高级语言·低级语言
雪碧透心凉_5 天前
Win32汇编学习笔记09.SEH和反调试
汇编·笔记·学习
傻童:CPU6 天前
乘法指令mul
汇编
Crossoads6 天前
【汇编语言】外中断(三)—— 探秘汇编外中断:从安装新INT 9例程到指令系统总结
android·开发语言·汇编·stm32·单片机·嵌入式硬件·dubbo
古井无波 20246 天前
arm64函数源码和汇编解析(objdump)
汇编