当前位置: 代码迷 >> WinCE >> 自绘控件发生了一个奇怪的现象
  详细解决方案

自绘控件发生了一个奇怪的现象

热度:253   发布时间:2016-04-28 11:52:33.0
自绘控件发生了一个奇怪的现象,求助

//这种情况下窗口背景是不发生变化的
case WM_PAINT:
{
HDC hDCMem;
hdc = BeginPaint(hWnd, &ps);
// TODO: Add any drawing code here...
hDCMem = CreateCompatibleDC(hdc);
RECT rcWnd = {};
GetClientRect(_this->m_hWnd, &rcWnd);
FillRect(hDCMem,&rcWnd,(HBRUSH)(GetStockObject(BLACK_BRUSH)));
int nWidth = rcWnd.right - rcWnd.left;
int nHeight = rcWnd.bottom - rcWnd.top;
BitBlt(hdc,0,0,nWidth,nHeight,hDCMem,0,0,SRCCOPY);
EndPaint(hWnd, &ps);
}
break;



//这种情况下窗口背景是正常的
case WM_PAINT:
{
hdc = BeginPaint(hWnd, &ps);
// TODO: Add any drawing code here...
RECT rcWnd = {};
GetClientRect(hWnd, &rcWnd);
FillRect(hdc,&rcWnd,(HBRUSH)(GetStockObject(BLACK_BRUSH)));
EndPaint(hWnd, &ps);
}
break;

------解决思路----------------------
CreateCompatibleDC得到的 DC 是空白的,必须要选择一个图形对象。
  相关解决方案