whats new ¦  programming tips ¦  indy articles ¦  intraweb articles ¦  informations ¦  links ¦  interviews
 misc ¦  tutorials ¦  Add&Win Game

Tips (1548)

Database (90)
Files (137)
Forms (107)
Graphic (116)
IDE (21)
Indy (5)
Internet / LAN (131)
IntraWeb (0)
Math (76)
Misc (127)
Multimedia (45)
Objects/
ActiveX (51)

OpenTools API (3)
Printing (35)
Strings (83)
System (268)
VCL (243)

Top15

Tips sort by
component


Search Tip

Add new Tip

Add&Win Game

Advertising

15 Visitors Online


 
...set the background color of a MDI Form?
Autor: Alex Pierson
[ Print tip ]  

Tip Rating (12):  
     


{*******************************************************************************
 *
 *  Hintergrundfarbe eines MDI-Formulars setzen ohne die Farbe der darauf
 *  liegenden Objekte wie TGroupBox oder TPageControl zu verändern.
 *
 *  Setting the Background color of a MDI Form without changing the color
 *  of overlayed objects like TGroupBox or TPageControl.
 *
 ******************************************************************************}

unit Unit1;

interface

uses
  
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs;

type
  
TForm1 = class(TForm)
  private
    
FClientInstance: TFarProc;
    FPrevClientProc: TFarProc;
    BkBrush: HBRUSH;
    procedure ClientWndProc(var Message: TMessage);
  public
    constructor 
Create(AOwner: TComponent); override;
    destructor Destroy; override;
  end;

implementation

{$R *.dfm}

constructor TForm1.Create(AOwner: TComponent);
begin
  inherited
;
  BkBrush := CreateSolidBrush(clGray);
  FClientInstance := Classes.MakeObjectInstance(ClientWndProc);
  FPrevClientProc := Pointer(GetWindowLong(ClientHandle, GWL_WNDPROC));
  SetWindowLong(ClientHandle, GWL_WNDPROC, Longint(FClientInstance));
end;

destructor TForm1.Destroy;
begin
  
DeleteObject(BkBrush);
  inherited;
end;

procedure TForm1.ClientWndProc(var Message: TMessage);
var
  
DC: HDC;
  BrushOld: HBRUSH;
begin
  with Message do 
  begin
    case 
Msg of
      
WM_ERASEBKGND:
        begin
          
DC := TWMEraseBkGnd(Message).DC;
          BrushOld := SelectObject(DC, BkBrush);
          FillRect(DC, ClientRect, BkBrush);
          SelectObject(DC, BrushOld);
          Result := 1;
        end;
      else
        
Result := CallWindowProc(FPrevClientProc, ClientHandle, Msg, wParam, lParam);
    end;
  end;
end;

end.

 

Rate this tip:

poor
very good


Copyright © by SwissDelphiCenter.ch
All trademarks are the sole property of their respective owners