Delphi Programming How to send and handle a custom Windows message These notes apply to Delphi running on a Microsoft Windows platform. Delphi allows you to define your own messages when can then be posted on the Windows message queue and then handled by your own custom handler in your application. The notes here show how to: • • • • Define your own custom message Each message must have a unique id.
The constant WM_USER is defined (in the Messages unit) as the first message number available for application use. Const WM_MY_MESSAGE = WM_USER + 0; WM_ANO_MESSAGE = WM_USER + 1; These messages should be defined in the interface section of the unit containing the form that will be handling them. Alternately, to guarantee that all messages are unique within an application consider defining all your messages together in a single unit. Note: • WM_USER is fine for internal application messages. • Use WM_APP for messages between applications. • Use the RegisterMessage API call if you need a message number that is guaranteed to be unique in a system.