How to find who generated a windows message

266 Views Asked by At

We have a very large, complex MFC application. For some reason a particular mode for running our application is generating WM_SIZE messages to the window. It should not be happening and is killing performance. I can see the message getting handled. How can I find what or where in the code, is generating the window message?

Note: it tends to happen when we have a performance monitoring tool hooked into the application. So it might be the third party tool doing it.
But it only happens in this one particular mode of operation so it might be some sort of strange interaction.

2

There are 2 best solutions below

0
On

You could see message map to specify for which all windows onSize has been mapped.

as an 'not elegant' alternative, you could trape WM_ONSIZE in PreTranslateMessage and see windows handle using hwnd member of pMsg structure being passed in PreTranslateMessage.

1
On

How would it help to know who sends the message? I would rather focus on a solution, such as delay processing of the message (assuming this processing is responsible for the perf hit) when an avalanche of such messages is detected.

e.g. If you receive too many messages within x milliseconds, you may decide to start a timer and process only the last message receives when the timer elapses. This way, you process max one message per x milli-seconds instead of each one.