- Introduction
- Message Handling: Not "Contract Free"
- Assigning Message Result Values
- The TApplication Type's OnMessage Event
Assigning Message Result Values
When you handle some Windows messages, Windows expects you to return a result value. The classic example is the WM_CTLCOLOR message. When you handle this message, Windows expects you to return a handle to a brush with which you want Windows to paint a dialog box or control. (Delphi provides a Color property for components that does this for you, so the example is just for illustration purposes.) You can return this brush handle easily with a message-handling procedure by assigning a value to the Result field of TMessage (or another message record) after calling inherited. For example, if you were handling WM_CTLCOLOR, you could return a brush handle value to Windows with the following code:
procedure TForm1.WMCtlColor(var Msg: TWMCtlColor); var BrushHand: hBrush; begin inherited; { Create a brush handle and place into BrushHand variable } Msg.Result := BrushHand; end;