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

📄 lion-tutorial04.htm

📁 内有一些代码
💻 HTM
📖 第 1 页 / 共 2 页
字号:
    <br>
    <b>&nbsp;&nbsp;&nbsp; mov&nbsp;&nbsp; hwnd,eax</b> <br>
    <b>&nbsp;&nbsp;&nbsp; invoke ShowWindow, hwnd,SW_SHOWNORMAL</b> <br>
    <b>&nbsp;&nbsp;&nbsp; invoke UpdateWindow, hwnd</b> <br>
    <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .WHILE TRUE</b> <br>
    <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
    invoke GetMessage, ADDR msg,NULL,0,0</b> <br>
    <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
    .BREAK .IF (!eax)</b> <br>
    <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
    invoke TranslateMessage, ADDR msg</b> <br>
    <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
    invoke DispatchMessage, ADDR msg</b> <br>
    <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .ENDW</b> <br>
    <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mov&nbsp;&nbsp;&nbsp;&nbsp; 
    eax,msg.wParam</b> <br>
    <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ret</b> <br>
    <b>WinMain endp</b> 
  <p><b>WndProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM</b> <br>
    <b>&nbsp;&nbsp;&nbsp; LOCAL hdc:HDC</b> <br>
    <b>&nbsp;&nbsp;&nbsp; LOCAL ps:PAINTSTRUCT</b> <br>
    <b>&nbsp;&nbsp;&nbsp; LOCAL rect:RECT</b> <br>
    <b>&nbsp;&nbsp;&nbsp; .IF uMsg==WM_DESTROY</b> <br>
    <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; invoke PostQuitMessage,NULL</b> 
    <br>
    <b>&nbsp;&nbsp;&nbsp; .ELSEIF uMsg==WM_PAINT</b> <br>
    <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; invoke BeginPaint,hWnd, ADDR 
    ps</b> <br>
    <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mov&nbsp;&nbsp;&nbsp; hdc,eax</b> 
    <br>
    <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; invoke GetClientRect,hWnd, ADDR 
    rect</b> <br>
    <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; invoke DrawText, hdc,ADDR OurText,-1, 
    ADDR rect, \</b> <br>
    <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
    DT_SINGLELINE or DT_CENTER or DT_VCENTER</b> <br>
    <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; invoke EndPaint,hWnd, ADDR ps</b> 
    <br>
    <b>&nbsp;&nbsp;&nbsp; .ELSE</b> <br>
    <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; invoke DefWindowProc,hWnd,uMsg,wParam,lParam</b> 
    <br>
    <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ret</b> <br>
    <b>&nbsp;&nbsp;&nbsp; .ENDIF</b> <br>
    <b>&nbsp;&nbsp;&nbsp; xor&nbsp;&nbsp; eax, eax</b> <br>
    <b>&nbsp;&nbsp;&nbsp; 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>&nbsp;&nbsp;&nbsp; LOCAL hdc:HDC</b> <br>
  <b>&nbsp;&nbsp;&nbsp; LOCAL ps:PAINTSTRUCT</b> <br>
  <b>&nbsp;&nbsp;&nbsp; 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>
  &nbsp; 
<blockquote><b>RECT Struct</b> <br>
  <b>&nbsp;&nbsp;&nbsp; left&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  LONG ?</b> <br>
  <b>&nbsp;&nbsp;&nbsp; top&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  LONG ?</b> <br>
  <b>&nbsp;&nbsp;&nbsp; right&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; LONG ?</b> 
  <br>
  <b>&nbsp;&nbsp;&nbsp; bottom&nbsp;&nbsp;&nbsp; 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>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; invoke BeginPaint,hWnd, ADDR 
  ps</b> <br>
  <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mov&nbsp;&nbsp;&nbsp; hdc,eax</b> 
  <br>
  <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; invoke GetClientRect,hWnd, ADDR 
  rect</b> <br>
  <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; invoke DrawText, hdc,ADDR OurText,-1, 
  ADDR rect, \</b> <br>
  <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  DT_SINGLELINE or DT_CENTER or DT_VCENTER</b> <br>
  <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 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>&nbsp; handle to device context <br>
  <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. <br>
  <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. <br>
  <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. <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>&nbsp; specifies a single line of text</li>
    <li> <b>DT_CENTER</b>&nbsp; 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&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<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>

⌨️ 快捷键说明

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