您可以使用BeginPaint和EndPaint功能来准备和完成客户区中的图纸。BeginPaint返回用于在客户区中绘制的显示DC的句柄; EndPaint结束绘制请求并释放DC。
在以下示例中,窗口过程将写入“Hello,Windows!”在客户区。为了确保在首次创建窗口时字符串可见,WinMain函数在创建并显示窗口后立即调用UpdateWindow.这将导致WM_PAINT消息立即发送到窗口过程。
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;
}