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:

code format="bb4w" 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 code You should call this procedure immediately after initialising the Multiple Document Interface, as follows:

code format="bb4w" PROC_initmdi(hWindowMenu%) MDIBkgdCol% = &800000 PROCsubclassmdiclient code 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:

code format="bb4w" MDIBkgdCol% = &008000 SYS "InvalidateRect", @hmdi%, 0, 1 code