Custom Messages in Non-Windowed Classes - need a default handler?
Well, yes of course. AllocateHWnd
accepts a TWndMethod
to act as the window procedure of the created window. The confusion, I guess, is caused by that the compiler accepts the messsage
directive. Don't put it:
private FHwnd : HWND; procedure HandleMyMessage(var Message : TMessage);..procedure TMyClass.HandleMyMessage(var Message: TMessage);begin case Message.Msg of TH_MYMESSAGE: // end; Message.Result := DefWindowProc(FHWnd, Message.Msg, Message.WParam, Message.LParam);end;
edit: (Response to comment). To have the message handled on the class that created the utility window, you can route your message from the window AllocateHWnd creates to your class:
private FHwnd : HWND; procedure HandleMyMessage(var Message : TMessage); procedure THMyMessage(var Message: TMessage); message TH_MYMESSAGE;..procedure TMyClass.HandleMyMessage(var Message: TMessage);begin case Message.Msg of TH_MYMESSAGE: Dispatch(Message); end; Message.Result := DefWindowProc(FHWnd, Message.Msg, Message.WParam, Message.LParam);end;procedure TMyClass.THMyMessage(var Message: TMessage);begin //end;