When people use software, most of them want to see the results they need. For example, playing RPG games means to see the protagonists they operate and do various things. In 2D RPG games, what we actually do is constantly update the screen, that is, constantly displaying BMP images. In common programs, most of them also display various texts and images, but there is a type of application that does not show the results very much, that is, the service program. In any case, as long as we want to see the results of the program execution, we need to display them in the program. That is, you need to call the beginpaint and endpaint functions. The beginpaint function is used to tell the Windows system to output content to the display card and put the operation request displayed in the system display queue. Because there is usually only one display card on the system, this type of resource is exclusive, so the operating system will make the display operation linear, ensure that the display of each window is independent, instead of displaying a part in window A or a part in window B, it is then displayed in window B after window a is displayed. Therefore, the beginpaint function tells the operating system that I need to display it. you can arrange it. When beginpaint is returned, the system's display resource handle is obtained. In this way, you can call a lot of GDI functions to perform operations. After the display is complete, remember to call the function endpaint, because after the inpaint function is used to request an exclusive display resource, if it is not released back, other programs will never be able to get the display resource, in this way, the system will be deadlocked. If you have time to carefully check the windows source program, you will find out how the beginpaint function and endpaint function constitute. For example, when the beginpaint function is called, The cursor is first hidden, and then displayed. After the endpaint function is called, the hidden cursor is displayed.
The beginpaint and endpaint functions are declared as follows:
Winuserapi
HDC
Winapi
Beginpaint (
_ In hwnd,
_ Out lppaintstruct lppaint );
Winuserapi
Bool
Winapi
Endpaint (
_ In hwnd,
_ In const paintstruct * lppaint );
HwndIs the window handle.
LppaintIs to obtain the display parameters. Its structure is defined as follows:
Typedef struct tagpaintstruct {
HDC;
Bool ferase;
Rect rcpaint;
Bool frestore;
Bool fincupdate;
Byte rgbreserved [32];
} Paintstruct, * ppaintstruct;
HDCIs to obtain the device handle.
FeraseWhether to clean the background.
RcpaintIs the size of the displayed window.
Frestore,Fincupdate,RgbreservedIs a reserved parameter.
The Return Value of the beginpaint function is also the device handle.
An example of calling this function is as follows:
#001 //
#002 // purpose: to process messages in the main window.
#003 //
#004 // Cai junsheng 2007/07/12 QQ: 9073204
#005 //
#006 lresult callback wndproc (hwnd, uint message, wparam, lparam)
#007 {
#008 int wmid, wmevent;
#009 paintstruct pS;
#010 HDC;
#011
#012 switch (Message)
#013 {
#014 case wm_command:
#015 wmid = loword (wparam );
#016 wmevent = hiword (wparam );
#017 // menu option command response:
#018 switch (wmid)
#019 {
#020 case idm_about:
#021 dialogbox (hinst, makeintresource (idd_aboutbox), hwnd, about );
#022 break;
#023 case idm_exit:
#024 destroywindow (hwnd );
#025 break;
#026 default:
#027 return defwindowproc (hwnd, message, wparam, lparam );
#028}
#029 break;
#030 case wm_paint:
#031 HDC = beginpaint (hwnd, & PS );
#032 //
#033 endpaint (hwnd, & PS );
#034 break;
#035 case wm_destroy:
#036 postquitmessage (0 );
#037 break;
#038 default:
#039 return defwindowproc (hwnd, message, wparam, lparam );
#040}
#041 return 0;
#042}
Line 3 calls the beginpaint function.
Line 3 calls the function endpaint.