📄 lion-tutorial20.htm
字号:
<b> CW_USEDEFAULT,350,200,NULL,NULL,\</b>
<br>
<b> hInst,NULL</b>
<br>
<b> mov hwnd,eax</b> <br>
<b> .while TRUE</b> <br>
<b> invoke GetMessage, ADDR msg,NULL,0,0</b>
<br>
<b> .BREAK .IF (!eax)</b> <br>
<b> invoke TranslateMessage, ADDR
msg</b> <br>
<b> invoke DispatchMessage, ADDR msg</b>
<br>
<b> .endw</b> <br>
<b> mov eax,msg.wParam</b> <br>
<b> ret</b> <br>
<b>WinMain endp</b>
<p><b>WndProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM</b> <br>
<b> .if uMsg==WM_CREATE</b> <br>
<b> invoke CreateWindowEx,WS_EX_CLIENTEDGE,ADDR
EditClass,NULL,\</b> <br>
<b> WS_CHILD+WS_VISIBLE+WS_BORDER,20,\</b>
<br>
<b> 20,300,25,hWnd,NULL,\</b>
<br>
<b> hInstance,NULL</b>
<br>
<b> mov hwndEdit,eax</b> <br>
<b> invoke SetFocus,eax</b> <br>
<b> ;-----------------------------------------</b>
<br>
<b> ; Subclass it!</b> <br>
<b> ;-----------------------------------------</b>
<br>
<b> invoke SetWindowLong,hwndEdit,GWL_WNDPROC,addr
EditWndProc</b> <br>
<b> mov OldWndProc,eax</b> <br>
<b> .elseif uMsg==WM_DESTROY</b> <br>
<b> invoke PostQuitMessage,NULL</b>
<br>
<b> .else</b> <br>
<b> invoke DefWindowProc,hWnd,uMsg,wParam,lParam</b>
<br>
<b> ret</b> <br>
<b> .endif</b> <br>
<b> xor eax,eax</b> <br>
<b> ret</b> <br>
<b>WndProc endp</b>
<p><b>EditWndProc PROC hEdit:DWORD,uMsg:DWORD,wParam:DWORD,lParam:DWORD</b> <br>
<b> .if uMsg==WM_CHAR</b> <br>
<b> mov eax,wParam</b> <br>
<b> .if (al>="0" && al<="9")
|| (al>="A" && al<="F") || (al>="a" && al<="f") || al==VK_BACK</b>
<br>
<b> .if al>="a"
&& al<="f"</b> <br>
<b>
sub al,20h</b> <br>
<b> .endif</b>
<br>
<b> invoke
CallWindowProc,OldWndProc,hEdit,uMsg,eax,lParam</b> <br>
<b> ret</b>
<br>
<b> .endif</b> <br>
<b> .elseif uMsg==WM_KEYDOWN</b> <br>
<b> mov eax,wParam</b> <br>
<b> .if al==VK_RETURN</b> <br>
<b> invoke
MessageBox,hEdit,addr Message,addr AppName,MB_OK+MB_ICONINFORMATION</b> <br>
<b> invoke
SetFocus,hEdit</b> <br>
<b> .else</b> <br>
<b> invoke
CallWindowProc,OldWndProc,hEdit,uMsg,wParam,lParam</b> <br>
<b> ret</b>
<br>
<b> .endif</b> <br>
<b> .else</b> <br>
<b> invoke CallWindowProc,OldWndProc,hEdit,uMsg,wParam,lParam</b>
<br>
<b> ret</b> <br>
<b> .endif</b> <br>
<b> xor eax,eax</b> <br>
<b> ret</b> <br>
<b>EditWndProc endp</b> <br>
<b>end start</b>
<h3> Analysis:</h3>
<ul>
<b> invoke SetWindowLong,hwndEdit,GWL_WNDPROC,addr
EditWndProc</b> <br>
<b> mov OldWndProc,eax</b>
</ul>
After the edit control is created, we subclass it by calling SetWindowLong, replacing
the address of the original window procedure with our own window procedure. Note
that we store the address of the original window procedure for use with CallWindowProc.
Note the EditWndProc is an ordinary window procedure.
<ul>
<b> .if uMsg==WM_CHAR</b> <br>
<b> mov eax,wParam</b> <br>
<b> .if (al>="0" && al<="9")
|| (al>="A" && al<="F") || (al>="a" && al<="f") || al==VK_BACK</b>
<br>
<b> .if al>="a"
&& al<="f"</b> <br>
<b>
sub al,20h</b> <br>
<b> .endif</b>
<br>
<b> invoke
CallWindowProc,OldWndProc,hEdit,uMsg,eax,lParam</b> <br>
<b> ret</b>
<br>
<b> .endif</b>
</ul>
Within EditWndProc, we filter WM_CHAR messages. If the character is between 0-9
or a-f, we accept it by passing along the message to the original window procedure.
If it is a lower case character, we convert it to upper case by adding it with
20h. Note that, if the character is not the one we expect, we discard it. We don't
pass it to the original window proc. So when the user types something other than
0-9 or a-f, the character just doesn't appear in the edit control.
<ul>
<b> .elseif uMsg==WM_KEYDOWN</b> <br>
<b> mov eax,wParam</b> <br>
<b> .if al==VK_RETURN</b> <br>
<b> invoke
MessageBox,hEdit,addr Message,addr AppName,MB_OK+MB_ICONINFORMATION</b> <br>
<b> invoke
SetFocus,hEdit</b> <br>
<b> .else</b> <br>
<b> invoke
CallWindowProc,OldWndProc,hEdit,uMsg,wParam,lParam</b> <br>
<b> ret</b>
<br>
<b> .end</b>
</ul>
I want to demonstrate the power of subclassing further by trapping Enter key.
EditWndProc checks WM_KEYDOWN message if it's VK_RETURN (the Enter key). If it
is, it displays a message box saying "You pressed the Enter key in the text box!".
If it's not an Enter key, it passes the message to the original window procedure.
<br>
You can use window subclassing to take control over other windows. It's one of
the powerful techniques you should have in your arsenal.
<hr size="1">
<div align="center"> This article come from Iczelion's asm page, Welcom to <a href="http://asm.yeah.net">http://asm.yeah.net</a></div>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -