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

📄 lion-tutorial10.htm

📁 内有一些代码
💻 HTM
📖 第 1 页 / 共 3 页
字号:
  <br>
  <b>&nbsp;&nbsp;&nbsp; mov&nbsp;&nbsp; hDlg,eax</b> <br>
  <b>&nbsp;&nbsp;&nbsp; invoke ShowWindow, hDlg,SW_SHOWNORMAL</b> <br>
  <b>&nbsp;&nbsp;&nbsp; invoke UpdateWindow, hDlg</b> <br>
  <b>&nbsp;&nbsp;&nbsp; invoke GetDlgItem,hDlg,IDC_EDIT</b> <br>
  <b>&nbsp;&nbsp;&nbsp; invoke SetFocus,eax</b> <br>
  <b>&nbsp;&nbsp;&nbsp; .WHILE TRUE</b> <br>
  <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; invoke GetMessage, ADDR msg,NULL,0,0</b> 
  <br>
  <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .BREAK .IF (!eax)</b> <br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <b>invoke IsDialogMessage, hDlg, ADDR msg</b> 
  <br>
  <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .IF eax ==FALSE</b> <br>
  <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; invoke 
  TranslateMessage, ADDR msg</b> <br>
  <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; invoke 
  DispatchMessage, ADDR msg</b> <br>
  <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .ENDIF</b> <br>
  <b>&nbsp;&nbsp;&nbsp; .ENDW</b> <br>
  <b>&nbsp;&nbsp;&nbsp; mov&nbsp;&nbsp;&nbsp;&nbsp; eax,msg.wParam</b> <br>
  <b>&nbsp;&nbsp;&nbsp; ret</b> <br>
  <b>WinMain endp</b> 
<p><b>WndProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM</b> <br>
  <b>&nbsp;&nbsp;&nbsp; .IF uMsg==WM_DESTROY</b> <br>
  <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; invoke PostQuitMessage,NULL</b> 
  <br>
  <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> <br>
  <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .IF ax==IDM_GETTEXT</b> 
  <br>
  <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  invoke GetDlgItemText,hWnd,IDC_EDIT,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; .ELSEIF 
  ax==IDM_CLEAR</b> <br>
  <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  invoke SetDlgItemText,hWnd,IDC_EDIT,NULL</b> <br>
  <b>&nbsp;&nbsp;&nbs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p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  invoke SendMessage,hWnd,WM_COMMAND,IDM_EXIT,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; xor&nbsp;&nbsp;&nbsp; eax,eax</b> <br>
  <b>&nbsp;&nbsp;&nbsp; ret</b> <br>
  <b>WndProc endp</b> <br>
  <b>end start</b> <br>
<hr width="100%">
<center>
  <b>Dialog.rc</b> 
</center>
<hr width="100%">
<br>
<b>#include "resource.h"</b> 
<p><b>#define IDC_EDIT&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  3000</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sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  32003</b> <br>
  &nbsp; 
<p><b>MyDialog DIALOG 10, 10, 205, 60</b> <br>
  <b>STYLE 0x0004 | DS_CENTER | WS_CAPTION | WS_MINIMIZEBOX |</b> <br>
  <b>WS_SYSMENU | WS_VISIBLE | WS_OVERLAPPED | DS_MODALFRAME | DS_3DLOOK</b> <br>
  <b>CAPTION "Our First Dialog Box"</b> <br>
  <b>CLASS "DLGCLASS"</b> <br>
  <b>BEGIN</b> <br>
  <b>&nbsp;&nbsp;&nbsp; EDITTEXT&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  IDC_EDIT,&nbsp;&nbsp; 15,17,111,13, ES_AUTOHSCROLL | ES_LEFT</b> <br>
  <b>&nbsp;&nbsp;&nbsp; DEFPUSHBUTTON&nbsp;&nbsp; "Say Hello", IDC_BUTTON,&nbsp;&nbsp;&nbsp; 
  141,10,52,13</b> <br>
  <b>&nbsp;&nbsp;&nbsp; PUSHBUTTON&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "E&amp;xit", 
  IDC_EXIT,&nbsp; 141,26,52,13, WS_GROUP</b> <br>
  <b>END</b> <br>
  &nbsp; 
<p><b>MyMenu&nbsp; MENU</b> <br>
  <b>BEGIN</b> <br>
  <b>&nbsp;&nbsp;&nbsp; POPUP "Test Controls"</b> <br>
  <b>&nbsp;&nbsp;&nbsp; BEGIN</b> <br>
  <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MENUITEM "Get Text", IDM_GETTEXT</b> 
  <br>
  <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MENUITEM "Clear Text", IDM_CLEAR</b> 
  <br>
  <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MENUITEM "", , 0x0800 /*MFT_SEPARATOR*/</b> 
  <br>
  <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MENUITEM "E&amp;xit", IDM_EXIT</b> 
  <br>
  <b>&nbsp;&nbsp;&nbsp; END</b> <br>
  <b>END</b> 
