?? tut9.html
字號:
ADDR EditClassName,NULL,\</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>
WS_CHILD or WS_VISIBLE or WS_BORDER or ES_LEFT\</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>
or ES_AUTOHSCROLL,\</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>
50,35,200,25,hWnd,EditID,hInstance,NULL</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>
mov hwndEdit,eax</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>
invoke SetFocus, hwndEdit</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>
invoke CreateWindowEx,NULL, ADDR ButtonClassName,\</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>
ADDR ButtonText,\</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>
WS_CHILD or WS_VISIBLE or BS_DEFPUSHBUTTON,\</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>
75,70,140,25,hWnd,ButtonID,hInstance,NULL</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>
mov hwndButton,eax</font></font></font></b></ul>
<font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>We create
the controls during processing of WM_CREATE message. We call CreateWindowEx
with an extra window style, WS_EX_CLIENTEDGE, which makes the client area
look sunken. The name of each control is a predefined one, "edit" for edit
control, "button" for button control. Next we specify the child window's
styles. Each control has extra styles in addition to the normal window
styles. For example, the button styles are prefixed with "BS_" for "button
style", edit styles are prefixed with "ES_" for "edit style". You have
to look these styles up in a Win32 API reference. Note that you put a control
ID in place of the menu handle. This doesn't cause any harm since a child
window control cannot have a menu.</font></font></font>
<br><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>After
creating each control, we keep its handle in a variable for future use.</font></font></font>
<br><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>SetFocus
is called to give input focus to the edit box so the user can type the
text into it immediately.</font></font></font>
<br><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>Now
comes the really exciting part. Every child window control sends notification
to its parent window with WM_COMMAND.</font></font></font><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1></font></font></font>
<p><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>
.ELSEIF uMsg==WM_COMMAND</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>
mov eax,wParam</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>
.IF lParam==0</font></font></font></b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1></font></font></font>
<p><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>Recall
that a menu also sends WM_COMMAND messages to notify the window about its
state too. How can you differentiate between WM_COMMAND messages originated
from a menu or a control? Below is the answer</font></font></font>
<br><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1></font></font></font>
<center><table BORDER WIDTH="100%" >
<tr>
<td><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1></font></font></font></td>
<td><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>Low
word of wParam</font></font></font></td>
<td><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>High
word of wParam</font></font></font></td>
<td><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>lParam</font></font></font></td>
</tr>
<tr>
<td><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>Menu</font></font></font></td>
<td><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>Menu
ID</font></font></font></td>
<td><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>0</font></font></font></td>
<td><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>0</font></font></font></td>
</tr>
<tr>
<td><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>Control</font></font></font></td>
<td><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>Control
ID</font></font></font></td>
<td><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>Notification
code</font></font></font></td>
<td><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>Child
Window Handle</font></font></font></td>
</tr>
</table></center>
<font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1></font></font></font>
<p><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>You
can see that you should check lParam. If it's zero, the current WM_COMMAND
message is from a menu. You cannot use wParam to differentiate between
a menu and a control since the menu ID and control ID may be identical
and the notification code may be zero.</font></font></font><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1></font></font></font>
<p><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>
.IF ax==IDM_HELLO</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>
invoke SetWindowText,hwndEdit,ADDR TestString</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>
.ELSEIF ax==IDM_CLEAR</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>
invoke SetWindowText,hwndEdit,NULL</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>
.ELSEIF ax==IDM_GETTEXT</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>
invoke GetWindowText,hwndEdit,ADDR buffer,512</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>
invoke MessageBox,NULL,ADDR buffer,ADDR AppName,MB_OK</font></font></font></b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1></font></font></font>
<p><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>You
can put a text string into an edit box by calling SetWindowText. You clear
the content of an edit box by calling SetWindowText with NULL. SetWindowText
is a general purpose API function. You can use SetWindowText to change
the caption of a window or the text on a button.</font></font></font>
<br><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>To
get the text in an edit box, you use GetWindowText.</font></font></font><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1></font></font></font>
<p><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>
.IF ax==ButtonID</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>
shr eax,16</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>
.IF ax==BN_CLICKED</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>
invoke SendMessage,hWnd,WM_COMMAND,IDM_GETTEXT,0</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>
.ENDIF</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>
.ENDIF</font></font></font></b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1></font></font></font>
<p><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>The
above code snippet deals with the condition when the user presses the button.
First, it checks the low word of wParam to see if the control ID matches
that of the button. If it is, it checks the high word of wParam to see
if it is the notification code BN_CLICKED which is sent when the button
is clicked.</font></font></font>
<br><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>The
interesting part is after it's certain that the notification code is BN_CLICKED.
We want to get the text from the edit box and display it in a message box.
We can duplicate the code in the IDM_GETTEXT section above but it doesn't
make sense. If we can somehow send a WM_COMMAND message with the low word
of wParam containing the value IDM_GETTEXT to our own window procedure,
we can avoid code duplication and simplify our program. SendMessage function
is the answer. This function sends any message to any window with any wParam
and lParam we want. So instead of duplicating the code, we call SendMessage
with the parent window handle, WM_COMMAND, IDM_GETTEXT, and 0. This has
identical effect to selecting "Get Text" menu item from the menu. The window
procedure doesn't perceive any difference between the two.</font></font></font>
<br><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>You
should use this technique as much as possible to make your code more organized.</font></font></font>
<br><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>Last
but not least, do not forget the TranslateMessage function in the message
loop. Since you must type in some text into the edit box, your program
must translate raw keyboard input into readable text. If you omit this
function, you will not be able to type anything into your edit box.</font></font></font>
<br>
<hr WIDTH="100%">
<center><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>[<a href="http://win32asm.cjb.net">Iczelion's
Win32 Assembly HomePage</a>]</font></font></font></b></center>
</body>
</html>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -