aehimself 396 Posted February 21, 2022 Hello, I have a TObject descendant which has a message handler defined like: TProgressContent = Class strict private Procedure ProcessWindowMessage(Var Msg: TMessage); Message UM_WORKERENDED; End; This message gets sent when a worker thread finished so I extract some data and free it up. I started to get some strange results and some application freezes, and it quickly turned out that lots of other messages arrive in this handler. I have some 144's and 2's entering up here. The solution is easy - I just made an if Msg.Message = UM_WORKERENDED inside the handler and now all the issues are solved but isn't explicitly defining the message should already filter the rest out? Also, out of curiosity, what is a window message with the ID of 144? Couldn't find anything on Google so far. Cheers! Share this post Link to post
Attila Kovacs 629 Posted February 21, 2022 #define WM_UAHDESTROYWINDOW 0x0090 // handled by DefWindowProc and the comment should give some hint why are there different messages Share this post Link to post
Remy Lebeau 1398 Posted February 21, 2022 3 hours ago, aehimself said: I have a TObject descendant which has a message handler defined like: You can't send window messages to a non-windowed class. Well, unless you are calling TObject.Dispatch() directly, that is. Are you? 3 hours ago, aehimself said: This message gets sent when a worker thread finished so I extract some data and free it up. Why are you not posting (not sending) the message to an actual window? 3 hours ago, aehimself said: I started to get some strange results and some application freezes, and it quickly turned out that lots of other messages arrive in this handler. You did not show how you are actually sending the message to the class in the first place. 3 hours ago, aehimself said: isn't explicitly defining the message should already filter the rest out? Yes, it should, if the messages are going through the normal Dispatch() mechanism to begin with. But since you didn't show your actual code, maybe that is not actually the case? We can't see your code. 3 hours ago, aehimself said: Also, out of curiosity, what is a window message with the ID of 144? Couldn't find anything on Google so far. 144 is in the range of system-reserved message IDs, however there is no known system message with an ID of 144. Message ID 2 is WM_DESTROY, though. Share this post Link to post
aehimself 396 Posted February 21, 2022 24 minutes ago, Remy Lebeau said: You can't send window messages to a non-windowed class. Well, unless you are calling TObject.Dispatch() directly, that is. Are you? Why are you not posting (not sending) the message to an actual window? Well.. technically I am. I have one allocated with AllocateHwnd. I guess in this case all messages are sent there, even if it's filtered. 30 minutes ago, Remy Lebeau said: 144 is in the range of system-reserved message IDs, however there is no known system message with an ID of 144. Message ID 2 is WM_DESTROY, though. Yes, I managed to find 2, but there was nothing on 144 though which I could find. Share this post Link to post
Anders Melander 1784 Posted February 21, 2022 37 minutes ago, aehimself said: Well.. technically I am. I have one allocated with AllocateHwnd. I guess in this case all messages are sent there, even if it's filtered. If you're using ProcessWindowMessage as the WndProc you declared with AllocateHwnd then it's no surprise that ProcessWindowMessage are seeing all messages. The message directive is used to build a message dispatch table but that table is only used if the messages are process via the Dispatch method. You could call Dispatch within your WndProc and have the message routed via the dispatch table (to another method) but there's really no reason for that extra indirection in this case. Just filter directly within ProcessWindowMessage. 1 Share this post Link to post
Remy Lebeau 1398 Posted February 22, 2022 On 2/21/2022 at 10:32 AM, aehimself said: Well.. technically I am. I have one allocated with AllocateHwnd. I guess in this case all messages are sent there, even if it's filtered. You can't mix AllocateHwnd() with message dispatch methods, that is not how the system works. You need to handle the messages directly in the WndProc that you give to AllocateHwnd(). 1 Share this post Link to post