?? lion-tutorial10.htm
字號:
<br>
<b> mov hDlg,eax</b> <br>
<b> invoke ShowWindow, hDlg,SW_SHOWNORMAL</b> <br>
<b> invoke UpdateWindow, hDlg</b> <br>
<b> invoke GetDlgItem,hDlg,IDC_EDIT</b> <br>
<b> invoke SetFocus,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 IsDialogMessage, hDlg, ADDR msg</b>
<br>
<b> .IF eax ==FALSE</b> <br>
<b> invoke
TranslateMessage, ADDR msg</b> <br>
<b> invoke
DispatchMessage, ADDR msg</b> <br>
<b> .ENDIF</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_DESTROY</b> <br>
<b> invoke PostQuitMessage,NULL</b>
<br>
<b> .ELSEIF uMsg==WM_COMMAND</b> <br>
<b> mov eax,wParam</b> <br>
<b> .IF lParam==0</b> <br>
<b> .IF ax==IDM_GETTEXT</b>
<br>
<b>
invoke GetDlgItemText,hWnd,IDC_EDIT,ADDR buffer,512</b> <br>
<b>
invoke MessageBox,NULL,ADDR buffer,ADDR AppName,MB_OK</b> <br>
<b> .ELSEIF
ax==IDM_CLEAR</b> <br>
<b>
invoke SetDlgItemText,hWnd,IDC_EDIT,NULL</b> <br>
<b> .ELSE</b>
<br>
<b>
invoke DestroyWindow,hWnd</b> <br>
<b> .ENDIF</b>
<br>
<b> .ELSE</b> <br>
<b> mov edx,wParam</b>
<br>
<b> shr edx,16</b>
<br>
<b> .IF dx==BN_CLICKED</b>
<br>
<b>
.IF ax==IDC_BUTTON</b> <br>
<b>
invoke SetDlgItemText,hWnd,IDC_EDIT,ADDR TestString</b> <br>
<b>
.ELSEIF ax==IDC_EXIT</b> <br>
<b>
invoke SendMessage,hWnd,WM_COMMAND,IDM_EXIT,0</b> <br>
<b>
.ENDIF</b> <br>
<b> .ENDIF</b>
<br>
<b> .ENDIF</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> <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
3000</b> <br>
<b>#define IDC_BUTTON
3001</b> <br>
<b>#define IDC_EXIT
3002</b>
<p><b>#define IDM_GETTEXT
32000</b> <br>
<b>#define IDM_CLEAR
32001</b> <br>
<b>#define IDM_EXIT
32003</b> <br>
<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> EDITTEXT
IDC_EDIT, 15,17,111,13, ES_AUTOHSCROLL | ES_LEFT</b> <br>
<b> DEFPUSHBUTTON "Say Hello", IDC_BUTTON,
141,10,52,13</b> <br>
<b> PUSHBUTTON "E&xit",
IDC_EXIT, 141,26,52,13, WS_GROUP</b> <br>
<b>END</b> <br>
<p><b>MyMenu MENU</b> <br>
<b>BEGIN</b> <br>
<b> POPUP "Test Controls"</b> <br>
<b> BEGIN</b> <br>
<b> MENUITEM "Get Text", IDM_GETTEXT</b>
<br>
<b> MENUITEM "Clear Text", IDM_CLEAR</b>
<br>
<b> MENUITEM "", , 0x0800 /*MFT_SEPARATOR*/</b>
<br>
<b> MENUITEM "E&xit", IDM_EXIT</b>
<br>
<b> 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> EDITTEXT
IDC_EDIT, 15,17,111,13, ES_AUTOHSCROLL | ES_LEFT</b> <br>
<b> DEFPUSHBUTTON "Say Hello", IDC_BUTTON,
141,10,52,13</b> <br>
<b> PUSHBUTTON "E&xit",
IDC_EXIT, 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 "text" ,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 wc.cbWndExtra,DLGWINDOWEXTRA</b> <br>
<b>mov 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> <b>invoke IsDialogMessage, hDlg, ADDR
msg</b> <br>
<b> .IF eax ==FALSE</b> <br>
<b> invoke
TranslateMessage, ADDR msg</b> <br>
<b> invoke
DispatchMessage, ADDR msg</b> <br>
<b> .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 + -