ClientWndProc (Delphi)

From RAD Studio Code Examples
Jump to: navigation, search

Description

This example shows the overriding of the ClientWndProc method. To test the method bellow, create a VCL forms application ( Start > New > VCL Forms Application - Delphi ). Then set the FormStyle property from Object Inspector as fsMDIForm and override the ClientWndProc method of the TForm1 class. Also declare the global variable FDefClientProc of type TFarProc.

The method result is that the background color of the MDI parent form is changed into white.

Code

type
  TForm1 = class(TForm)
  private
    { Private declarations }
  public
    procedure ClientWndProc(var Message: TMessage); override;
  end;

var
  Form1: TForm1;
  FDefClientProc: TFarProc;

implementation

{$R *.dfm}

procedure TForm1.ClientWndProc(var Message: TMessage);
begin
  case Message.Msg of
  // Erase the background at the location of an MDI client window
    WM_ERASEBKGND:
    begin
      CallWindowProc(FDefClientProc, ClientHandle, Message.Msg, Message.wParam, Message.lParam);
      Color:=clWhite;
      Message.Result:=1;
    end;
  //Ensure the client area is redrawn by calling InvalidateRect }
    WM_VSCROLL, WM_HSCROLL:
    begin
      Message.Result := CallWindowProc(FDefClientProc, ClientHandle, Message.Msg, Message.wParam, Message.lParam);
      InvalidateRect(ClientHandle, nil, True);
      end;
    else
  // Call the original window procedure
      Message.Result := CallWindowProc(FDefClientProc, ClientHandle, Message.Msg, Message.wParam, Message.lParam);
  end;
  inherited ClientWndProc(Message);
end

Uses

See Also