序
找了几句代码, 向dialog上的static控件设置图片资源.
实验
// Dialog Data
//{{AFX_DATA(CRE_VikingKillerDlg)
enum { IDD = IDD_RE_VIKINGKILLER_DIALOG };
CStatic m_CtrlBg;
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CRE_VikingKillerDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
void CRE_VikingKillerDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CRE_VikingKillerDlg)
DDX_Control(pDX, ID_BG, m_CtrlBg);
//}}AFX_DATA_MAP
}
BOOL CRE_VikingKillerDlg::OnInitDialog()
{
HBITMAP hBitmap;
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL) {
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty()) {
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
hBitmap = LoadBitmap(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDB_BITMAP_BG));
m_CtrlBg.ModifyStyle(0, SS_BITMAP); // ! must call before SetBitmap
m_CtrlBg.SetBitmap(hBitmap);
return TRUE; // return TRUE unless you set the focus to a control
}