tags:

views:

296

answers:

3

Does anyone know where I can find an example of how to determine if the Maximize and/or Minimize buttons on a window are available and/or disabled?

The window will not be in the same process as my application. I have the hWnd and I have tried using GetMenuItemInfo, but I can't find any good samples for how to do this.

Thanks!

A: 

Use the GetWindowInfo function.

Test the WINDOWINFO structure's dwStyle field and see if the WS_MAXIMIZEBOX bit is on.

WINDOWINFO.dwStyle & WS_MAXIMIZEBOX != 0
Asher
You probably meant WS_MAXIMIZEBOX. WS_MAXIMIZE is a different thing.
atzz
Hm, Asher, isn't WS_MAXIMIZE used to indicate that you want to create a maximized window?
splattne
@atzz - you are right... fixed it...
Asher
@splattne - I think that the TITLEBARINFO can be used to indicate that the maximize box is N/A (but visible). this occurs when the window is already maximized.
Asher
+4  A: 

The Win32 API provides the GetTitleBarInfo function which returns a TITLEBARINFO Structure:

typedef struct {
    DWORD cbSize;
    RECT rcTitleBar;
    DWORD rgstate[CCHILDREN_TITLEBAR+1];
} TITLEBARINFO, *PTITLEBARINFO, *LPTITLEBARINFO;

So you could check the rgstate: Pointer to an array that receives a DWORD value for each element of the title bar. The following are the title bar elements represented by the array.

Index Title Bar Element
----- --------------------
0     The title bar itself
1     Reserved.
2     Minimize button
3     Maximize button    <--------------
4     Help button
5     Close button

Each array element is a combination of one or more of the following values.

Value                    Meaning
-----                    -------------------------------------------
STATE_SYSTEM_FOCUSABLE   The element can accept the focus.
STATE_SYSTEM_INVISIBLE   The element is invisible.
STATE_SYSTEM_OFFSCREEN   The element has no visible representation.
STATE_SYSTEM_UNAVAILABLE The element is unavailable.  
STATE_SYSTEM_PRESSED     The element is in the pressed state.rgstate
splattne
Wow, I'm working with Win32, on and off, for what... 10 years, and I never heard of this function! :) Thanks for the pointer!
atzz
+5  A: 
bool has_maximize_btn = (GetWindowLong(hWnd, GWL_STYLE) & WS_MAXIMIZEBOX) != 0;
bool has_minimize_btn = (GetWindowLong(hWnd, GWL_STYLE) & WS_MINIMIZEBOX) != 0;
atzz