窗口客戶區域中的繪圖
您可以使用 BeginPaint 和 EndPaint 函式來準備並完成用戶區域中的繪圖。 BeginPaint 會將句柄傳回用於在工作區中繪製的顯示裝置內容;EndPaint 結束繪製要求並釋放裝置內容。
在下列範例中,視窗程式會在工作區中寫入訊息 “Hello, Windows!” 。 為了確保第一次建立視窗時會顯示字串,WinMain 函式會在建立及顯示視窗之後立即呼叫 UpdateWindow。 這會導致 WM_PAINT 訊息立即傳送至窗口程式。
LRESULT APIENTRY WndProc(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;
// Process other messages.
}
}
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
HWND hwnd;
hwnd = CreateWindowEx(
// parameters
);
ShowWindow(hwnd, SW_SHOW);
UpdateWindow(hwnd);
return msg.wParam;
}