亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb

首頁 > 學院 > 開發設計 > 正文

iczelion tut4

2019-09-10 09:07:10
字體:
來源:轉載
供稿:網友

Tutorial 4: Painting with Text

Theory:

Text in Windows is a type of GUI object.  Each character is composed of numerous pixels (dots) that are lumped together into a distinct pattern. That's why it's called "painting" instead of "writing". Normally, you paint text in your own client area (actually, you can paint outside client area but that's another story).  Putting text on screen in Windows is drastically different from DOS. In DOS, you can think of the screen in 80x25 dimension. But in Windows, the screen are shared by several programs. Some rules must be enforced to avoid programs writing over each other's screen. Windows ensures this by limiting painting area of each window to its own client area only. The size of client area of a window is also not constant. The user can change the size anytime. So you must determine the dimensions of your own client area dynamically.
Before you can paint something on the client area, you must ask for permission from Windows. That's right, you don't have absolute control of the screen as you were in DOS anymore.  You must ask Windows for permission to paint your own client area. Windows will determine the size of your client area, font, colors and other GDI attributes and sends a handle to device context back to your program. You can then use the device context as a passport to painting on your client area.
What is a device context? It's just a data structure maintained internally by Windows. A device context is associated with a particular device, such as a printer or video display. For a video display, a device context is usually associated with a particular window on the display.
Some of the values in the device context are graphic attributes such as colors, font etc. These are default values which you can change at will. They exist to help reduce the load from having to specify these attributes in every GDI function calls.
You can think of a device context as a default environment prepared for you by Windows. You can override some default settings later if you so wish.
When a program need to paint, it must obtain a handle to a device context. Normally, there are several ways to accomplish this.
  • call BeginPaint in response to WM_PAINT message.
    call GetDC in response to other messages.
    call CreateDC to create your own device context
One thing you must remember, after you're through with the device context handle, you must release it during the processing of a single message. Don't obtain the handle in response to one message and release it in response to another.
Windows posts WM_PAINT messages to a window to notify that it's now time to repaint its client area. Windows does not save the content of client area of a window.  Instead, when a situation occurs that warrants a repaint of client area (such as when a window was covered by another and is just uncovered), Windows puts WM_PAINT message in that window's message queue. It's the responsibility of that window to repaint its own client area. You must gather all information about how to repaint your client area in the WM_PAINT section of your window procedure, so the window procudure can repaint the client area when WM_PAINT message arrives.
Another concept you must come to terms with is the invalid rectangle. Windows defines an invalid rectangle as the smallest rectangular area in the client area that needs to be repainted. When Windows detects an invalid rectangle in the client area of a window , it posts WM_PAINT message to that window. In response to WM_PAINT message, the window can obtain a paintstruct structure which contains, among others, the coordinate of the invalid rectangle. You call BeginPaint in response to WM_PAINT message to validate the invalid rectangle. If you don't process WM_PAINT message, at the very least you must call DefWindowProc or ValidateRect to validate the invalid rectangle else Windows will repeatedly send you WM_PAINT message.
Below are the steps you should perform in response to a WM_PAINT message:
  • Get a handle to device context with BeginPaint.
    Paint the client area.
    Release the handle to device context with EndPaint
Note that you don't have to explicitly validate the invalid rectangle. It's automatically done by the BeginPaint call. Between BeginPaint-Endpaint pair, you can call any GDI functions to paint your client area. Nearly all of them require the handle to device context as a parameter.

Content:

We will write a program that displays a text string "Win32 assembly is great and easy!" in the center of the client area.
.386
.model flat,stdcall
option casemap:none

WinMain proto :DWORD,:DWORD,:DWORD,:DWORD include masm32includewindows.inc
include masm32includeuser32.inc
includelib masm32libuser32.lib
include masm32includekernel32.inc
includelib masm32libkernel32.lib .DATA
ClassName db "SimpleWinClass",0
AppName  db "Our First Window",0
OurText  db "Win32 assembly is great and easy!",0 .DATA?
hInstance HINSTANCE ?
CommandLine LPSTR ? .CODE
start:
   invoke GetModuleHandle, NULL
   mov    hInstance,eax
   invoke GetCommandLine
   mov CommandLine,eax

   invoke WinMain, hInstance,NULL,CommandLine, SW_SHOWDEFAULT
   invoke ExitProcess,eax WinMain proc hInst:HINSTANCE, hPrevInst:HINSTANCE, CmdLine:LPSTR, CmdShow:DWORD
   LOCAL wc:WNDCLASSEX
   LOCAL msg:MSG
   LOCAL hwnd:HWND
   mov   wc.cbSize,SIZEOF WNDCLASSEX
   mov   wc.style, CS_HREDRAW or CS_VREDRAW
   mov   wc.lpfnWndProc, OFFSET WndProc
   mov   wc.cbClsExtra,NULL
   mov   wc.cbWndExtra,NULL
   push  hInst
   pop   wc.hInstance
   mov   wc.hbrBackground,COLOR_WINDOW+1
   mov   wc.lpszMenuName,NULL
   mov   wc.lpszClassName,OFFSET ClassName
   invoke LoadIcon,NULL,IDI_APPLICATION
   mov   wc.hIcon,eax
   mov   wc.hIconSm,eax
   invoke LoadCursor,NULL,IDC_ARROW
   mov   wc.hCursor,eax
   invoke RegisterClassEx, addr wc
   invoke CreateWindowEx,NULL,ADDR ClassName,ADDR AppName,
/t   WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,
/t   CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,
/t   hInst,NULL
   mov   hwnd,eax
   invoke ShowWindow, hwnd,SW_SHOWNORMAL
   invoke UpdateWindow, hwnd
       .WHILE TRUE
/t        invoke GetMessage, ADDR msg,NULL,0,0
/t        .BREAK .IF (!eax)
/t        invoke TranslateMessage, ADDR msg
/t        invoke DispatchMessage, ADDR msg
       .ENDW
       mov     eax,msg.wParam
       ret
WinMain endp WndProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
   LOCAL hdc:HDC
   LOCAL ps:PAINTSTRUCT
   LOCAL rect:RECT
   .IF uMsg==WM_DESTROY
       invoke PostQuitMessage,NULL
   .ELSEIF uMsg==WM_PAINT
       invoke BeginPaint,hWnd, ADDR ps
       mov    hdc,eax
       invoke GetClientRect,hWnd, ADDR rect
       invoke DrawText, hdc,ADDR OurText,-1, ADDR rect,
/t        DT_SINGLELINE or DT_CENTER or DT_VCENTER
       invoke EndPaint,hWnd, ADDR ps
   .ELSE
       invoke DefWindowProc,hWnd,uMsg,wParam,lParam
       ret
   .ENDIF
   xor   eax, eax
   ret
WndProc endp
end start

Analysis:

The majority of the code is the same as the example in tutorial 3. I'll explain only the important changes.    LOCAL hdc:HDC
   LOCAL ps:PAINTSTRUCT
   LOCAL rect:RECT 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:
RECT Struct
   left/t   LONG ?
   top/t   LONG ?
   right        LONG ?
   bottom    LONG ?
RECT ends
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.        invoke BeginPaint,hWnd, ADDR ps
       mov    hdc,eax
       invoke GetClientRect,hWnd, ADDR rect
       invoke DrawText, hdc,ADDR OurText,-1, ADDR rect,
/t        DT_SINGLELINE or DT_CENTER or DT_VCENTER
       invoke EndPaint,hWnd, ADDR ps 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: DrawText proto hdc:HDC, lpString:DWORD, nCount:DWORD, lpRect:DWORD, uFormat:DWORD 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:
  • hdc  handle to device context
    lpString  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.
    nCount  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.
    lpRect  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.
    uFormat The value that specifies how the string is displayed in the rectangle. We use three values combined by "or" operator:
    • DT_SINGLELINE  specifies a single line of text
    • DT_CENTER  centers the text horizontally.
    • DT_VCENTER centers the text vertically. Must be used with DT_SINGLELINE.
After you finish painting the client area, you must call EndPaint function to release the handle to device context.
That's it. We can summarize the salient points here:
  • You call BeginPaint-EndPaint pair in response to WM_PAINT message.
  • Do anything you like with the client area between the calls to BeginPaint and EndPaint.
  • If you want to repaint your client area in response to other messages, you have two choices:
    • Use GetDC-ReleaseDC pair and do your painting between these calls
    • 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
上一篇:給PE文件打補丁

下一篇:iczelion tut6

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表

圖片精選

亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb
亚洲品质视频自拍网| 粉嫩av一区二区三区免费野| 国产在线久久久| 亚洲天堂影视av| 91免费综合在线| 久久久久久久久久久免费精品| 亲子乱一区二区三区电影| 亚洲另类xxxx| 亚洲成人精品视频| 久久精品国产96久久久香蕉| 亚洲一区二区三区在线视频| 色www亚洲国产张柏芝| 热99久久精品| 国产偷亚洲偷欧美偷精品| 美日韩精品免费视频| 国产精品久久久久久网站| 中文字幕亚洲精品| 欧美性猛交xxxxx免费看| 日韩在线欧美在线国产在线| 尤物99国产成人精品视频| 91成人精品网站| 欧美尺度大的性做爰视频| 2019中文字幕全在线观看| 国产精品永久免费观看| 国产精品久久999| 国产精品第100页| 国产精品一区=区| 国产视频精品自拍| 国产精品成人免费视频| 亚洲色无码播放| 久久精品男人天堂| 久久久久久久久久av| 亚洲精品一区中文字幕乱码| 国产成人精品在线| 亚洲国产美女精品久久久久∴| 国产日韩欧美一二三区| 亚洲成年人影院在线| 热99精品里视频精品| 精品亚洲夜色av98在线观看| 国产精品免费一区豆花| 欧美电影在线观看高清| 欧美成人精品一区二区| 欧美高清第一页| 亚洲伦理中文字幕| 国产日本欧美一区| 性色av一区二区三区在线观看| 96国产粉嫩美女| 91高清视频在线免费观看| 亚洲专区中文字幕| 亚洲欧洲午夜一线一品| 久久亚洲精品小早川怜子66| 国产精品福利无圣光在线一区| 欧美激情精品久久久久久免费印度| 精品人伦一区二区三区蜜桃网站| 日韩视频欧美视频| 欧美一级视频免费在线观看| 91丝袜美腿美女视频网站| 国产精品老女人精品视频| 精品小视频在线| 欧美激情欧美激情在线五月| 日韩在线激情视频| 国产欧美日韩中文字幕在线| 麻豆一区二区在线观看| 日韩激情视频在线| 国产综合久久久久| 日韩美女免费线视频| 亚洲成avwww人| 亚洲亚裔videos黑人hd| 欧美日韩国产91| 亚洲国产三级网| 日韩中文字幕不卡视频| 亚洲永久免费观看| 国产精品久久久久久久一区探花| 91精品久久久久久久久久久久久| 国产精品香蕉在线观看| 国产精品福利无圣光在线一区| 久久视频在线播放| 国产亚洲精品美女久久久久| 午夜精品久久久久久久99黑人| 中文字幕免费精品一区高清| 亚洲第一av在线| 狠狠色噜噜狠狠狠狠97| 夜色77av精品影院| 久久福利视频导航| 欧美成人黑人xx视频免费观看| 2019中文字幕在线| 奇米影视亚洲狠狠色| 国产999精品| 国内免费久久久久久久久久久| 成人亚洲欧美一区二区三区| 欧美精品一二区| 亚洲激情在线视频| 最近2019中文字幕在线高清| 日韩成人小视频| 一夜七次郎国产精品亚洲| 欧美人成在线视频| 中文字幕精品久久| 亚洲欧美日韩一区二区在线| 色综合老司机第九色激情| 欧美国产极速在线| 国产香蕉精品视频一区二区三区| 日韩在线视频观看正片免费网站| 日本免费一区二区三区视频观看| 久久久久久久一区二区| 欧美午夜激情视频| 亚洲毛片在线免费观看| 一本色道久久88综合日韩精品| 亚洲的天堂在线中文字幕| 欧美精品情趣视频| 91精品久久久久久久久久久| 欧美在线视频一二三| 国产亚洲精品美女| 国产精品小说在线| 国自在线精品视频| 成人精品aaaa网站| 国产精品福利无圣光在线一区| 国产精品福利久久久| 亚洲性猛交xxxxwww| 国产精品久久久久久久7电影| 欧美裸体男粗大视频在线观看| 欧美孕妇性xx| 国产91ⅴ在线精品免费观看| 国产精品揄拍一区二区| 亚洲91精品在线观看| 色综合色综合网色综合| 久久久久久久久久久亚洲| 成人黄色av播放免费| 日韩电影中文字幕av| 国产美女搞久久| 亚洲电影天堂av| 一区二区在线视频| 亚洲午夜国产成人av电影男同| 国产精品中文在线| 欧美视频精品一区| 亚洲精品国产欧美| 国产精品一区二区久久国产| 国产欧美日韩中文| 国产成人精品一区| 欧美成人精品在线视频| 久久久在线观看| 久久精品免费播放| 久久精品中文字幕免费mv| 亚洲免费成人av电影| 亚洲免费人成在线视频观看| 在线视频日韩精品| 国模吧一区二区三区| 国产丝袜一区视频在线观看| 欧美激情在线播放| 亚洲精品动漫100p| 久久伊人精品视频| 久久综合久久八八| 欧美性猛交视频| 九九九热精品免费视频观看网站| 在线观看国产精品91| 秋霞av国产精品一区| 久久久久久久91| 国产精品美女主播在线观看纯欲| 91久久国产综合久久91精品网站| 欧美一区二区影院| 91网站在线免费观看| 国自在线精品视频| 日本亚洲欧美成人| 国产一区二区香蕉| 亚洲全黄一级网站|