mfc开发问题_v1

来源:互联网 发布:mysql 触发器 可靠性 编辑:程序博客网 时间:2024/06/05 15:57

1. 设置对话框按钮背景图片?

首先,设置对话框按钮的属性为Bitmap,然后导入资源文件(一个你需要作为背景的小图片),最后在该对话框类的OnInitDialog函数中添加如下代码:

//设置对话框按钮背景图片HBITMAP hBmp=::LoadBitmap(AfxGetInstanceHandle(),  MAKEINTRESOURCE(IDB_BITMAP2));      m_nCollectGoods.SetBitmap(hBmp);//m_nCollectGoods为该按钮对应的成员变量   最后运行即可。

2. 给对话框加背景图片?

首先导入需要的图片,然后在对应类的OnPaint函数的else中添加以下代码:

//CDialog::OnPaint();//注意,此处需要禁用CPaintDC   dc(this);   CRect   rect;   GetClientRect(&rect);   CDC   dcMem;   dcMem.CreateCompatibleDC(&dc);   CBitmap   bmpBackground;   bmpBackground.LoadBitmap(IDB_BITMAP4);   //IDB_BITMAP4是你自己的图对应的ID,由于我刚刚加入的位图资源 //被我命名成了IDB_Bg,因而我这句就是bmpBackground.LoadBitmap(IDB_Bg);  BITMAP   bitmap;   bmpBackground.GetBitmap(&bitmap);   CBitmap   *pbmpOld=dcMem.SelectObject(&bmpBackground);   dc.StretchBlt(0,0,rect.Width(),rect.Height(),&dcMem,0,0,            bitmap.bmWidth,bitmap.bmHeight,SRCCOPY);