Windows can be redrawn by the system under certain circumstances, such as when the invalid area is re-exposed, and the Vm_paint message is sent to the window's processing, but there may be Windows own Update window processing, as in the following code, the keystroke is explicitly converted to Vm_ The paint message lets the window process handle it, but the result is that the window is not redrawn immediately after the keystroke (the display font is not changed), but instead changes the font the next time it is redrawn, but if it changes to a updatewindow () function, the font is changed immediately. Guess UpdateWindow (), Invaliddaterect (), and Windows system calls all have Update window processing.
#include <windows.h>
LRESULT CALLBACK WndProc (HWND hwnd,uint message,wparam wparam,lparam LPARAM);
LRESULT CALLBACK WndProc (HWND hwnd,uint message,wparam wparam,lparam LPARAM)
{
HDC hdc;
Paintstruct PS;
Rect rect;
static int a=0;
Switch (message)
{
Case WM_CREATE:
return 0;
Case WM_PAINT:
Hdc=beginpaint (HWND,&PS);
GetClientRect (Hwnd,&rect);
int C;
if (a==0)
DrawText (Hdc,text ("Liu Wangsheng!"), -1,&rect,dt_singleline| dt_center| Dt_vcenter);
Else
C=drawtext (Hdc,text ("HELLO hello!"), -1,&rect,dt_singleline);
EndPaint (HWND,&PS);
return 0;
Case Wm_destroy:
PostQuitMessage (0);
return 0;
Case WM_KEYDOWN:
Switch (WParam)
{
Case VK_UP:
A=1;
SendMessage (hwnd,wm_paint,0,0);
InvalidateRect (hwnd,null,true);
return 0;
Case Vk_down:
PostQuitMessage (0);
return 0;
}
return 0;
}
return DefWindowProc (Hwnd,message,wparam,lparam);
return 0;
}
int Apientry WinMain (hinstance hinstance,hinstance hprevinstance, LPSTR lpcmdline,int ncmdshow)
{
Todo:place code here.
Static TCHAR Szappname[]=text ("LWS");
HWND hwnd;
MSG msg;
Wndclass 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=null;
Wndclass.lpszclassname=szappname;
RegisterClass (&wndclass);
Hwnd=createwindow (Szappname,
TEXT ("hello!"),
Ws_overlappedwindow,
Cw_usedefault,
Cw_usedefault,
Cw_usedefault,
Cw_usedefault,
Null
Null
HINSTANCE,
NULL);
ShowWindow (hwnd,ncmdshow);
UpdateWindow (HWND);
while (GetMessage (&msg,null,0,0))
{
TranslateMessage (&MSG);
DispatchMessage (&MSG);
}
return msg.wparam;
}
http://blog.csdn.net/tobacco5648/article/details/7422803
Questions about Windows Update window content (as an experiment, the effect is obvious)