[Window Redraw Technology - Virtual Window Realization]

zhaozj2021-02-16  48

1 The Windows program is a graphical window, and each window can be switched to each other. However, in this window, it is involved in a window redrawing problem: When the A window is overwritten by the B window or partially override, the content in the A window will be wiped by the B window ... …As shown below:

2 ---------------------------- How to achieve the redrawing of a window when the B window is removed? There are three methods here: 1) When the content of the window is created with some calculation method, the redrawing window can be calculated again in WM_PAINT messages. This method is suitable for the case where the amount of calculation is small. Otherwise, the calculation time is too long, and the redraw effect is still not ideal ~ 2) Pre-save the window display event record, when the window is redrawn, the event will occur. 3) Establish a virtual window corresponding to the display window (on the screen) (equivalent to its mirror), each time you write content to the display window, and also write the same content to the virtual window, two Always keep synchronization. When the B window is removed, a WM_PAINT message is generated, and the program is required to redraw the window. At this time, you can directly copy the contents of the virtual window to the display window, thereby realizing the redrawing of the window! ! This is also the most common technology that most Windows application re-draws window. As shown below: 3 ------------------------- Implementation using the Windows API to implement this technology. Divided into the following three processes: 1) Create a virtual window. (WM_CREATE implementation) 2) Synchronize the virtual window (implementation during the drawing) 3) When the dictation, the virtual window is copied to the display window (in WM_PAINT) to implement the source code (if the green part is There is a portion of the [color] tagged, and the kind of not-red-painted situation will appear in the first post, because the DefWindowProc process does not process the window redrawn, which requires programmers to work, so programmers also If you don't eat dry rice, you must consider thoughtful features with the best way ----------- everyone will try it!)

Code

#include "resource.h" // globals // proclresult callback wndproc (hwnd, uint, wparam, lparam); // *************** *********************************************************** * // WinMain // ***************************************************** ********************** HINSTANCE PINSTANCE; int WinStance Hinstance, Hinstance Hprevinstance, Pstr Szcmdline, Int Icmdshow {static char szappname [] = " AppName "; HWND hwnd; MSG msg; WNDCLASSEX wndclass; wndclass.cbSize = sizeof (wndclass); wndclass.style = CS_HREDRAW | CS_VREDRAW; wndclass.lpfnWndProc = WndProc; wndclass.cbClsExtra = 0; wndclass.cbWndExtra = 0; wndclass.hInstance = hInstance; wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION); wndclass.hCursor = LoadCursor (NULL, IDC_ARROW); wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH); wndclass.lpszMenuName = MAKEINTRESOURCE (IDR_MENU1); wndclass.lpszClassName = Szappname; wndclass.hiconsm = loading; registerclassex; hwnd = createwindow (Szappname, Window Title ", WS_OVERLAPPEDWINDOW, CW_USEDEF AULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL); ShowWindow (hwnd, iCmdShow); UpdateWindow (hwnd); while (GetMessage (& msg, NULL, 0,0)) {TranslateMessage (& msg); DispatchMessage ( & msg);} return msg.wparam;} // ************************************************ **************************** Window process // ************** *********************************************************** ** LRESULT CALLBACK WndProc (HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam) {HDC hdc; PAINTSTRUCT ps; static HDC memDC; static HBITMAP hBitmap; HBRUSH hBrush; static int maxX, maxY; int response; switch (iMsg) { Case WM_CREATE: {[color = green] maxx =

GetSystemMetrics (SM_CXSCREEN); maxY = GetSystemMetrics (SM_CYSCREEN); hdc = GetDC (hwnd); // get the current device context memDC = CreateCompatibleDC (hdc); // get a compatible device context hBitmap = CreateCompatibleBitmap (hdc, maxX, MAXY); // Creating a compatible bitmap SelectObject (MEMDC, HBitMap); // Select bitmap to memory device description table Hbrush = (HBrush) getStockObject (white_brush); // Get white painting SelectObject (MEMDC, HBRUSH); // Select the painting brush into the memory device description table PATBLT (MEMDC, 0, 0, Maxx, Maxy, Patcopy); // Filled ReleaseDC (HWnd, HDC) with the current painting; // Release the current device description table [/ color ] Break;} case wm_paint: HDC = BeginPaint (HWND, & PS); [Color = Green] Bitblt (HDC, ps.rcpaint.l, ps.rcpaint.top, ps.rcpaint.right-ps.rcpaint.Left, PS .rcpaint.bottom-ps.rcpaint.top, memdc, ps.rcpaint.Left, ps.rcpaint.top, srccopy; // to scribble // to copy the MEMDC content to HDC * / [/ Color] endpaint (hwnd, & ps); Return 0; Case WM_Command: Switch (WPARAM)) {CASE IDM_DRAW: HDC = Getdc (HWND); Int x, Y, Width, Height; int Red, Green Blue; width = getSystemMetrics; height = getSystemMetrics (SM_CYFULLSCREEN); // Get high and wide for the customer area (x = 0; x

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

New Post(0)