User Tools

Site Tools


changing_20the_20mdi_20background_20colour

This is an old revision of the document!


Changing the MDI background colour

by Richard Russell, March 2007

If your program uses a Multiple Document Interface, by means of the MDILIB library, the background of the MDI client area is filled with the COLOR_APPWORKSPACE system colour, which by default is a mid-grey. Although you can change this colour in Windows Control Panel that will affect all applications, which you probably don't want to do.

It is possible to change the MDI client background colour just for your program by subclassing its window procedure. To do that you can use the following procedure:

      DEF PROCsubclassmdiclient
      LOCAL E%, M%, O%, P%
      DIM P% 99
      SYS "GetWindowLong", @hmdi%, -4 TO O%
      [OPT 2
      .E% ; WM_ERASEBKGND
      push [^MDIBkgdCol%]
      call "CreateSolidBrush"
      mov edx,[esp+12] ; hDC = wParam
      sub esp,16 ; Room for RECT
      mov ecx,esp
      push eax ; for DeleteObject
      push eax ; for FillRect
      push ecx ; for FillRect
      push edx ; for FillRect
      push ecx ; for GetClientRect
      push @hmdi%
      call "GetClientRect"
      call "FillRect"
      call "DeleteObject"
      add esp,16
      mov eax,1
      ret 16
      .M% cmp dword [esp+8],20 : jz E% : jmp O%
      ]
      SYS "SetWindowLong", @hmdi%, -4, M%
      ENDPROC

You should call this procedure immediately after initialising the Multiple Document Interface, as follows:

      PROC_initmdi(hWindowMenu%)
      MDIBkgdCol% = &800000
      PROCsubclassmdiclient

The MDI background colour will be set to whatever RGB value you load into MDIBkgdCol%, which in the above example is a dark blue.

If you want to change the MDI client colour whilst your program is running, you will need to use code similar to the following to force the background to be refreshed:

      MDIBkgdCol% = &008000
      SYS "InvalidateRect", @hmdi%, 0, 1
This website uses cookies. By using the website, you agree with storing cookies on your computer. Also you acknowledge that you have read and understand our Privacy Policy. If you do not agree leave the website.More information about cookies
changing_20the_20mdi_20background_20colour.1522502348.txt.gz · Last modified: 2024/01/05 00:18 (external edit)