How can one check whether a window is minimized using the win32 api?
Asked
Active
Viewed 1.1k times
3 Answers
9
Try GetWindowLong and test for the WS_MINIMIZE style:
LONG lStyles = GetWindowLong(GWL_STYLE);
if( lStyles & WS_MINIMIZE )
ATLTRACE(_T("minimized"));
else
ATLTRACE(_T("not minimized"));
You can also query for GWL_EXSTYLES
-
1Ans how is that easier than IsIconic? – GolezTrol Nov 30 '10 at 00:02
-
4I never professed to this being "easier". The OP asked how to do it using the win32 API. Giving this answer demonstrates to the OP that he's checking a window style, which may help him in the future... – Nov 30 '10 at 00:04
-
1interesting. the winapi docs label `WS_MINIMIZE` as "The window is initially minimized. Same as the WS_ICONIC style.". What does "initially" mean? – Claudiu Nov 30 '10 at 00:12
-
WS_MINIMIZE is a style that can be applied to a window at creation time and it's meant in that context. See CreateWindowEx for details – Nov 30 '10 at 00:14
-
3+1, this isn't correct. A Window doesn't lose WS_MINIMIZE when a window gets restored – Ana Betts Nov 30 '10 at 02:24
-
I agree with that, maybe I wasn't clear. WS_MINIMIZE is one of many styles that can be applied to a window at creation time; but those styles stay with a window throughout its lifetime. SetWindowLong and GetWindowLong (the focus of my answer) allow the user to read/write styles and extended styles of a window. @Claudiu asked what "initially" meant in the context of the documentation!!! Read the 3rd comment down!!! If you have a look at the docs @Claudiu was referring to, you'd understand his question and my response! – Nov 30 '10 at 08:12
-
@freefallr: ah in that case this isn't what I want. I want to know if a window is minimized _now_, not if it was when it was created – Claudiu Nov 30 '10 at 15:23
-
@Claudiu - this is what you want. It'll give you the status of the window now. But the same Styles are set for the CreateWindowEx() call. – Nov 30 '10 at 15:26
-
I know the docs are a bit confusing, but have a look at CreateWindowEx() http://msdn.microsoft.com/en-us/library/ms632680(VS.85).aspx - it's creation requires that you specify dwStyle and dwExStyle - these are GWL_STYLE and GWL_EXSTYLE respectively. When a windows state changes, these styles are updated to reflect the new state of the window. – Nov 30 '10 at 15:28