Ways to change the background of an MDI client window

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.