如题:
钩子函数能够哦顺利的执行,但总是画不出东西,为什么呢?
代码如下:
LRESULT CALLBACK DrawTitlBar(int nCode,WPARAM wParam, LPARAM lParam)
{
HWND hWnd = AfxGetApp()->GetMainWnd()->m_hWnd;
MSG *msg;
msg = (MSG*)lParam;
CString str;
if(msg->message ==WM_NCPAINT || msg->message == WM_PAINT || msg->message == WM_MOVE || msg->message == WM_NCACTIVATE)
{
CRect Rect;
GetWindowRect(hWnd, Rect);
CRect TitleRect;
TitleRect.left = GetSystemMetrics(SM_CXFRAME);
TitleRect.top = GetSystemMetrics(SM_CYFRAME);
TitleRect.right = Rect.right -TitleRect.left - GetSystemMetrics(SM_CXFRAME); 
TitleRect.bottom = TitleRect.top + GetSystemMetrics(SM_CYSIZE);
HDC hDC = GetWindowDC(hWnd);
HDC hDisplayMemDC = CreateCompatibleDC(hDC);
CBitmap *pBitmap = new CBitmap;
pBitmap->LoadBitmap(IDB_TOP);
BITMAP BitmapInfo;
pBitmap->GetBitmap(&BitmapInfo);
CBitmap *pOldBitmap = new CBitmap;
pOldBitmap = (CBitmap*)SelectObject(hDisplayMemDC,pBitmap); //调试pOldBitmap指向NULL,这句有影响吗?
BitBlt(hDC,TitleRect.left,TitleRect.top,BitmapInfo.bmWidth, BitmapInfo.bmHeight,hDisplayMemDC,0, 0, SRCCOPY);//绘制标题栏的一部分
SelectObject(hDisplayMemDC,pOldBitmap);
pBitmap->DeleteObject();
}
return CallNextHookEx((HHOOK)hhook,nCode,wParam,lParam); 
}