` Printed Icetips Article

Icetips Article



Par2: Change Background color on appframe
2005-02-03 -- Jim Gambon
 
> How can I change the background color of the appframe window?  On
> MDI/SDI windows you can just set the background window, but you can't
> on APPLICATION windows.  Any good ideas?

I just tested this out in C6. It requires no sub-classing, and I think it
works as you need it. What it does is change the appframe's class to use a
brush of your own definition. For your example of "solid white" do this:

In Global or Module level map put these Win32 API definitions:

    MODULE('Win32API')
GetClassLong    PROCEDURE(LONG thehWnd,LONG
theIndex),LONG,PASCAL,NAME('GetClassLongA')
SetClassLong    PROCEDURE(LONG thehWnd,LONG theIndex,LONG
theNewValue),LONG,PROC,PASCAL,NAME('SetClassLongA')
CreateSolidBrush    PROCEDURE(LONG
TheColor),LONG,PASCAL,NAME('CreateSolidBrush')
DeleteObject    PROCEDURE(LONG
theObject),LONG,PROC,PASCAL,NAME('DeleteObject')
    END !MODULE

You will also need, if you want, this equate:
GCL_HBRBACKGROUND   EQUATE(-10)

Then, in the AppFrame procedure, create some LONG variables for saving the
brushs.

SaveNewBrush    LONG
SaveOldBrush    LONG

Next, right after the OPEN(AppFrame) statement in ThisWindow.Init (so that you
catch it before any actual screen activity takes place) put this:

  SaveOldBrush = GetClassLong(AppFrame{PROP:ClientHandle},GCL_HBRBACKGROUND)
  SaveNewBrush = CreateSolidBrush(0FFFFFFh)  ! Solid White
  IF SaveNewBrush <> 0
    SetClassLong(AppFrame{PROP:ClientHandle},GCL_HBRBACKGROUND,SaveNewBrush)
  END !IF

Finally, reset and delete the brush objects in the TakeCloseEvent handler for
the ThisWindow object:

  IF SaveOldBrush <> 0
    SetClassLong(AppFrame{PROP:ClientHandle},GCL_HBRBACKGROUND,SaveOldBrush)
    SaveOldBrush = 0
  END !IF

  IF SaveNewBrush <> 0
    DeleteObject(SaveNewBrush)
    SaveNewBrush = 0
  END !IF

I haven't tried it out yet, but I bet you could create a number of cool brush
objects to paint the background.



Printed May 3, 2024, 2:17 pm
This article has been viewed/printed 35114 times.