Article ID: 293215 - View products that this article applies to.
This article was previously published under Q293215
When an application's top-level window is minimized through the Minimize command from its System menu or a click on its Minimize button, the operating system will trim the working set for the process. This is done to free up RAM for foreground applications. As a result of this trimming, a process may experience significantly poorer performance because its memory pages are being faulted back into RAM.
If an application minimizes its top-level window programmatically by calling the ShowWindow() API with the SW_MINIMIZE command, the working set of the process will be trimmed. However, the working set will not be trimmed when the window is programmatically minimized through the use of ShowWindow() with the SW_SHOWMINIMIZED command.
The working set of a process is the set of memory pages currently visible to the process in physical RAM. Access to this memory is very fast because the pages are resident and available for an application to use without triggering a page fault.
A process can explicitly trim its own working set by calling the SetProcessWorkingSetSize() API while passing "-1" for both the dwMinimumWorkingSetSize and dwMaximumWorkingSetSize parameters. This is essentially how the system trims the process when its top-level window is minimized. This does not mean that the memory pages used by the process are immediately discarded from RAM. In fact, these pages may remain resident for quite a while. They are simply flagged so that the system can use them for other processes as necessary. This is significantly faster than waiting on the system's standard trimming algorithm.
When a window is minimized through the Minimize command from its System menu or the Minimize button, the window is sent a WM_SYSCOMMAND message with the SC_MINIMIZE command. If the window procedure passes this message on to the system's default window procedure by calling DefWindowProc(), the default procedure will handle the message by calling ShowWindow() with the SW_MINIMIZE command. As stated earlier, this will cause the process working set to be trimmed.
You can write an application that can be minimized without having its working set trimmed. To do this, the window procedure for the top-level window should intercept the WM_SYSCOMMAND message and respond to the SC_MINIMIZE command by calling ShowWindow() directly with the SW_SHOWMINIMIZED command. It should not pass the SC_MINIMIZE command on to DefWindowProc().
Sample CodeThe following code demonstrates how to write a window procedure that intercepts the WM_SYSCOMMAND message to bypass the default window procedure and prevent the process working set from being trimmed:
Article ID: 293215 - Last Review: November 21, 2006 - Revision: 5.1
Contact us for more help