You use the BeginPaint and EndPaint functions to prepare for and complete the drawing in the client area. BeginPaint returns a handle of the display DC used for drawing in the client area; EndPaint ends the paint request and releases the DC.
In the following example, the window procedure writes the message "Hello, Windows!" in the client area. To make sure the string is visible when the window is first created, the WinMain function calls UpdateWindow immediately after creating and showing the window. This causes a WM_PAINT message to be sent immediately to the window procedure.
LRESULT APIENTRY WndProc(hwnd, message, wParam, lParam)
HWND hwnd;
UINT message;
WPARAM wParam;
LPARAM lParam;
{
PAINTSTRUCT ps;
HDC hdc;
switch (message) {
case WM_PAINT:
hdc = BeginPaint(hwnd, &ps);
TextOut(hdc, 0, 0, "Hello, Windows!", 15);
EndPaint(hwnd, &ps);
return 0L;
.
.
.
}
}
int APIENTRY WinMain(hInstance, hPrevInstance, lpCmdLine, nCmdShow)
HINSTANCE hInstance; /* handle of current instance */
HINSTANCE hPrevInstance; /* handle of previous instance */
LPSTR lpCmdLine; /* address of command line */
int nCmdShow; /* show-window type (open/icon) */
{
HWND hwnd;
hwnd = CreateWindowEx( /* parameters */ );
ShowWindow(hwnd, SW_SHOW);
UpdateWindow(hwnd);
.
.
.
return msg.wParam;
}