我在对话中加入图片移动闪烁,还有加入
下面是个按钮类,他的父窗体也是个对话框只加载了一个背景图片.在背景消息里面加入的图片(OnEraseBkgnd).
按钮类,从对话框中继承下来的,用GDI+画的.
但是我移动按钮类的时候闪烁.
DLGICO::DLGICO(CWnd* pParent /*=NULL*/)
: CDialog(DLGICO::IDD, pParent)
{
//WCHAR pv_filename[MAX_PATH];
//memset(pv_filename,0,MAX_PATH);
//GetFilePath("Out_abuse.png",pv_filename);
//pv_filename = L"bmp";
m_ButtonImage=NULL;
m_ButtonImage = Image::FromFile(L"D:\\载入.PNG", false);
m_bChanage=false;
}
BOOL __fastcall SetWindowBackgroundImage(HWND mhWnd, Image* pImg)
//这个可以不要双缓存画图.但是为什么画PNG后面有黑色边框.是不是没有刷背景(ONPAINT)造成的???????
{
int nWidth = pImg->GetWidth();
int nHeight = pImg->GetHeight();
HDC hdcSource = ::GetDC(mhWnd);
HDC hdcMemory = ::CreateCompatibleDC(hdcSource);
::SetBkMode(hdcMemory,TRANSPARENT );
HBITMAP hbmp = ::CreateCompatibleBitmap(hdcSource, 600, 600);
HBITMAP hOld = (HBITMAP)::SelectObject(hdcMemory, hbmp);
Gdiplus::Graphics GCanvas(hdcMemory);
GCanvas.SetInterpolationMode(InterpolationModeHighQuality);
GCanvas.SetCompositingQuality(CompositingQualityHighQuality);
GCanvas.SetSmoothingMode(SmoothingModeAntiAlias);
Gdiplus::RectF rcf(0,0,nWidth,nHeight);
GCanvas.DrawImage(pImg,rcf,0,0,nWidth,nHeight,UnitPixel);
::BitBlt(hdcSource,0,0,nWidth,nHeight,hdcMemory,0,0,SRCCOPY);
::SelectObject(hdcMemory, hOld);
::DeleteObject(hbmp);
::DeleteDC(hdcMemory);
::ReleaseDC(mhWnd, hdcSource);
return true;
}
// DLGICO 消息处理程序
void DLGICO::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
m_bChanage=true;
//this->GetWindowRect(m_OldRect);
// SetCursor(AfxGetApp()->LoadCursorA(IDC_CURSOR1));
PostMessage(WM_NCLBUTTONDOWN,HTCAPTION,MAKELPARAM(point.x,point.y));
CDialog::OnLButtonDown(nFlags, point);
//CDialog::OnLButtonDown(nFlags, point);
}
void DLGICO::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
m_bChanage=false;
CDialog::OnLButtonUp(nFlags, point);
}
void DLGICO::OnMove(int x, int y)
{
// TODO: 在此处添加消息处理程序代码
CDialog::OnMove(x, y);
CRect PRect,DlgRect;
this->GetClientRect(&DlgRect);
CwindowDlg* pDlg=(CwindowDlg* )GetParent();
//pDlg->GetPictureRect(PRect);// 取得图片的坐标
// GetWindowRect(cRect);
我想通过下面来刷新父窗体.??????????????????????????
/*if(m_bChanage)
{
pDlg->RedrawWindow();
}*/
/*if(m_bChanage)
pDlg->RedrawWindow();*/
}
void DLGICO::SetPicture()
{
CDC *pDC= this->GetDC();
if(pDC&&m_ButtonImage)
{
Graphics graphics(/*this->GetDC()->GetSafeHdc()*/pDC->m_hDC);
CRect rect;
GetClientRect(&rect);
graphics.DrawImage(m_ButtonImage,0,0,rect.Width(),rect.Height());
//SetWindowBackgroundImage(m_hWnd, m_ButtonImage);
WCHAR string[] = L"Sample Text";
Font myFont(L"Arial", 22);
PointF origin(20.0f, 20.0f);
SolidBrush blackBrush(Gdiplus::Color(255,255, 0,255));
StringFormat format;
graphics.DrawString(
string,
11,
&myFont,
origin,
&format,
&blackBrush);
}
ReleaseDC(pDC);
}
void DLGICO::OnPaint()
{
CPaintDC dc(this); // device context for painting
// TODO: 在此处添加消息处理程序代码
// 不为绘图消息调用 CDialog::OnPaint()
//if(m_bChanage)
SetPicture();
}
HBRUSH DLGICO::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)//背景透明.
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
if(nCtlColor == CTLCOLOR_DLG)
{
pDC->SetBkColor(TRANSPARENT);
return HBRUSH(GetStockObject(HOLLOW_BRUSH/*NULL_BRUSH*/));
}
// TODO: 在此更改 DC 的任何属性
// TODO: 如果默认的不是所需画笔,则返回另一个画笔
return hbr;
}
void DLGICO::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
//SetCursor(AfxGetApp()->LoadCursorA(IDC_CURSOR1));
//this->RedrawWindow();
CDialog::OnMouseMove(nFlags, point);
}
BOOL DLGICO::OnEraseBkgnd(CDC* pDC)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
return true;
return CDialog::OnEraseBkgnd(pDC);
}