?? lion-tutorial04.htm
字號(hào):
<br>
<b> mov hwnd,eax</b> <br>
<b> invoke ShowWindow, hwnd,SW_SHOWNORMAL</b> <br>
<b> invoke UpdateWindow, hwnd</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 TranslateMessage, ADDR msg</b> <br>
<b>
invoke DispatchMessage, ADDR msg</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> LOCAL hdc:HDC</b> <br>
<b> LOCAL ps:PAINTSTRUCT</b> <br>
<b> LOCAL rect:RECT</b> <br>
<b> .IF uMsg==WM_DESTROY</b> <br>
<b> invoke PostQuitMessage,NULL</b>
<br>
<b> .ELSEIF uMsg==WM_PAINT</b> <br>
<b> invoke BeginPaint,hWnd, ADDR
ps</b> <br>
<b> mov hdc,eax</b>
<br>
<b> invoke GetClientRect,hWnd, ADDR
rect</b> <br>
<b> invoke DrawText, hdc,ADDR OurText,-1,
ADDR rect, \</b> <br>
<b>
DT_SINGLELINE or DT_CENTER or DT_VCENTER</b> <br>
<b> invoke EndPaint,hWnd, ADDR ps</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>
</blockquote>
<h3> Analysis:</h3>
The majority of the code is the same as the example in tutorial 3. I'll explain
only the important changes.
<p><b> LOCAL hdc:HDC</b> <br>
<b> LOCAL ps:PAINTSTRUCT</b> <br>
<b> LOCAL rect:RECT</b>
<p>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: <br>
<blockquote><b>RECT Struct</b> <br>
<b> left
LONG ?</b> <br>
<b> top
LONG ?</b> <br>
<b> right LONG ?</b>
<br>
<b> bottom LONG ?</b> <br>
<b>RECT ends</b></blockquote>
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.
<p><b> invoke BeginPaint,hWnd, ADDR
ps</b> <br>
<b> mov hdc,eax</b>
<br>
<b> invoke GetClientRect,hWnd, ADDR
rect</b> <br>
<b> invoke DrawText, hdc,ADDR OurText,-1,
ADDR rect, \</b> <br>
<b>
DT_SINGLELINE or DT_CENTER or DT_VCENTER</b> <br>
<b> invoke EndPaint,hWnd, ADDR ps</b>
<p>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:
<p><b>DrawText proto hdc:HDC, lpString:DWORD, nCount:DWORD, lpRect:DWORD, uFormat:DWORD</b>
<p>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:
<ul>
<b><u>hdc</u></b> handle to device context <br>
<b><u>lpString</u></b> 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. <br>
<b><u>nCount</u></b> 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. <br>
<b><u>lpRect</u></b> 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. <br>
<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:
<ul>
<li> <b>DT_SINGLELINE</b> specifies a single line of text</li>
<li> <b>DT_CENTER</b> centers the text horizontally.</li>
<li> <b>DT_VCENTER</b> centers the text vertically. Must be used with DT_SINGLELINE.</li>
</ul>
</ul>
After you finish painting the client area, you must call EndPaint function to
release the handle to device context. <br>
That's it. We can summarize the salient points here:
<ul>
<li> You call BeginPaint-EndPaint pair in response to WM_PAINT message.</li>
<li> Do anything you like with the client area between the calls to BeginPaint
and EndPaint.</li>
<li> If you want to repaint your client area in response to other messages,
you have two choices:</li>
<ul>
<li> Use GetDC-ReleaseDC pair and do your painting between these calls</li>
<li> Call InvalidateRect or UpdateWindow 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<strong> </strong></li>
</ul>
</ul>
<hr size="1">
<div align="center"> This article come from Iczelion's asm page, Welcom to <a href="http://asm.yeah.net">http://asm.yeah.net</a></div>
</body>
</html>
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -