?? tut3.html
字號:
<br><font color="#CCCCCC"><font size=-1>Note: You don't have to declare
the function name as WinMain. In fact, you have complete freedom in this
regard. You don't have to use any WinMain-equivalent function at all. You
can paste the codes inside WinMain function next to GetCommandLine and
your program will still be able to function perfectly.</font></font>
<br><font color="#CCCCCC"><font size=-1>Upon returning from WinMain, eax
is filled with exit code. We pass that exit code as the parameter to ExitProcess
which terminates our application.</font></font>
<p><b><font color="#999900"><font size=-1>WinMain proc Inst:HINSTANCE,hPrevInst:HINSTANCE,CmdLine:LPSTR,CmdShow:DWORD</font></font></b>
<p><font color="#CCCCCC"><font size=-1>The above line is the function declaration
of WinMain. Note the parameter:type pairs that follow PROC directive. They
are parameters that WinMain receives from the caller. You can refer to
these parameters by name instead of by stack manipulation. In addition,
MASM will generate the prologue and epilogue codes for the function. So
we don't have to concern ourselves with stack frame on function enter and
exit.</font></font>
<p><b><font color="#999900"><font size=-1> LOCAL wc:WNDCLASSEX</font></font></b>
<br><b><font color="#999900"><font size=-1> LOCAL msg:MSG</font></font></b>
<br><b><font color="#999900"><font size=-1> LOCAL hwnd:HWND</font></font></b>
<p><font color="#CCCCCC"><font size=-1>LOCAL directive allocates memory
from the stack for local variables used in the function. The bunch of LOCAL
directives must be immediately below the PROC directive. The LOCAL directive
is immediately followed by <the name of local variable>:<variable
type>. So LOCAL wc:WNDCLASSEX tells MASM to allocate memory from the stack
the size of WNDCLASSEX structure for the variable named wc. We can refer
to wc in our codes without any difficulty involved in stack manipulation.
That's really a godsend, I think. The downside is that local variables
cannot be used outside the function they're created and will be automatically
destroyed when the function returns to the caller. Another drawback is
that you cannot initialize local variables automatically because they're
just stack memory allocated dynamically when the function is entered .
You have to manually assign them with desired values after LOCAL directives.</font></font>
<p><b><font color="#999900"><font size=-1> mov
wc.cbSize,SIZEOF WNDCLASSEX</font></font></b>
<br><b><font color="#999900"><font size=-1> mov
wc.style, CS_HREDRAW or CS_VREDRAW</font></font></b>
<br><b><font color="#999900"><font size=-1> mov
wc.lpfnWndProc, OFFSET WndProc</font></font></b>
<br><b><font color="#999900"><font size=-1> mov
wc.cbClsExtra,NULL</font></font></b>
<br><b><font color="#999900"><font size=-1> mov
wc.cbWndExtra,NULL</font></font></b>
<br><b><font color="#999900"><font size=-1> push
hInstance</font></font></b>
<br><b><font color="#999900"><font size=-1> pop
wc.hInstance</font></font></b>
<br><b><font color="#999900"><font size=-1> mov
wc.hbrBackground,COLOR_WINDOW+1</font></font></b>
<br><b><font color="#999900"><font size=-1> mov
wc.lpszMenuName,NULL</font></font></b>
<br><b><font color="#999900"><font size=-1> mov
wc.lpszClassName,OFFSET ClassName</font></font></b>
<br><b><font color="#999900"><font size=-1> invoke LoadIcon,NULL,IDI_APPLICATION</font></font></b>
<br><b><font color="#999900"><font size=-1> mov
wc.hIcon,eax</font></font></b>
<br><b><font color="#999900"><font size=-1> mov
wc.hIconSm,eax</font></font></b>
<br><b><font color="#999900"><font size=-1> invoke LoadCursor,NULL,IDC_ARROW</font></font></b>
<br><b><font color="#999900"><font size=-1> mov
wc.hCursor,eax</font></font></b>
<br><b><font color="#999900"><font size=-1> invoke RegisterClassEx,
addr wc</font></font></b>
<p><font color="#CCCCCC"><font size=-1>The inimidating lines above are
really simple in concept. It just takes several lines of instruction to
accomplish. The concept behind all these lines is <i>window class</i>.
A window class is nothing more than a blueprint or specification of a window.
It defines several important characteristics of a window such as its icon,
its cursor, the function responsible for it, its color etc. You create
a window from a window class. This is some sort of object oriented concept.
If you want to create more than one window with the same characteristics,
it stands to reason to store all these characteristics in only one place
and refer to them when needed. This scheme will save lots of memory by
avoiding duplication of information. Remember, Windows is designed in the
past when memory chips are prohibitive and most computers have 1 MB of
memory. Windows must be very efficient in using the scarce memory resource.
The point is: if you define your own window, you must fill the desired
characteristics of your window in a WNDCLASS or WNDCLASSEX structure and
call RegisterClass or RegisterClassEx before you're able to create your
window. You only have to register the window class once for each window
type you want to create a window from.</font></font>
<br><font color="#CCCCCC"><font size=-1>Windows has several predefined
Window classes, such as button and edit box. For these windows (or controls),
you don't have to register a window class, just call CreateWindowEx with
the predefined class name.</font></font>
<br><font color="#CCCCCC"><font size=-1>The single most important member
in the WNDCLASSEX is lpfnWndProc. lpfn stands for long pointer to function.
Under Win32, there's no "near" or "far" pointer, just pointer because of
the new FLAT memory model. But this is again a leftover from the day of
Win16. Each window class must be associated with a function called window
procedure. The window procedure is responsible for message handling of
all windows created from the associated window class. Windows will send
messages to the window procedure to notify it of important events concerning
the windows it 's responsible for,such as user keyboard or mouse input.
It's up to the window procedure to respond intelligently to each window
message it receives. You will spend most of your time writing event handlers
in window procedure.</font></font>
<br><font color="#CCCCCC"><font size=-1>I describe each member of WNDCLASSEX
below:</font></font>
<p><b><font color="#CCCCCC"><font size=-1>WNDCLASSEX STRUCT DWORD</font></font></b>
<br><b><font color="#CCCCCC"><font size=-1> cbSize
DWORD ?</font></font></b>
<br><b><font color="#CCCCCC"><font size=-1> style
DWORD ?</font></font></b>
<br><b><font color="#CCCCCC"><font size=-1> lpfnWndProc
DWORD ?</font></font></b>
<br><b><font color="#CCCCCC"><font size=-1> cbClsExtra
DWORD ?</font></font></b>
<br><b><font color="#CCCCCC"><font size=-1> cbWndExtra
DWORD ?</font></font></b>
<br><b><font color="#CCCCCC"><font size=-1> hInstance
DWORD ?</font></font></b>
<br><b><font color="#CCCCCC"><font size=-1> hIcon
DWORD ?</font></font></b>
<br><b><font color="#CCCCCC"><font size=-1> hCursor
DWORD ?</font></font></b>
<br><b><font color="#CCCCCC"><font size=-1> hbrBackground
DWORD ?</font></font></b>
<br><b><font color="#CCCCCC"><font size=-1> lpszMenuName
DWORD ?</font></font></b>
<br><b><font color="#CCCCCC"><font size=-1> lpszClassName
DWORD ?</font></font></b>
<br><b><font color="#CCCCCC"><font size=-1> hIconSm
DWORD ?</font></font></b>
<br><b><font color="#CCCCCC"><font size=-1>WNDCLASSEX ENDS</font></font></b>
<p><font size=-1><b><font color="#FFFF00">cbSize: </font></b><font color="#CCCCCC">The
size of WNDCLASSEX structure in bytes. We can use SIZEOF operator to get
the value.</font></font>
<br><font size=-1><b><font color="#FFFF00">style: </font></b><font color="#CCCCCC">The
style of windows created from this class. You can combine several styles
together using "or" operator.</font></font>
<br><font size=-1><b><font color="#FFFF00">lpfnWndProc:</font></b><font color="#CCCCCC">
The address of the window procedure responsible for windows created from
this class.</font></font>
<br><font size=-1><b><font color="#FFFF00">cbClsExtra:</font></b><font color="#CCCCCC">
Specifies the number of extra bytes to allocate following the window-class
structure. The operating system initializes the bytes to zero. You can
store window class-specific data here.</font></font>
<br><font size=-1><b><font color="#FFFF00">cbWndExtra: </font></b><font color="#CCCCCC">Specifies
the number of extra bytes to allocate following the window instance. The
operating system initializes the bytes to zero. If an application uses
the WNDCLASS structure to register a dialog box created by using the CLASS
directive in the resource file, it must set this member to DLGWINDOWEXTRA.</font></font>
<br><font size=-1><b><font color="#FFFF00">hInstance:</font></b><font color="#CCCCCC">
Instance handle of the module.</font></font>
<br><font size=-1><b><font color="#FFFF00">hIcon:</font></b><font color="#CCCCCC">
Handle to the icon. Get it from LoadIcon call.</font></font>
<br><font size=-1><b><font color="#FFFF00">hCursor:</font></b><font color="#CCCCCC">
Handle to the cursor. Get it from LoadCursor call.</font></font>
<br><font size=-1><b><font color="#FFFF00">hbrBackground:</font></b><font color="#CCCCCC">
Background color of windows created from the class.</font></font>
<br><font size=-1><b><font color="#FFFF00">lpszMenuName:</font></b><font color="#CCCCCC">
Default menu handle for windows created from the class.</font></font>
<br><font size=-1><b><font color="#FFFF00">lpszClassName:</font></b><font color="#CCCCCC">
The name of this window class.</font></font>
<br><font size=-1><b><font color="#FFFF00">hIconSm:</font></b><font color="#CCCCCC">
Handle to a small icon that is associated with the window class. If this
member is NULL, the system searches the icon resource specified by the
hIcon member for an icon of the appropriate size to use as the small icon.</font></font>
<p><b><font size=-1><font color="#006600"> </font><font color="#999900">
invoke CreateWindowEx, NULL,\</font></font></b>
<br><b><font color="#999900"><font size=-1>
ADDR ClassName,\</font></font></b>
<br><b><font color="#999900"><font size=-1>
ADDR AppName,\</font></font></b>
<br><b><font color="#999900"><font size=-1>
WS_OVERLAPPEDWINDOW,\</font></font></b>
<br><b><font color="#999900"><font size=-1>
CW_USEDEFAULT,\</font></font></b>
<br><b><font color="#999900"><font size=-1>
CW_USEDEFAULT,\</font></font></b>
<br><b><font color="#999900"><font size=-1>
CW_USEDEFAULT,\</font></font></b>
<br><b><font color="#999900"><font size=-1>
CW_USEDEFAULT,\</font></font></b>
<br><b><font color="#999900"><font size=-1>
NULL,\</font></font></b>
<br><b><font color="#999900"><font size=-1>
NULL,\</font></font></b>
<br><b><font color="#999900"><font size=-1>
hInst,\</font></font></b>
<br><b><font color="#999900"><font size=-1>
NULL</font></font></b>
<p><font color="#CCCCCC"><font size=-1>After registering the window class,
we can call CreateWindowEx to create our window based on the submitted
window class. Notice that there are 12 parameters to this function.</font></font>
<p><b><font color="#CCCCCC"><font size=-1>CreateWindowExA proto dwExStyle:DWORD,\</font></font></b>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -