?? tut9.html
字號:
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Author" content="Iczelion">
<meta name="GENERATOR" content="Mozilla/4.51 [en] (Win95; I) [Netscape]">
<title>Iczelion's Win32 Assembly Tutorial 9: Child Window Controls</title>
</head>
<body text="#FFFFFF" bgcolor="#000000" link="#FFFF00" vlink="#C0C0C0" alink="#C0FFC0">
<center>
<h1>
<font face="Arial,Helvetica"><font color="#999900">Tutorial 9: Child Window
Controls</font></font></h1></center>
<font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>In this
tutorial, we will explore child window controls which are very important
input and output devices of our programs.</font></font></font><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1></font></font></font>
<p><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>Download
the example <a href="files/tut09.zip">here</a>.</font></font></font>
<h3>
<font face="Arial,Helvetica"><font color="#CCCCCC"><font size=+0>Theory:</font></font></font></h3>
<font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>Windows
provides several predefined window classes which we can readily use in
our own programs. Most of the time we use them as components of a dialog
box so they're usually called child window controls. The child window controls
process their own mouse and keyboard messages and notify the parent window
when their states have changed. They relieve the burden from programmers
enormously so you should use them as much as possible. In this tutorial,
I put them on a normal window just to demonstrate how you can create and
use them but in reality you should put them in a dialog box.</font></font></font>
<br><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>Examples
of predefined window classes are button, listbox, checkbox, radio button,edit
etc.</font></font></font>
<br><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>In
order to use a child window control, you must create it with CreateWindow
or CreateWindowEx. Note that you don't have to register the window class
since it's registered for you by Windows. The class name parameter MUST
be the predefined class name. Say, if you want to create a button, you
must specify "button" as the class name in CreateWindowEx. The other parameters
you must fill in are the parent window handle and the control ID. The control
ID must be unique among the controls. The control ID is the ID of that
control. You use it to differentiate between the controls.</font></font></font>
<br><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>After
the control was created, it will send messages notifying the parent window
when its state has changed. Normally, you create the child windows during
WM_CREATE message of the parent window. The child window sends WM_COMMAND
messages to the parent window with its control ID in the low word of wParam,
the notification code in the high word of wParam, and its window handle
in lParam. Each child window control has different notification codes,
refer to your Win32 API reference for more information.</font></font></font>
<br><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>The
parent window can send commands to the child windows too, by calling SendMessage
function. SendMessage function sends the specified message with accompanying
values in wParam and lParam to the window specified by the window handle.
It's an extremely useful function since it can send messages to any window
provided you know its window handle.</font></font></font>
<br><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>So,
after creating the child windows, the parent window must process WM_COMMAND
messages to be able to receive notification codes from the child windows.</font></font></font>
<h3>
<font face="Arial,Helvetica"><font color="#CCCCCC"><font size=+0>Example:</font></font></font></h3>
<font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>We will
create a window which contains an edit control and a pushbutton. When you
click the button, a message box will appear showing the text you typed
in the edit box. There is also a menu with 4 menu items:</font></font></font>
<ol>
<li>
<font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1><b>Say
Hello</b> -- Put a text string into the edit box</font></font></font></li>
<li>
<font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1><b>Clear
Edit Box</b> -- Clear the content of the edit box</font></font></font></li>
<li>
<font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1><b>Get
Text </b>-- Display a message box with the text in the edit box</font></font></font></li>
<li>
<font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1><b>Exit
</b>-- Close the program.</font></font></font></li>
</ol>
<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>WinMain
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><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>.data</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>ClassName
db "SimpleWinClass",0</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>AppName
db "Our First Window",0</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>MenuName
db "FirstMenu",0</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>ButtonClassName
db "button",0</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>ButtonText
db "My First Button",0</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>EditClassName
db "edit",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><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>.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>hwndButton
HWND ?</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>hwndEdit
HWND ?</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font size=-1><font color="#CCCCCC">buffer
db 512 dup(?) </font><font color="#999900">
; buffer to store the text retrieved from the edit box</font></font></font></b><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>.const</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font size=-1><font color="#CCCCCC">ButtonID
equ 1 </font><font color="#999900">
; The control ID of the button control</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font size=-1><font color="#CCCCCC">EditID
equ 2 </font><font color="#999900">
; The control ID of the edit control</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>IDM_HELLO
equ 1</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>IDM_CLEAR
equ 2</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>IDM_GETTEXT
equ 3</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>IDM_EXIT
equ 4</font></font></font></b><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>.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 GetCommandLine<br>
mov CommandLine,eax</font></font></font></b> <br>
<b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>
invoke WinMain, hInstance,NULL,CommandLine, SW_SHOWDEFAULT</font></font></font></b>
<br>
<b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>
invoke ExitProcess,eax</font></font></font></b><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>WinMain
proc hInst:HINSTANCE,hPrevInst:HINSTANCE,CmdLine:LPSTR,CmdShow:DWORD</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>
LOCAL wc:WNDCLASSEX</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -