Brian K. Carroll
Brian K. Carroll

Reputation: 125

Determining if the Maximize button is available

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!

Upvotes: 2

Views: 819

Answers (3)

Asher
Asher

Reputation: 1867

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

Upvotes: 0

atzz
atzz

Reputation: 18010

bool has_maximize_btn = (GetWindowLong(hWnd, GWL_STYLE) & WS_MAXIMIZEBOX) != 0;
bool has_minimize_btn = (GetWindowLong(hWnd, GWL_STYLE) & WS_MINIMIZEBOX) != 0;

Upvotes: 6

splattne
splattne

Reputation: 104050

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

Upvotes: 4

Related Questions