16,548
社区成员




LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
switch (message)
{
case WM_ERASEBKGND:
{
return TRUE;
}
case WM_PAINT:
{
TCHAR szHello[MAX_LOADSTRING];
LoadString(hInst, IDS_HELLO, szHello, MAX_LOADSTRING);
RECT rtc;
GetClientRect(hWnd, &rtc);
int nWidth = rtc.right - rtc.left;
int nHeight = rtc.bottom - rtc.top;
RECT rt = {0, 0, nWidth, nHeight};
PAINTSTRUCT ps;
HDC hDstDC = BeginPaint(hWnd, &ps);
HDC hdc = CreateCompatibleDC(hDstDC);
int nSaveDC = SaveDC(hdc);
HBITMAP hMemBmp = CreateCompatibleBitmap(hDstDC, nWidth, nHeight);
HGDIOBJ hOldBmp = SelectObject(hdc, hMemBmp);
//在HDC上绘图
{
//填充背景色
HBRUSH hBkbr = CreateSolidBrush(GetSysColor(COLOR_WINDOW));
FillRect(hdc, &rt, hBkbr);
DeleteObject(hBkbr);
//背景透明
int nBkMode = SetBkMode(hdc, TRANSPARENT);
//字体颜色
int nTxtColor = SetTextColor(hdc, GetSysColor(COLOR_WINDOWTEXT));
DrawText(hdc, szHello, strlen(szHello), &rt, DT_CENTER);
//恢复字体颜色
SetTextColor(hdc, nTxtColor);
//回复背景属性
SetBkMode(hdc, nBkMode);
}
//贴图到目标区域
BitBlt(hDstDC, rtc.left, rtc.top, nWidth, nHeight, hdc, 0, 0, SRCCOPY);
//结束清理
SelectObject(hdc, hOldBmp);
DeleteObject(hMemBmp);
RestoreDC(hdc, nSaveDC);
DeleteDC(hdc);
EndPaint(hWnd, &ps);
return 0;
}
return DefWindowProc(hWnd, message, wParam, lParam);
}