Win32汇编--加速键
加速键资源在编辑中也时常用到,比如Ctrl+A,Ctrl+Z等等,现在就介绍一下在Win32汇编中如何使用加速键资源,
本例中按”Ctrl+O”会弹出一个消息框,按”Ctrl+E”则会在弹出一个消息框之后关闭窗口:
1>新键一个工程,创建一个新的窗口.
2>在资源中添加\’加速键\’资源
首先,用ResEdit(下载:32位,64位)打开工程中的资源文件,然后添加新的加速键资源:
然后,在.const中写上资源的ID号:
接着,对原来的消息循环进行修改,在TranslateMessage和DispatchMessage之前TranslateMeeage:
最后,在WM_COMMAND中对消息作出具体的响应:
下面给出全部源代码(完整工程下载)
.dp-highlighter { font-family: “Consolas”, “Courier New”, Courier, mono, serif; font-size: 16px; background-color: rgba(231, 229, 220, 1); width: 99%; overflow: auto; margin: 18px 0 !important; padding-top: 1px }
.dp-highlighter ol, .dp-highlighter ol li, .dp-highlighter ol li span { margin: 0; padding: 0; border: none }
.dp-highlighter a, .dp-highlighter a:hover { background: none; border: none; padding: 0; margin: 0 }
.dp-highlighter .bar { padding-left: 45px }
.dp-highlighter.collapsed .bar, .dp-highlighter.nogutter .bar { padding-left: 0 }
.dp-highlighter ol { list-style: decimal; background-color: rgba(255, 255, 255, 1); margin: 0 0 1px !important; padding: 0; color: rgba(92, 92, 92, 1) }
.dp-highlighter.nogutter ol, .dp-highlighter.nogutter ol li { list-style: none !important; margin-left: 0 !important }
.dp-highlighter ol li, .dp-highlighter .columns div { list-style-type: decimal-leading-zero; list-style-position: outside !important; list-style-image: initial; border-left: 3px solid rgba(108, 226, 108, 1); background-color: rgba(248, 248, 248, 1); color: rgba(92, 92, 92, 1); padding: 0 3px 0 10px !important; margin: 0 !important; line-height: 19px }
.dp-highlighter.nogutter ol li, .dp-highlighter.nogutter .columns div { border: 0 }
.dp-highlighter .columns { background-color: rgba(248, 248, 248, 1); color: rgba(128, 128, 128, 1); overflow: hidden; width: 100% }
.dp-highlighter .columns div { padding-bottom: 5px }
.dp-highlighter ol li.alt { background-color: rgba(255, 255, 255, 1); color: inherit }
.dp-highlighter ol li span { color: rgba(0, 0, 0, 1); background-color: inherit }
.dp-highlighter.collapsed ol { margin: 0 }
.dp-highlighter.collapsed ol li { display: none }
.dp-highlighter.printing { border: none }
.dp-highlighter.printing .tools { display: none !important }
.dp-highlighter.printing li { display: list-item !important }
.dp-highlighter .tools { padding: 3px 8px 10px 10px; font: 9px Verdana, Geneva, Arial, Helvetica, sans-serif; color: rgba(192, 192, 192, 1); background-color: rgba(248, 248, 248, 1); border-left: 3px solid rgba(108, 226, 108, 1) }
.dp-highlighter.nogutter .tools { border-left: 0 }
.dp-highlighter.collapsed .tools { border-bottom: 0 }
.dp-highlighter .tools a { font-size: 9px; color: rgba(160, 160, 160, 1); background-color: inherit; text-decoration: none; margin-right: 10px }
.dp-highlighter .tools a:hover { color: rgba(255, 0, 0, 1); background-color: inherit; text-decoration: underline }
.dp-about { background-color: rgba(255, 255, 255, 1); color: rgba(51, 51, 51, 1); margin: 0; padding: 0 }
.dp-about table { width: 100%; height: 100%; font-size: 11px; font-family: Tahoma, Verdana, Arial, sans-serif !important }
.dp-about td { padding: 10px; vertical-align: top }
.dp-about .copy { border-bottom: 1px solid rgba(172, 168, 153, 1); height: 95% }
.dp-about .title { color: rgba(255, 0, 0, 1); background-color: inherit; font-weight: bold }
.dp-about .para { margin: 0 0 4px }
.dp-about .footer { background-color: rgba(236, 234, 219, 1); color: rgba(51, 51, 51, 1); border-top: 1px solid rgba(255, 255, 255, 1); text-align: right }
.dp-about .close { font-size: 11px; font-family: Tahoma, Verdana, Arial, sans-serif !important; background-color: rgba(236, 234, 219, 1); color: rgba(51, 51, 51, 1); width: 60px; height: 22px }
.dp-highlighter .comment, .dp-highlighter .comments { color: rgba(0, 130, 0, 1); background-color: inherit }
.dp-highlighter .string { color: rgba(0, 0, 255, 1); background-color: inherit }
.dp-highlighter .keyword { color: rgba(0, 102, 153, 1); font-weight: bold; background-color: inherit }
.dp-highlighter .preprocessor { color: rgba(128, 128, 128, 1); background-color: inherit }
.dp-highlighter .asmkeyword { color: rgba(128, 0, 175, 1); background-color: inherit }
.dp-highlighter .asmlib { color: rgba(204, 0, 204, 1); background-color: inherit }
.dp-highlighter .asmreg { color: rgba(255, 41, 0, 1); background-color: inherit }
.dp-highlighter .asmreserved { color: rgba(0, 102, 153, 1); background-color: inherit }
.dp-highlighter .asmjumper { color: rgba(255, 122, 0, 1); background-color: inherit }
.dp-highlighter .asmdescript { color: rgba(0, 37, 204, 1); background-color: inherit }
.dp-highlighter .asmfunction { color: rgba(204, 0, 204, 1); background-color: inherit }
.dp-highlighter .jiankuohao { color: rgba(0, 0, 0, 1); background-color: inherit }
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 ?
.const
szClassName db \’MyClass\’,0
szCaption db \’My Window\’,0
;——————————————-
IDR_ACCELERATOR equ 101
ID_ACC1 equ 40000
ID_ACC2 equ 40001
.code
_WinMain proc
LOCAL @stWndClass:WNDCLASSEX
LOCAL @stMsg:MSG
LOCAL @hAcc
;————————–
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
;————————–
invoke RegisterClassEx,addr @stWndClass
;————————–
invoke CreateWindowEx,WS_EX_CLIENTEDGE,offset szClassName,\
offset szCaption,WS_OVERLAPPEDWINDOW,100,100,600,400,\
NULL,NULL,hInstance,NULL
mov hWinMain,eax
;————————–
invoke ShowWindow,hWinMain,SW_SHOWNORMAL
;————————–
invoke UpdateWindow,hWinMain
;——————–[Load accelerator]————
invoke LoadAccelerators,hInstance,IDR_ACCELERATOR
mov @hAcc,eax
.while TRUE
invoke GetMessage,addr @stMsg,NULL,0,0
.break .if eax==0
;—————-[handle accelerators\’ message]———
invoke TranslateAccelerator,hWinMain,@hAcc,addr @stMsg
.if eax==0 ;if “TranslateAccelerator” doesn\’t handle the message
invoke TranslateMessage,addr @stMsg
invoke DispatchMessage,addr @stMsg
.endif
.endw
ret
_WinMain endp
;====================================================
_ProcWinMain proc uses ebx esi edi hWnd,uMsg,wParam,lParam
mov eax,uMsg
.if eax==WM_CLOSE
invoke DestroyWindow,hWinMain
invoke PostQuitMessage,NULL
.elseif eax==WM_COMMAND
mov eax,wParam
.if ax==ID_ACC1
invoke MessageBox,NULL,CTEXT(“Ctrl+O Pressed”),CTEXT(“INFO”),MB_OK
.elseif ax==ID_ACC2
invoke MessageBox,NULL,CTEXT(“Ctrl+E Pressed, Program will exit now”),CTEXT(“INFO”),MB_OK
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