WINCE下,存在区别
这里有个DEMO:
[url=http://www.evccode.com/ch/ProductView.asp?ID=14][/url]
实现原理:
首先,获取背景位图,然后再重新贴图。
实现代码:
HBRUSH CLightSettingDlg::GetBkBrush( HWND hWnd, UINT nID, HBITMAP hBmBk )
{
HWND hWndCtrl;
hWndCtrl = ::GetDlgItem( hWnd, nID );
HBRUSH hBrushCtrl = NULL;
if( NULL != hWndCtrl )
{
RECT rcCtrl;
::GetWindowRect( hWndCtrl, &rcCtrl );
::ScreenToClient(hWnd, (LPPOINT)&rcCtrl);
::ScreenToClient(hWnd, ((LPPOINT)&rcCtrl)+1);
HDC hDC = ::GetDC(hWnd);
HDC hMemDCBk = CreateCompatibleDC( hDC );
HDC hMemDCCtrl = CreateCompatibleDC( hDC );
HBITMAP hBmCtrl = CreateCompatibleBitmap( hDC, _W(rcCtrl), _H(rcCtrl) );
HBITMAP hBmOldBk;
HBITMAP hBmOldCtrl;
hBmOldBk = (HBITMAP) ::SelectObject( hMemDCBk, hBmBk );
hBmOldCtrl = (HBITMAP) ::SelectObject( hMemDCCtrl, hBmCtrl );
::BitBlt( hMemDCCtrl, 0, 0, _W(rcCtrl), _H(rcCtrl), hMemDCBk, _X(rcCtrl), _Y(rcCtrl), SRCCOPY );
//::StretchBlt(hMemDCCtrl, 0, 0, _W(rcCtrl), _H(rcCtrl), hMemDCBk, 0,0,20, 30, SRCCOPY );
::SelectObject(hMemDCCtrl, hBmOldCtrl );
::SelectObject(hMemDCBk, hBmOldBk );
hBrushCtrl = ::CreatePatternBrush( hBmCtrl );
DeleteObject( hBmCtrl );
::DeleteDC( hMemDCBk );
::DeleteDC( hMemDCCtrl );
::ReleaseDC( hWnd, hDC );
}
return hBrushCtrl;
}