⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lion-tutorial09.htm

📁 内有一些代码
💻 HTM
📖 第 1 页 / 共 2 页
字号:
  <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  invoke SetWindowText,hwndEdit,ADDR TestString</b> <br>
  <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .ELSEIF 
  ax==IDM_CLEAR</b> <br>
  <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  invoke SetWindowText,hwndEdit,NULL</b> <br>
  <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .ELSEIF&nbsp; 
  ax==IDM_GETTEXT</b> <br>
  <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  invoke GetWindowText,hwndEdit,ADDR buffer,512</b> <br>
  <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  invoke MessageBox,NULL,ADDR buffer,ADDR AppName,MB_OK</b> <br>
  <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .ELSE</b> 
  <br>
  <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  invoke DestroyWindow,hWnd</b> <br>
  <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .ENDIF</b> 
  <br>
  <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .ELSE</b> <br>
  <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .IF ax==ButtonID</b> 
  <br>
  <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  shr eax,16</b> <br>
  <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  .IF ax==BN_CLICKED</b> <br>
  <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  invoke SendMessage,hWnd,WM_COMMAND,IDM_GETTEXT,0</b> <br>
  <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  .ENDIF</b> <br>
  <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .ENDIF</b> 
  <br>
  <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .ENDIF</b> <br>
  <b>&nbsp;&nbsp;&nbsp; .ELSE</b> <br>
  <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; invoke DefWindowProc,hWnd,uMsg,wParam,lParam</b> 
  <br>
  <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ret</b> <br>
  <b>&nbsp;&nbsp;&nbsp; .ENDIF</b> <br>
  <b>&nbsp;&nbsp;&nbsp;&nbsp; xor&nbsp;&nbsp;&nbsp; eax,eax</b> <br>
  <b>&nbsp;&nbsp;&nbsp; ret</b> <br>
  <b>WndProc endp</b> <br>
  <b>end start</b> 
<h3> <b>Analysis:</b></h3>
Let's analyze the program. 
<ul>
  <b>&nbsp;&nbsp;&nbsp; .ELSEIF uMsg==WM_CREATE</b> <br>
  <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; invoke CreateWindowEx,WS_EX_CLIENTEDGE, 
  \</b> <br>
  <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  ADDR EditClassName,NULL,\</b> <br>
  <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  WS_CHILD or WS_VISIBLE or WS_BORDER or ES_LEFT\</b> <br>
  <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  or ES_AUTOHSCROLL,\</b> <br>
  <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  50,35,200,25,hWnd,EditID,hInstance,NULL</b> <br>
  <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mov&nbsp; hwndEdit,eax</b> <br>
  <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; invoke SetFocus, hwndEdit</b> 
  <br>
  <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; invoke CreateWindowEx,NULL, ADDR 
  ButtonClassName,\</b> <br>
  <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  ADDR ButtonText,\</b> <br>
  <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  WS_CHILD or WS_VISIBLE or BS_DEFPUSHBUTTON,\</b> <br>
  <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  75,70,140,25,hWnd,ButtonID,hInstance,NULL</b> <br>
  <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mov&nbsp; hwndButton,eax</b> 
</ul>
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. <br>
After creating each control, we keep its handle in a variable for future use. 
<br>
SetFocus is called to give input focus to the edit box so the user can type the 
text into it immediately. <br>
Now comes the really exciting part. Every child window control sends notification 
to its parent window with WM_COMMAND. 
<p><b>&nbsp;&nbsp;&nbsp; .ELSEIF uMsg==WM_COMMAND</b> <br>
  <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mov eax,wParam</b> <br>
  <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .IF lParam==0</b> 
<p>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 <br>
  &nbsp; 
<center>
  <table BORDER width="100%" >
    <tr> 
      <td>&nbsp;</td>
      <td>Low word of wParam</td>
      <td>High word of wParam</td>
      <td>lParam</td>
    </tr>
    <tr> 
      <td>Menu</td>
      <td>Menu ID</td>
      <td>0</td>
      <td>0</td>
    </tr>
    <tr> 
      <td>Control</td>
      <td>Control ID</td>
      <td>Notification code</td>
      <td>Child Window Handle</td>
    </tr>
  </table>
</center>
<p>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. 
<p><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .IF ax==IDM_HELLO</b> 
  <br>
  <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  invoke SetWindowText,hwndEdit,ADDR TestString</b> <br>
  <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .ELSEIF 
  ax==IDM_CLEAR</b> <br>
  <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  invoke SetWindowText,hwndEdit,NULL</b> <br>
  <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .ELSEIF&nbsp; 
  ax==IDM_GETTEXT</b> <br>
  <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  invoke GetWindowText,hwndEdit,ADDR buffer,512</b> <br>
  <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  invoke MessageBox,NULL,ADDR buffer,ADDR AppName,MB_OK</b> 
<p>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. <br>
  To get the text in an edit box, you use GetWindowText. 
<p><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .IF ax==ButtonID</b> 
  <br>
  <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  shr eax,16</b> <br>
  <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  .IF ax==BN_CLICKED</b> <br>
  <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  invoke SendMessage,hWnd,WM_COMMAND,IDM_GETTEXT,0</b> <br>
  <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  .ENDIF</b> <br>
  <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .ENDIF</b> 
<p>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. <br>
  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. <br>
  You should use this technique as much as possible to make your code more organized. 
  <br>
  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. 
<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 + -