15,979
社区成员
发帖
与我相关
我的任务
分享
void TestCmd::OnTestCmdWindSizeNotification(CATCommand* cmd, CATNotification* evt, CATCommandClientData data)
{
HWND hwnd;
hwnd = FindWindow(NULL, L"TestCmd");
if(0 != hwnd)
{
CWnd *pWnd =CWnd::FromHandle(hwnd);
CBitmap * m_bitmap= new CBitmap();
CString FilePathName = "C:\\1.bmp";
HBITMAP hBitmap=(HBITMAP)LoadImage(AfxGetInstanceHandle(),FilePathName,IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
if(!m_bitmap->Attach(hBitmap))
{
cout<<"导入图片失败"<<endl;
return;
}
CPaintDC dc(pWnd);
CDC *pDC = &dc;
CRect rect;
GetClientRect(hwnd,&rect);
CDC dcMem;
dcMem.CreateCompatibleDC(&dc);
BITMAP bitmap;
m_bitmap->GetBitmap(&bitmap);
CBitmap*pbmpOld=dcMem.SelectObject(m_bitmap);
pDC->StretchBlt(0,0,rect.Width(),rect.Height(),&dcMem,0,0, bitmap.bmWidth-1,bitmap.bmHeight-1,SRCCOPY);
}
}
可以实现修改背景图片,但是必须手动修改对话框大小才能刷新,感觉就是WM_PAINT进入了消息队列但是并没有触发,下次手动修改触发了消息。试过添加Invalidate和UpdateWindow ,但是不行,GDI这块不是很懂,请教各位一下。