At the Computer College of Beijing University of Technology, Mr. Hu's "Deep MDI client window Programming" article discusses two ways to change the background of MDI client windows in the learning process, and describes one of the implementation methods, as well as sample code. I admire the author's diligent attitude towards learning, and at the same time suggest the solutions I have taken when I encounter the same situation.
Hope to learn and communicate with each other.
In fact, vc6.0/5.0 has provided a method for modifying the client area background of the MDI main window in its MSDN library and given an example.
First, we introduce the standard method of Windows window background refresh by processing WM_ERASEBKGND messages. The following demo code shows how it is done.
BOOL CSampleView::OnEraseBkgnd(CDC* pDC)
{
// 设置画刷为希望的背景色
CBrush backBrush(RGB(255, 128, 128));
// 保存旧画刷
CBrush* pOldBrush = pDC- >SelectObject(&backBrush);
CRect rect;
pDC- >GetClipBox(&rect);
// 擦除需要的区域
// 用创建的画刷绘制背景区域
pDC- >PatBlt(rect.left, rect.top, rect.Width(), rect.Height(),
PATCOPY);
pDC- >SelectObject(pOldBrush);
return TRUE;
}
To change the client area background of the MDI main window, we need to do some extra work: first subclass the client Area child window of the MDI main window, and then process the WM_ERASEBKGND message.
We can demonstrate how to modify the client area background of the MDI main window by performing the following steps:
1. Use ClassWizard to create a window class with a base class of CWnd, which can be named Cnewclientwnd.
2. Add a member variable of type Cnewclientwnd to the window class created in the previous step in CMainFrame, which can be named M_wndnewclient. 3. In the CMainFrame member function OnCreate, after the call to the base class Cmdiframewnd::oncreate (), add a call statement to SubclassWindow ().
if (!m_wndNewClient.SubclassWindow(m_hWndMDIClient))
{
TRACE("Failed to subclass MDI client window\n");
return -1; // fail to create
}
M_hwndmdiclient is a CMDIFRAMEWND member variable that contains a handle to the MDI client window.
Note: (You cannot find m_hwndmdiclient by using Help to refer to CMDIFrameWnd member variables)
4. Use the starting demo code to handle the WM_ERASEBKGND message for the window class Cnewclientwnd created in the first step.