Windows API text Output (i)

Source: Internet
Author: User
Tags textout

---restore content starts---

One, draw and redraw

1,windows does not preserve the contents of the window, when the window is overwritten and then restored, Windows sends the WM_PAINT Message notification window process to redraw the client area (the window is not covered by the title bar, menu bar, toolbar, status bar, can be freely drawn), using functions GetClientRect (hwnd, &rect); The client area can be obtained and stored in a RECT structure.

2,wm_paint message

Calling the UpdateWindow () function, Windows sends the first WM_PAINT message to the window procedure.

The following conditions the window procedure receives the WM_PAINT message

* The user moves a window that causes the previously covered part of the window to be exposed.

* The user adjusts the window size (when the window type is set to Cs_hredraw and Cs_vredraw values)

* Program calls ScrollWindow or SCROLLDC function to scroll client area.

* Program calls InvalidateRect or INVALIDATERGN to generate WM_PAINT messages explicitly

When the client area is temporarily obscured, Windows tries to save the overwritten content, not every time it succeeds. Windows may send a WM_PAINT message if the following occurs.

*windows Close a dialog box or message box that overrides a portion of a window

* Drop-down menu is pulled down and retracted

* Display prompt information

In the following cases, Windows always saves the content that is overwritten and then restores the

* mouse pointer moves in client area

* Drag diagram in customer area

3, valid rectangle and invalid rectangle

The area that needs to be drawn is called an "invalid zone" or an "update zone", and when the client area has an invalid zone, Windows places a WM_PAINT message in the application's message queue.

Windows retains a drawing information structure for each window (save invalid rectangles and other information) invalid zone is always up to date, Windows does not place multiple WM_PAINT messages in Message Queuing

A window procedure can call InvalidateRect to force a rectangle in the client area to fail, if there is already a WM_PAINT message in the message queue, Windows will calculate a new invalid rectangle, or if not, a WM_PAINT message will be placed. At any time, you can use the GetUpdateRect function to get the coordinates

After the window procedure calls the BeginPaint function, the entire client area becomes valid or can be used ValidateRect, WM_PAINT in the current message queue will be deleted

Ii. Introduction to GDI

1, draw a window for the client area to call the Windows Graphics Device interface letter

The function used for string output is

TextOut (hdc, x, Y, Pstext, ilength);

HDC is the device environment interface, X, y determines the upper-left corner of the string, Pstext is a pointer to a string, and ilength is the length of the string

2, the handle is a 32-bit unsigned integer used to identify a unique object, and the device Environment (DC) is a data structure maintained internally by GDI, associated with a specific device. Handles must be obtained and disposed during the same message process.

There are two ways to get methods

The first case WM_PAINT:

Hdc=beginpaint (hwnd, &PS); The BeginPaint function will invalidate the invalid area, erase the invalid area with the window background, and populate the PS fields

...

EndPaint (hwnd, &PS);

return 0;

The second Kind

HDC=GETDC (HWND);//clipping rectangle for the entire customer area, does not speak invalid zone to be effective

....

ReleaseDC (HWND,HDC);

GETWINDOWDC can get the entire window of the device environment handle

3, Draw information structure paintstruct

  

typedef  struct  tagpaintstruct{hdc    HDC; BOOL    ferase;//is true after calling the BeginPaint function. Use InvalidateRect (hwnd,null,true) TRUE when erasing the original background rect    rcpaint; BOOL    Frestore; BOOL    fincupdate; BYTE     rgbreserved[];} paintstruct;

4,textout function Explanation

TextOut (hdc, x, Y, Pstext, ilength);

The device environment determines the text color and text background color

Character size

struct tagtextmetricw{    LONG        tmheight;    LONG        tmascent;    LONG        tmdescent;    LONG        tminternalleading;    LONG        tmexternalleading;    LONG        tmavecharwidth;    LONG        Tmmaxcharwidth;} Textmetric;

---restore content ends---

Windows API text Output (i)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.