With a class (TObject) I have :
private
FHwnd : HWND;
procedure HandleMyMessage(var Message : TMessage); message TH_MYMESSAGE;
where TH_MYMESSAGE = WM_USER + 1
In the class constructor:
FHwnd := AllocateHWND(HandleMyMessage);
The only object which receives a reference to FHwnd
is a private custom TThread (created within this class) and the only message it posts is TH_MYMESSAGE
. My understanding is that the message
directive in the procedure declaration restricts its handling to only TH_MYMESSAGE
.
This was working fine in testing, but upon integration into a much larger application I am getting feedback that HandleMyMessage
is firing for other messages as well (with obvious undesired results).
This was easily corrected by adding if Message.Msg <> TH_MYMESSAGE then Exit;
in HandleMyMessage
. My question is : Why is this happening?
My best guess is that AllocateHWND
has made HandleMyMessage
the equivalent of a DefWndProc
despite it having the message
directive. Is there a correct way to implement this which I'm missing?
HandleMyMessage
becomesWndProc
of created non-visual window. so it recieves all messages; your solution to filterMessage.Msg
is correct too.message
method modificator us used by Delphi for default handlingTObject.Dispatch
calls (in non-windowed classes) – StrandWndProc
for other messages wouldHandleMyMessage
filter properly with themessage
directive if I had doneAllocateHWND
on some other general procedure? – Disorder