📄 tut10.html
字号:
class structure:</font></font></font>
<ul><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>mov
wc.cbWndExtra,DLGWINDOWEXTRA</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>mov
wc.lpszClassName,OFFSET ClassName</font></font></font></b></ul>
<font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>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.</font></font></font>
<ul><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>invoke
CreateDialogParam,hInstance,ADDR DlgName,NULL,NULL,NULL</font></font></font></b></ul>
<font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>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.</font></font></font>
<br><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>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.</font></font></font>
<ul><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>invoke
GetDlgItem,hDlg,IDC_EDIT</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>invoke
SetFocus,eax</font></font></font></b></ul>
<font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>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.</font></font></font>
<p><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>
<b>invoke IsDialogMessage, hDlg, ADDR msg</b></font></font></font>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>
.IF eax ==FALSE</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>
invoke TranslateMessage, ADDR msg</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>
invoke DispatchMessage, ADDR msg</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>
.ENDIF</font></font></font></b>
<p><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>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. Note another difference from the previous tutorial.
When the window procedure wants to get the text from the edit control,
it calls GetDlgItemText function instead of GetWindowText. GetDlgItemText
accepts a control ID instead of a window handle. That makes the call easier
in the case you use a dialog box.</font></font></font>
<br>
<hr WIDTH="100%">
<br><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>Now
let's go to the second approach to using a dialog box as a main window.
In the next example, I 'll create an application modal dialog box. You'll
not find a message loop or a window procedure because they're not necessary!</font></font></font>
<hr WIDTH="100%">
<center><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>dialog.asm
(part 2)</font></font></font></b></center>
<hr WIDTH="100%">
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>.386</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>.model
flat,stdcall</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>option
casemap:none</font></font></font></b><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1></font></font></font></b>
<p><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>DlgProc
proto :DWORD,:DWORD,:DWORD,:DWORD</font></font></font></b><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1></font></font></font></b>
<p><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>include
\masm32\include\windows.inc</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>include
\masm32\include\user32.inc</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>include
\masm32\include\kernel32.inc</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>includelib
\masm32\lib\user32.lib</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>includelib
\masm32\lib\kernel32.lib</font></font></font></b>
<p><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>.data</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>DlgName
db "MyDialog",0</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>AppName
db "Our Second Dialog Box",0</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>TestString
db "Wow! I'm in an edit box now",0</font></font></font></b>
<p><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>.data?</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>hInstance
HINSTANCE ?</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>CommandLine
LPSTR ?</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>buffer
db 512 dup(?)</font></font></font></b>
<p><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>.const</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>IDC_EDIT
equ 3000</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>IDC_BUTTON
equ 3001</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>IDC_EXIT
equ 3002</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>IDM_GETTEXT
equ 32000</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>IDM_CLEAR
equ 32001</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>IDM_EXIT
equ 32002</font></font></font></b>
<br>
<p><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>.code</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>start:</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>
invoke GetModuleHandle, NULL</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>
mov hInstance,eax</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>
invoke DialogBoxParam, hInstance, ADDR DlgName,NULL, addr DlgProc, NULL</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>
invoke ExitProcess,eax</font></font></font></b>
<p><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>DlgProc
proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>
.IF uMsg==WM_INITDIALOG</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>
invoke GetDlgItem, hWnd,IDC_EDIT</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>
invoke SetFocus,eax</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>
.ELSEIF uMsg==WM_CLOSE</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>
invoke SendMessage,hWnd,WM_COMMAND,IDM_EXIT,0</font></font></font></b>
<br><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>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>
.IF ax==IDM_GETTEXT</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>
invoke GetDlgItemText,hWnd,IDC_EDIT,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>
<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 SetDlgItemText,hWnd,IDC_EDIT,NULL</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>
.ELSEIF ax==IDM_EXIT</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>
invoke EndDialog, hWnd,NULL</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>
.ELSE</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>
mov edx,wParam</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>
shr edx,16</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>
.if dx==BN_CLICKED</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -