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

📄 tut4.html

📁 win32汇编教程 希望各位多多支持
💻 HTML
📖 第 1 页 / 共 2 页
字号:
mov&nbsp;&nbsp; hwnd,eax</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>&nbsp;&nbsp;&nbsp;
invoke ShowWindow, hwnd,SW_SHOWNORMAL</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>&nbsp;&nbsp;&nbsp;
invoke UpdateWindow, hwnd</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
.WHILE TRUE</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
invoke GetMessage, ADDR msg,NULL,0,0</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
.BREAK .IF (!eax)</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
invoke TranslateMessage, ADDR msg</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
invoke DispatchMessage, ADDR msg</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
.ENDW</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
mov&nbsp;&nbsp;&nbsp;&nbsp; eax,msg.wParam</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
ret</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>WinMain
endp</font></font></font></b>
<p><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>WndProc
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>&nbsp;&nbsp;&nbsp;
LOCAL hdc:HDC</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>&nbsp;&nbsp;&nbsp;
LOCAL ps:PAINTSTRUCT</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>&nbsp;&nbsp;&nbsp;
LOCAL rect:RECT</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>&nbsp;&nbsp;&nbsp;
.IF uMsg==WM_DESTROY</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
invoke PostQuitMessage,NULL</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>&nbsp;&nbsp;&nbsp;
.ELSEIF uMsg==WM_PAINT</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
invoke BeginPaint,hWnd, ADDR ps</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
mov&nbsp;&nbsp;&nbsp; hdc,eax</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
invoke GetClientRect,hWnd, ADDR rect</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
invoke DrawText, hdc,ADDR OurText,-1, ADDR rect, \</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
DT_SINGLELINE or DT_CENTER or DT_VCENTER</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
invoke EndPaint,hWnd, ADDR ps</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>&nbsp;&nbsp;&nbsp;
.ELSE</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
invoke DefWindowProc,hWnd,uMsg,wParam,lParam</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
ret</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>&nbsp;&nbsp;&nbsp;
.ENDIF</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>&nbsp;&nbsp;&nbsp;
xor&nbsp;&nbsp; eax, eax</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>&nbsp;&nbsp;&nbsp;
ret</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>WndProc
endp</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>end
start</font></font></font></b></blockquote>

<h3>
Analysis:</h3>
<font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>The majority
of the code is the same as the example in tutorial 3. I'll explain only
the important changes.</font></font></font>
<p><b><font face="Arial,Helvetica"><font size=-1><font color="#CCCCCC">&nbsp;</font><font color="#999900">&nbsp;&nbsp;
LOCAL hdc:HDC</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#999900"><font size=-1>&nbsp;&nbsp;&nbsp;
LOCAL ps:PAINTSTRUCT</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#999900"><font size=-1>&nbsp;&nbsp;&nbsp;
LOCAL rect:RECT</font></font></font></b>
<p><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>These
are local variables that are used by GDI functions in our WM_PAINT section.
hdc is used to store the handle to device context returned from BeginPaint
call. ps is a PAINTSTRUCT structure. Normally you don't use the values
in ps. It's passed to BeginPaint function and Windows fills it with appropriate
values. You then pass ps to EndPaint function when you finish painting
the client area. rect is a RECT structure defined as follows:</font></font></font>
<br>&nbsp;
<blockquote><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>RECT
Struct</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>&nbsp;&nbsp;&nbsp;
left&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; LONG ?</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>&nbsp;&nbsp;&nbsp;
top&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; LONG ?</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>&nbsp;&nbsp;&nbsp;
right&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; LONG ?</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>&nbsp;&nbsp;&nbsp;
bottom&nbsp;&nbsp;&nbsp; LONG ?</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>RECT
ends</font></font></font></b></blockquote>
<font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>Left and
top are the coordinates of the upper left corner of a rectangle Right and
bottom are the coordinates of the lower right corner. One thing to remember:
The origin of the x-y axes is at the upper left corner of the client area.
So the point y=10 is BELOW the point y=0.</font></font></font>
<p><b><font face="Arial,Helvetica"><font size=-1><font color="#CCCCCC">&nbsp;</font><font color="#999900">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
invoke BeginPaint,hWnd, ADDR ps</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#999900"><font size=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
mov&nbsp;&nbsp;&nbsp; hdc,eax</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#999900"><font size=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
invoke GetClientRect,hWnd, ADDR rect</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#999900"><font size=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
invoke DrawText, hdc,ADDR OurText,-1, ADDR rect, \</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#999900"><font size=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
DT_SINGLELINE or DT_CENTER or DT_VCENTER</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#999900"><font size=-1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
invoke EndPaint,hWnd, ADDR ps</font></font></font></b>
<p><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>In
response to WM_PAINT message, you call BeginPaint with handle to the window
you want to paint and an uninitialized PAINTSTRUCT structure as parameters.
After successful call, eax contains the handle to device context. Next
you call GetClientRect to retrieve the dimension of the client area. The
dimension is returned in rect variable which you pass to DrawText as one
of its parameters. DrawText's syntax is:</font></font></font>
<p><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>DrawText
proto hdc:HDC, lpString:DWORD, nCount:DWORD, lpRect:DWORD, uFormat:DWORD</font></font></font></b>
<p><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>DrawText
is a high-level text output API function. It handles some gory details
such as word wrap, centering etc. so you could concentrate on the string
you want to paint. Its low-level brother, TextOut, will be examined in
the next tutorial. DrawText formats a text string to fit within the bounds
of a rectangle. It uses the currently selected font,color and background
(in the device context) to draw the text.Lines are wrapped to fit within
the bounds of the rectangle. It returns the height of the output text in
device units, in our case, pixels. Let's see its parameters:</font></font></font>
<ul><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1><b><u>hdc</u></b>&nbsp;
handle to device context</font></font></font>
<br><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1><b><u>lpString</u></b>&nbsp;
The pointer to the string you want to draw in the rectangle. The string
must be null-terminated else you would have to specify its length in the
next parameter, nCount.</font></font></font>
<br><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1><b><u>nCount</u></b>&nbsp;
The number of characters to output. If the string is null-terminated, nCount
must be -1. Otherwise nCount must contain the number of characters in the
string you want to draw.</font></font></font>
<br><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1><b><u>lpRect</u></b>&nbsp;
The pointer to the rectangle (a structure of type RECT) you want to draw
the string in. Note that this rectangle is also a clipping rectangle, that
is, you could not draw the string outside this rectangle.</font></font></font>
<br><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1><b><u>uFormat</u></b>
The value that specifies how the string is displayed in the rectangle.
We use three values combined by "or" operator:</font></font></font>
<ul>
<li>
<font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1><b>DT_SINGLELINE</b>&nbsp;
specifies a single line of text</font></font></font></li>

<li>
<font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1><b>DT_CENTER</b>&nbsp;
centers the text horizontally.</font></font></font></li>

<li>
<font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1><b>DT_VCENTER</b>
centers the text vertically. Must be used with DT_SINGLELINE.</font></font></font></li>
</ul>
</ul>
<font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>After
you finish painting the client area, you must call EndPaint function to
release the handle to device context.</font></font></font>
<br><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>That's
it. We can summarize the salient points here:</font></font></font>
<ul>
<li>
<font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>You call
BeginPaint-EndPaint pair in response to WM_PAINT message.</font></font></font></li>

<li>
<font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>Do anything
you like with the client area between the calls to BeginPaint and EndPaint.</font></font></font></li>

<li>
<font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>If you
want to repaint your client area in response to other messages, you have
two choices:</font></font></font></li>

<ul>
<li>
<font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>Use GetDC-ReleaseDC
pair and do your painting between these calls</font></font></font></li>

<li>
<font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>Call InvalidateRect
or UpdateWindow&nbsp; to invalidate the entire client area, forcing Windows
to put WM_PAINT message in the message queue of your window and do your
painting in WM_PAINT section</font></font></font></li>
</ul>
</ul>

<hr WIDTH="100%">
<center><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>[<a href="http://win32asm.cjb.net">Iczelion's
Win32 Assembly HomePage</a>]</font></font></font></b></center>

</body>
</html>

⌨️ 快捷键说明

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