怎么把Dialog的背景改成BMP,UP有分,分不够在给): 我想把DIALOG的背景改成BMP,不用FromHandle来改,而是用Attach来改,怎么来实现呢?谢谢 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 http://expert.csdn.net/Expert/topic/1655/1655962.xml http://www.vckbase.com/code/winview/dialog/BmpDlg_Demo.zip 对话框类成员,CBitmap m_bmpBkgnd,CBrush m_cbrBkgnd;BOOL CMyDialog::OnInitDialog() { CDialog::OnInitDialog(); m_bmpBkgnd.LoadBitmap(IDB_BITMAP1); m_cbrBkgnd.Attach(&m_bmpBkgnd); // TODO: Add extra initialization here return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE}BOOL CMyDialog::OnEraseBkgnd(CDC* pDC) { // TODO: Add your message handler code here and/or call default CRect rc; GetClientRect(&rc); pDC->FillRect(&rc,&m_cbrBkgnd); return TRUE;} to: bugyouth把背景改了以后怎么来改Check的背景呢?就是改来透明,然后跟DIALOG的背景一样? 把背景给成透明的就得了,如下面的代码BOOL OnEraseBkgnd(CDC* pDC) { CBrush brush; CRect rc; LOGBRUSH logBrush; logBrush.lbStyle=BS_NULL; logBrush.lbColor=RGB(0,0,0); brush.CreateBrushIndirect(&logBrush); CBrush *pBrush=(CBrush*)pDC->SelectObject(&brush); GetClientRect(&rc); pDC->Rectangle(&rc); pDC->SelectObject(pBrush); // return CListCtrl::OnEraseBkgnd(pDC); return TRUE;} CMyDlg::OnPaint()的else中加入如下的语句,可以实现加背景位图: CPaintDC dc(this); CBitmap bitmap; CBitmap *oldbitmap; CDC MemDc; bitmap.LoadBitmap(IDB_BITMAP1); MemDc.CreateCompatibleDC(&dc); oldbitmap = MemDc.SelectObject(&bitmap); dc.BitBlt(0, 0, 642, 468, &MemDc, 0, 0, SRCCOPY); MemDc.SelectObject(oldbitmap); CDialog::OnPaint(); 派生一个类,类中OnEraseBkgnd(CDC* pDC) 问一下: 为什么在Dialog类中,点击右键,弹出的ClassWizard...中没有WM_ERASEBKGND这个消息,而Dialog类是从CWnd类中继承下来的啊,请大家帮我分析分析! 选择classwizard->classinfo->message filter中的windows项,再返回message map看看 现在要一段这样的代码,就是可以把DIALOG的背景换了,并且还能把其它控件(比如Check)的背景改来跟DIALOG的背景一样,也就是透明!! 试试OnCtlColor其实你要达到目的,最好重新建立一个类,重载自绘制函数 出来了,出来了!多谢free_card!不过,我再问一下,dialog不就是window吗? 要改checkbutton就得派生子类来解决 http://www.csdn.net/Develop/read_article.asp?id=9603…… 用一个CStatic占满Dialog的整个窗口,然后在Dialog的IntitiaDialog中调用CStatic的SetBitmap方法。注意:Dialog上面的其他控件设为Transparent: ukyoking(东方不败)的方法可行. http://expert.csdn.net/Expert/topic/1655/1655962.xml试试OnCtlColor 刚写完的, 贴一下。 m_PhotoPath是位图文件的路径void CPhotoDialog::OnPaint() { CPaintDC dc(this); // device context for painting // TODO: Add your message handler code here if(m_PhotoPath.GetLength() == 0) return ; CBitmap hbmp; HBITMAP hbitmap; hbitmap=(HBITMAP)::LoadImage (::AfxGetInstanceHandle(), m_PhotoPath, IMAGE_BITMAP,0,0,LR_LOADFROMFILE|LR_CREATEDIBSECTION); if(NULL == hbitmap) return ; hbmp.Attach(hbitmap); BITMAP bm; hbmp.GetBitmap(&bm); CDC dcMem; dcMem.CreateCompatibleDC(&dc); CBitmap *poldBitmap=(CBitmap*)dcMem.SelectObject(hbmp); CRect lRect; GetWindowRect(&lRect); ScreenToClient(lRect); dc.StretchBlt(lRect.left ,lRect.top ,lRect.Width() ,lRect.Height() ,&dcMem,0 ,0,bm.bmWidth,bm.bmHeight,SRCCOPY); ::CloseHandle(hbitmap); return ; // Do not call CDialog::OnPaint() for painting messages} 最好的办法就是OnCtlColor,可以包含所有控件的背景。 BOOL CDlgbmpDlg::OnEraseBkgnd(CDC* pDC) { CRect rect; GetClientRect(&rect); CDC dc; dc.CreateCompatibleDC(pDC); CBitmap bitmapBkgnd; bitmapBkgnd.Attach (LoadBitmap (AfxGetInstanceHandle(), MAKEINTRESOURCE(IDB_BITMAP1))); CBitmap* pOldBitmap = dc.SelectObject(&bitmapBkgnd); int iBitmapWidth, iBitmapHeight ; int ixOrg, iyOrg; BITMAP bm; bitmapBkgnd.GetObject(sizeof(BITMAP),&bm); iBitmapWidth = bm.bmWidth; iBitmapHeight = bm.bmHeight; // If our bitmap is smaller than the background and tiling is // supported, tile it. Otherwise watch the efficiency - don't // spend time setting up loops you won't need. if (iBitmapWidth >= rect.Width() && iBitmapHeight >= rect.Height() ) { pDC->BitBlt (rect.left, rect.top, rect.Width(), rect.Height(), &dc, 0, 0, SRCCOPY); } else { for (iyOrg = 0; iyOrg < rect.Height(); iyOrg += iBitmapHeight) { for (ixOrg = 0; ixOrg < rect.Width(); ixOrg += iBitmapWidth) { pDC->BitBlt (ixOrg, iyOrg, rect.Width(), rect.Height(), &dc, 0, 0, SRCCOPY); } } } dc.SelectObject(pOldBitmap); return TRUE; return CDialog::OnEraseBkgnd(pDC);} 使用界面资源问题? 哪位高手知道OpenCV 中是否有区域增长的函数 我的24位图片转换为灰度图片的问题出现在那里? 如何修改"打开文件"对话框显示时的位置和大小??? ★★★学习windows编程的困惑(关于windows消息编程的讨论)(参与有分) char类型数组转换到unicode的问题。急! wsaeventselect的问题 怎样多次实现Undo功能? 提问:在关闭打印预览时,激发的是什么事件?如何重载? 我觉得很难的问题,不知哪位高手能够解决? 一个关于滚动条的问题,请赐招 简单问题,高分!!!
BOOL CMyDialog::OnInitDialog()
{
CDialog::OnInitDialog();
m_bmpBkgnd.LoadBitmap(IDB_BITMAP1);
m_cbrBkgnd.Attach(&m_bmpBkgnd);
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}BOOL CMyDialog::OnEraseBkgnd(CDC* pDC)
{
// TODO: Add your message handler code here and/or call default
CRect rc;
GetClientRect(&rc);
pDC->FillRect(&rc,&m_cbrBkgnd);
return TRUE;
}
把背景改了以后怎么来改Check的背景呢?
就是改来透明,然后跟DIALOG的背景一样?
{
CBrush brush;
CRect rc;
LOGBRUSH logBrush;
logBrush.lbStyle=BS_NULL;
logBrush.lbColor=RGB(0,0,0);
brush.CreateBrushIndirect(&logBrush);
CBrush *pBrush=(CBrush*)pDC->SelectObject(&brush);
GetClientRect(&rc);
pDC->Rectangle(&rc);
pDC->SelectObject(pBrush);
// return CListCtrl::OnEraseBkgnd(pDC);
return TRUE;
}
CPaintDC dc(this);
CBitmap bitmap;
CBitmap *oldbitmap;
CDC MemDc; bitmap.LoadBitmap(IDB_BITMAP1);
MemDc.CreateCompatibleDC(&dc);
oldbitmap = MemDc.SelectObject(&bitmap);
dc.BitBlt(0, 0, 642, 468, &MemDc, 0, 0, SRCCOPY);
MemDc.SelectObject(oldbitmap); CDialog::OnPaint();
为什么在Dialog类中,点击右键,弹出的ClassWizard...中没有WM_ERASEBKGND这个消息,而Dialog类是从CWnd类中继承下来的啊,请大家帮我分析分析!
其实你要达到目的,最好重新建立一个类,重载自绘制函数
不过,我再问一下,dialog不就是window吗?
注意:Dialog上面的其他控件设为Transparent:
试试OnCtlColor
void CPhotoDialog::OnPaint()
{
CPaintDC dc(this); // device context for painting
// TODO: Add your message handler code here
if(m_PhotoPath.GetLength() == 0)
return ;
CBitmap hbmp;
HBITMAP hbitmap;
hbitmap=(HBITMAP)::LoadImage (::AfxGetInstanceHandle(), m_PhotoPath, IMAGE_BITMAP,0,0,LR_LOADFROMFILE|LR_CREATEDIBSECTION);
if(NULL == hbitmap)
return ;
hbmp.Attach(hbitmap);
BITMAP bm;
hbmp.GetBitmap(&bm);
CDC dcMem;
dcMem.CreateCompatibleDC(&dc);
CBitmap *poldBitmap=(CBitmap*)dcMem.SelectObject(hbmp);
CRect lRect;
GetWindowRect(&lRect);
ScreenToClient(lRect);
dc.StretchBlt(lRect.left ,lRect.top ,lRect.Width() ,lRect.Height() ,&dcMem,0 ,0,bm.bmWidth,bm.bmHeight,SRCCOPY);
::CloseHandle(hbitmap);
return ;
// Do not call CDialog::OnPaint() for painting messages
}
{ CRect rect;
GetClientRect(&rect);
CDC dc;
dc.CreateCompatibleDC(pDC);
CBitmap bitmapBkgnd; bitmapBkgnd.Attach (LoadBitmap (AfxGetInstanceHandle(),
MAKEINTRESOURCE(IDB_BITMAP1)));
CBitmap* pOldBitmap = dc.SelectObject(&bitmapBkgnd);
int iBitmapWidth, iBitmapHeight ;
int ixOrg, iyOrg; BITMAP bm;
bitmapBkgnd.GetObject(sizeof(BITMAP),&bm);
iBitmapWidth = bm.bmWidth;
iBitmapHeight = bm.bmHeight; // If our bitmap is smaller than the background and tiling is
// supported, tile it. Otherwise watch the efficiency - don't
// spend time setting up loops you won't need. if (iBitmapWidth >= rect.Width() &&
iBitmapHeight >= rect.Height() )
{
pDC->BitBlt (rect.left,
rect.top,
rect.Width(),
rect.Height(),
&dc,
0, 0, SRCCOPY);
}
else
{
for (iyOrg = 0; iyOrg < rect.Height(); iyOrg += iBitmapHeight)
{
for (ixOrg = 0; ixOrg < rect.Width(); ixOrg += iBitmapWidth)
{
pDC->BitBlt (ixOrg,
iyOrg,
rect.Width(),
rect.Height(),
&dc,
0, 0, SRCCOPY);
}
}
} dc.SelectObject(pOldBitmap);
return TRUE;
return CDialog::OnEraseBkgnd(pDC);
}