ClientWndProc (C++)

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

// From ClientWndProc.h:

class TForm1 : public TForm
{
__published:	// IDE-managed Components
private:	// User declarations
public:		// User declarations
	__fastcall TForm1(TComponent* Owner);
protected:
	void __fastcall ClientWndProc(Messages::TMessage &Message);/* override */
};

// From ClientWndProc.cpp:

TForm1 *Form1;
void *FNewDefClientProc;

//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
	: TForm(Owner)
{
}
//---------------------------------------------------------------------------

void __fastcall TForm1::ClientWndProc(Messages::TMessage &Message)
{
  switch (Message.Msg)
  {
  // Erase the background at the location of an MDI client window
	case WM_ERASEBKGND:
	  Message.Result = CallWindowProc(
		(long(__stdcall*)(HWND__*, unsigned int, unsigned int, long)) FNewDefClientProc, Form1->Handle,
		Message.Msg, Message.WParam, Message.LParam);
	  Color = clWhite;
	  Message.Result = 1;
	  break;
  //Ensure the client area is redrawn by calling InvalidateRect }
	case WM_VSCROLL, WM_HSCROLL:
	  Message.Result = CallWindowProc(
		(long(__stdcall*)(HWND__*, unsigned int, unsigned int, long)) FNewDefClientProc, Form1->Handle,
		Message.Msg, Message.WParam, Message.LParam);
	  InvalidateRect(ClientHandle, NULL, True);
	  break;
    default:
  // Call the original window procedure
	  Message.Result = CallWindowProc(
		(long(__stdcall*)(HWND__*, unsigned int, unsigned int, long)) FNewDefClientProc, Form1->Handle,
		Message.Msg, Message.WParam, Message.LParam);
	  break;
  }
  TForm::ClientWndProc(Message);
}

Uses

See Also

Personal tools
Assistance