VC制作使用图片做为背景的对话框

来源:互联网 发布:美版iphone有4g网络 编辑:程序博客网 时间:2024/04/30 14:50

1、资源中加入对话框背景图片,命名为IDB_BK;
2、dlg类头文件中定义


private:
 CBitmap m_bitmap;
 CBrush  m_brush;

3、在OnInitDialog中加入
BOOL CDlg::OnInitDialog()
{
 ...
 m_bitmap.LoadBitmap(IDB_BK);
 m_brush.CreatePatternBrush(&m_bitmap);
 ...
}

4、在WM_CTLCOLOR消息中处理
HBRUSH CDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
 ...

 switch(nCtlColor)
 {
 case CTLCOLOR_DLG:
  return m_brush;
 ...
 }

 ...