Window invalid area demo

zhaozj2021-02-16  47

Invalid area of ​​the window

Author: Jiang Xuezhe (netsail0@163.net)

Textbook: Windows Program Design (Fifth Edition) Peking University Press [United States] Charles Petzold Co., Ltd. ¥: 160

Environment: Windows2000 PRO SP4 Internet Explorer 6.0 SP1 Visual C 6.0

Tint Jiang Computer Program Group (http://chulsoft.xiloo.com) Copyright, reprint, please explain the source ----------------------- --------------------------------------- As part of the window customer area or all Invalid ", so that the system will send a WM_PAINT message to the window process when refreshed.

The client area must be drawn after receiving the WM_PAINT message. In many cases we only need to update a small area. This is the case when the dialog covers some of the customer districts. When the dialog is closed, you need to redraw only the rectangular area previously covered by the dialog. This area is "invalid area" or "update area".

In order to make you better understand what is an invalid area, I wrote a program. The program's function is to get the coordinates of the latest invalid area. After running the program, you can use another smaller window to cover all or a small portion of the window. Then remove it. Alternatively or change the size of the window. The four numbers appearing in the client area are the latest invalid area coordinates. The following is the code of the WndProc section:

============================================================================================================================================================================================================= ========= Lresult Callback WndProc (HWND HWND, UINT Message, WParam WPARAM, LPARAM LPARAM) {Static Int CXCHAR, CXCAPS, CYCHAR; HDC HDC; Static Int T [4]; INT I; PAINTSTRUCT PS; TCHAR SZBUFFER [10];

Switch (Message) {case wm_paint: hdc = beginpaint (hwnd, & ps); t [0] = ps.rcpaint.l; t [1] = ps.rcpaint.top; t [2] = ps.rcpaint.bottom T [3] = ps.rcpaint.right;

For (i = 0; i <4; i ) {textout (HDC, T [0], T [1] i * 20, SZBuffer, WSPrintf (szbuffer, text ("% 5d"), T [i]) Endpaint (hwnd, & ps); returnograph;

Case WM_DESTROY: PostquitMessage (0); Return 0;} return defWindowProc (hwnd, message, wparam, lparam);} ========================= ================================== BEGINT function is obtained from the system in addition to obtaining the device descriptor Related information fills her second parameters, that is, the PaintStruct structure. This structure contains an RCPAINT structure. The RCPAINT structure is the coordinates of the latest invalid area.

When it is determined that the programmer intervention is required, it is done automatically by the system. Is a dark box operation. We only need to get the beginpaint function to get it. I am very dissatisfied with Microsoft's hidden detail. It is only limited to dissatisfaction. People have to bow under the roof.

转载请注明原文地址:https://www.9cbs.com/read-27624.html

New Post(0)