SAMPLE: Changing the Default Background Color of an MDI Client

Last reviewed: February 15, 1996
Article ID: Q75002
The information in this article applies to:
  • Microsoft Windows Software Development Kit (SDK) for Windows versions 3.0 and 3.1

SUMMARY

Normally, a multiple-document interface (MDI) client window defines its background color to be the system color value COLOR_BACKGROUND+1, which is defined in the Windows SDK file WINDOWS.H. This value corresponds to the window background color defined by the user in the Control Panel.

It is possible to alter the default background color of an MDI client window by subclassing the MDI client window procedure, and processing the WM_ERASEBKGND message. All other messages are passed to the original MDI client window procedure.

MORE INFORMATION

During processing of the WM_ERASEBKGND message, the class word that defines the MDI client's background color is altered using the SetClassWord() function. Then, control is passed to the original MDI client window procedure to paint and update the window. When control returns from the original MDI client window procedure, the MDI client's class word that defines the background color is set back to its original value so that other MDI applications currently running are not affected.

Below is a sample window procedure that can be used to subclass the default MDI client window procedure.

LONG FAR PASCAL MdiClientWndProc(hwnd, msg, wParam, lParam) HWND hwnd; WORD msg, wParam; LONG lParam; {

  LONG lRetCode;

  switch (msg)
    {
  case WM_ERASEBKGND:
    {
    HBRUSH hbrNew, hbrOld;
                                       // create a solid purple brush
    hbrNew = CreateSolidBrush(RGB(75, 45, 145));
                                    // set the class background color
    hbrOld = SetClassWord(hwnd, GCW_HBRBACKGROUND, hbrNew);
                   // let the old window procedure handle the message
    lRetCode = CallWindowProc(lpfnMDIClientOld, hwnd, msg, wParam,
                lParam);
                             // set background back to original value
    SetClassWord(hwnd, GCW_HBRBACKGROUND, hbrOld);
    DeleteObject(hbrNew);         // all done with this, so delete it
    break;
    }

  default:
    lRetCode = CallWindowProc(lpfnMDIClientOld, hwnd, msg, wParam,
                lParam);
    break;
    }
  return lRetCode;
}

This code fragment is taken from MDISUBCL.EXE, a file in the Microsoft Software Library, which contains an application that demonstrates this operation.

Download MDISUBCL.EXE, a self-extracting file, from the Microsoft Software Library (MSL) on the following services:

  • Microsoft Download Service (MSDL)

          Dial (206) 936-6735 to connect to MSDL
          Download MDISUBCL.EXE (size: 24085 bytes) 
    
  • Internet (anonymous FTP)

          ftp ftp.microsoft.com
          Change to the \SOFTLIB\MSLFILES directory
          Get MDISUBCL.EXE (size: 24085 bytes) 
    


Additional reference words: 3.00 3.10 softlib MDISUBCL.EXE
KBCategory: kbprg kbfile
KBSubcategory: UsrMdi


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: February 15, 1996
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.