User Tools

Site Tools


changing_20the_20mdi_20background_20colour

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 for visitor traffic analysis. By using the website, you agree with storing the cookies on your computer.More information
changing_20the_20mdi_20background_20colour.txt · Last modified: 2018/04/16 14:42 by richardrussell