这个问题困扰了很久,今天终于找到一个办法了,如下:
在App类中,重载DoMessageBox函数,
int CCustomUIApp::DoMessageBox(LPCTSTR lpszPrompt, UINT nType, UINT nIDPrompt)
{
CMessageBox dlgBox;
return (int)dlgBox.DoModal();
//return CWinApp::DoMessageBox(lpszPrompt, nType, nIDPrompt);
}
这儿CMessageBox 如下定义:
#if !defined(AFX_MESSAGEBOX_H__75740508_8980_49E1_BEED_452FDB9D3D78__INCLUDED_)
#define AFX_MESSAGEBOX_H__75740508_8980_49E1_BEED_452FDB9D3D78__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// MessageBox.h : header file
//
/
// CMessageBox dialog
class CMessageBox : public CDialog
{
// Construction
public:
CMessageBox(CWnd* pParent = NULL); // standard constructor
// Dialog Data
//{{AFX_DATA(CMessageBox)
enum { IDD = IDD_DLG_MSG };
// NOTE: the ClassWizard will add data members here
//}}AFX_DATA
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CMessageBox)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
CBrush m_brush;
// Generated message map functions
//{{AFX_MSG(CMessageBox)
afx_msg BOOL OnEraseBkgnd(CDC* pDC);
afx_msg HBRUSH OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor);
virtual BOOL OnInitDialog();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_MESSAGEBOX_H__75740508_8980_49E1_BEED_452FDB9D3D78__INCLUDED_)
// MessageBox.cpp : implementation file
//
#include "stdafx.h"
#include "CustomUI.h"
#include "MessageBox.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/
// CMessageBox dialog
CMessageBox::CMessageBox(CWnd* pParent /*=NULL*/)
: CDialog(CMessageBox::IDD, pParent)
{
//{{AFX_DATA_INIT(CMessageBox)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
void CMessageBox::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CMessageBox)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CMessageBox, CDialog)
//{{AFX_MSG_MAP(CMessageBox)
ON_WM_ERASEBKGND()
ON_WM_CTLCOLOR()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/
// CMessageBox message handlers
BOOL CMessageBox::OnEraseBkgnd(CDC* pDC)
{
// TODO: Add your message handler code here and/or call default
CRect rc;
GetClientRect(rc);
pDC->FillRect(rc,&CBrush(RGB(100,100,60)));
return TRUE;//CDialog::OnEraseBkgnd(pDC);
}
HBRUSH CMessageBox::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
// TODO: Change any attributes of the DC here
if( pWnd->GetDlgCtrlID() == IDC_STATIC_TITLE )
{
pDC->SetTextColor(RGB(255, 255, 255));
pDC->SetBkMode(TRANSPARENT);
hbr = m_brush;
}
// TODO: Return a different brush if the default is not desired
return hbr;
}
BOOL CMessageBox::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
m_brush.CreateStockObject(HOLLOW_BRUSH);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
执行效果如图: