Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: Getting notified of mainwindow WM_SIZE (Read 2196 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Getting notified of mainwindow WM_SIZE

As my component (foo_chronflow) is quite resource-heavy, I want it to have an option to free it's resources when it's not visible. From my understanding that's not really possible, so I opted for the next best thing: free the resources when the main window is minimized. At the moment I am using a timer to call ui_control::is_visible every 10 seconds to check for that, but I really don't like that solution.

So my question is: Is there a legal way to get notified of the main window state?

 

Getting notified of mainwindow WM_SIZE

Reply #1
I don't think there is. Subclassing is (at least) frowned upon due to the potential for abuse. With a message_filter there is no guarantee that your filter will run before the one for the main window itself so you might never receive the messages for the main window.

With regular DC based drawing and animation I would do the following. Start a one-shot timer (timer A) in the WM_PAINT handler after painting and validating the window. Invalidate the window in the WM_TIMER handler for timer A. Depending on how you calculate the timeout you can realize a fixed-rate or a fixed-delay timer. The trick is that you will not get the WM_PAINT message unless the window needs drawing for some reason. If it is invisible or hidden behind another window you will not get the WM_PAINT message. In order to free resource when the window is hidden I would use a second one-shot timer (timer B) as follows. I would start timer B in the WM_TIMER handler for timer A and I would cancel timer B in the WM_PAINT handler. If timer B elapses I would free the resources. I have not yet tried this approach for OpenGL based drawing so I'm not sure how well it would work.