MFC MDI: How to change the background of the MDI main frame?
Q: How can I change the background of the MDI main frame?
A: In fact, on the main frame background lies another window of 'MDIClient' class. So do the following:
Using ClassWizard, add a generic CWnd-derived class, let's say it CMDIClientWnd
Add a member of type CMDIClientWnd to CMainFrame class
Code:
class CMainFrame : public CMDIFrameWnd
{
// ...
// Attributes
protected:
CMDIClientWnd m_wndMDIClient;
// ...
};
In CMainFrame::OnCreate subclass the MDI client window
Code:
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;
// NOTE: m_hWndMDIClient is a public member of CMDIFrameWnd
m_wndMDIClient.SubclassWindow(m_hWndMDIClient);
// ...
}
Add a member of type CBrush to class CMDIClientWnd
Code:
class CMDIClientWnd : public CWnd
{
// Attributes
protected:
CBrush m_brush; // will be used to fill the backgound
};
Create the brush in CMDIClientWnd constructor
Code:
CMDIClientWnd::CMDIClientWnd()
{
// this example uses a pattern brush filled from a bitmap resource
CBitmap bitmap;
bitmap.LoadBitmap(IDB_FISHING);
m_brush.CreatePatternBrush(&bitmap);
}
Bookmarks