<h3> Analysis:</h3>
Let's analyze this first example. <br>
This example shows how to register a dialog template as a window class and create 
a "window" from that class. It simplifies your program since you don't have to 
create the child window controls yourself. <br>
Let's first analyze the dialog template. 
<p><b>MyDialog DIALOG 10, 10, 205, 60</b> 
<p>Declare the name of a dialog, in this case, "MyDialog" followed by the keyword 
  "DIALOG". The following four numbers are: x, y , width, and height of the dialog 
  box in dialog box units (not the same as pixels). 
<p><b>STYLE 0x0004 | DS_CENTER | WS_CAPTION | WS_MINIMIZEBOX |</b> <br>
  <b>WS_SYSMENU | WS_VISIBLE | WS_OVERLAPPED | DS_MODALFRAME | DS_3DLOOK</b> 
<p>Declare the styles of the dialog box. 
<p><b>CAPTION "Our First Dialog Box"</b> 
<p>This is the text that will appear in the dialog box's title bar. 
<p><b>CLASS "DLGCLASS"</b> 
<p>This line is crucial. It's this <b>CLASS</b> keyword that allows us to use 
  the dialog box template as a window class. Following the keyword is the name 
  of the "window class" 
<p><b>BEGIN</b> <br>
  <b>&nbsp;&nbsp;&nbsp; EDITTEXT&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  IDC_EDIT,&nbsp;&nbsp; 15,17,111,13, ES_AUTOHSCROLL | ES_LEFT</b> <br>
  <b>&nbsp;&nbsp;&nbsp; DEFPUSHBUTTON&nbsp;&nbsp; "Say Hello", IDC_BUTTON,&nbsp;&nbsp;&nbsp; 
  141,10,52,13</b> <br>
  <b>&nbsp;&nbsp;&nbsp; PUSHBUTTON&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "E&amp;xit", 
  IDC_EXIT,&nbsp; 141,26,52,13</b> <br>
  <b>END</b> 
<p>The above block defines the child window controls in the dialog box. They're 
  defined between <b>BEGIN</b> and <b>END</b> keywords. Generally the syntax is 
  as follows: 
<ul>
  <b>control-type&nbsp; "text"&nbsp;&nbsp; ,controlID, x, y, width, height [,styles]</b> 
</ul>
control-types are resource compiler's constants so you have to consult the manual. 
<br>
Now we go to the assembly source code. The interesting part is in the window class 
structure: 
<ul>
  <b>mov&nbsp;&nbsp; wc.cbWndExtra,DLGWINDOWEXTRA</b> <br>
  <b>mov&nbsp;&nbsp; wc.lpszClassName,OFFSET ClassName</b> 
</ul>
Normally, this member is left NULL, but if we want to register a dialog box template 
as a window class, we must set this member to the value<b> DLGWINDOWEXTRA</b>. 
Note that the name of the class must be identical to the one following the <b>CLASS</b> 
keyword in the dialog box template. The remaining members are initialized as usual. 
After you fill the window class structure, register it with RegisterClassEx. Seems 
familiar? This is the same routine you have to do in order to register a normal 
window class. 
<ul>
  <b>invoke CreateDialogParam,hInstance,ADDR DlgName,NULL,NULL,NULL</b> 
</ul>
After registering the "window class", we create our dialog box. In this example, 
I create it as a modeless dialog box with CreateDialogParam function. This function 
takes 5 parameters but you only have to fill in the first two: the instance handle 
and the pointer to the name of the dialog box template. Note that the 2nd parameter 
is not a pointer to the class name. <br>
At this point, the dialog box and its child window controls are created by Windows. 
Your window procedure will receive WM_CREATE message as usual. 
<ul>
  <b>invoke GetDlgItem,hDlg,IDC_EDIT</b> <br>
  <b>invoke SetFocus,eax</b> 
</ul>
After the dialog box is created, I want to set the input focus to the edit control. 
If I put these codes in WM_CREATE section, GetDlgItem call will fail since at 
that time, the child window controls are not created yet. The only way you can 
do this is to call it after the dialog box and all its child window controls are 
created. So I put these two lines after the UpdateWindow call. GetDlgItem function 
gets the control ID and returns the associated control's window handle. This is 
how you can get a window handle if you know its control ID. 
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <b>invoke IsDialogMessage, hDlg, ADDR 
  msg</b> <br>
  <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .IF eax ==FALSE</b> <br>
  <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; invoke 
  TranslateMessage, ADDR msg</b> <br>
  <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; invoke 
  DispatchMessage, ADDR msg</b> <br>
  <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .ENDIF</b> 
<p>The program enters the message loop and before we translate and dispatch messages, 
  we call IsDialogMessage function to let the dialog box manager handles the keyboard 
  logic of our dialog box for us. If this function returns TRUE , it means the 
  message is intended for the dialog box and is processed by the dialog box manager. 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -