Value Returned by GetWindowLong(hWnd, GWL_STYLE)

Last reviewed: November 2, 1995
Article ID: Q83366
The information in this article applies to:
  • Microsoft Windows Software Development Kit (SDK) versions 3.1
  • Microsoft Win32 Application Programming Interface (API) included with:

        - Microsoft Windows NT versions 3.5 and 3.51
        - Microsoft Windows 95 version 4.0
    

SUMMARY

GetWindowLong(hWnd, GWL_STYLE) returns the window style information stored at the GWL_STYLE offset of the window data structure identified by hWnd. This offset contains the current state of the window, rather than the style specified when the window was created.

Windows can set and clear the following styles over the lifetime of a window: WS_CLIPSIBLINGS, WS_DISABLED, WS_HSCROLL, WS_MAXIMIZE, WS_MINIMIZE, WS_SYSMENU (for MDI child windows), WS_THICKFRAME, WS_VISIBLE, and WS_VSCROLL. Windows will not dynamically set or clear any of the other styles. An application can modify the style state at the GWL_STYLE offset at any time by calling SetWindowLong(hWnd, GWL_STYLE, dwNewLong), but Windows will not be aware that the style has changed. Windows maintains some internal flags on the window style and may use these rather than checking the GWL_STYLE offset of the window data structure.

GetWindowLong(hWnd, GWL_STYLE) returns a LONG value, which contains the currently active styles combined by the Boolean OR operator. An application can change the information stored at the GWL_STYLE offset by calling SetWindowLong(hWnd, GWL_STYLE, dwNewLong).

MORE INFORMATION

The following table lists the windows styles that Windows updates throughout the life span of a window. In the Change column below, an "S" indicates that the style is set and a "C" indicates that the style is cleared. The Where column lists the source module involved. Windows will change a window's styles as follows:

Style       Change  Window      Where       Why
-----       ------  ------      -----       ---

WS_CLIPSIBLINGS

            S       Overlapped  WMCREATE.C  Set on creation.

WS_CLIPSIBLINGS

            S       Popup       WMCREATE.C  Set on creation.

WS_DISABLED S & C   Any         WMACT.C     Set or cleared when
                                            EnableWindow function
                                            disables or enables
                                            window.

WS_HSCROLL  S & C   SB_HORZ     WINSBCTL.C  Set or cleared as scroll
                                            bar range changed (for
                                            window scroll bar, not the
                                            SCROLL BAR class).

WS_HSCROLL  S & C   SB_HORZ     SBRARE.C    Set or cleared in
                                            ShowScrollBar (for window
                                            scroll bar, not the SCROLL
                                            BAR class).

WS_HSCROLL  S & C   List boxes  LBOXCTL1.C  Set if scroll bar required
                                            to see contents.

WS_HSCROLL  S & C   MDI frame   MDIWIN.C    Set if required to see
                                            children.

WS_MAXIMIZE C       Any         WMCREATE.C  On creation (reset
                                            immediately in
                                            WMMINMAX.C).

WS_MAXIMIZE C       Any         WMMOVE.C    Cleared if window resized.

WS_MAXIMIZE S & C   Any         WMMINMAX.C  Set if window maximized,
                                            cleared if no longer
                                            maximized.

WS_MINIMIZE C       Any         WMCREATE.C  On creation (reset
                                            immediately in
                                            WMMINMAX.C).

WS_MINIMIZE C       Any         WMMOVE.C    Cleared if window resized.

WS_MINIMIZE S & C   any         WMMINMAX.C  Set if window minimized,
                                            cleared if no longer
                                            minimized.

WS_SYSMENU  S & C   MDI child   MDIMENU.C   Cleared if child is
                                            maximized and uses frame
                                            menu. Set when child no
                                            longer maximized.

WS_THICKFRAME

            S & C   Any         WINSBCTL.C  State changed for only a
                                            few instructions during
                                            painting.

WS_VISIBLE  C       Any         WMCREATE.C  Cleared and then reset by
                                            call to ShowWindow.

WS_VISIBLE  S & C   Any         WMSHOW.C    Cleared if window hidden
                                            in ShowWindow, set if
                                            shown.

WS_VISIBLE  S & C   Any         WMSWP.C     Cleared if window hidden
                                            in ShowWindow, set if
                                            shown.

WS_VISIBLE  C       MDI client  MDIWIN.C    Cleared when current MDI
                                            child is maximized, and
                                            new child is activated.
                                            Immediately reset with
                                            call to ShowWindow.

WS_VISIBLE  S       Desktop     INLOADW.C   Ensure desktop visible.

WS_VISIBLE  S & C   Any         MSDWP.C     Set or cleared when
                                            DefWindowProc receives
                                            WM_SETREDRAW message to
                                            turn drawing on or off,
                                            respectively.

WS_VISIBLE  S & C   MDI client  MDIWIN.C    Cleared and then
                                            immediately reset to
                                            optimize painting.

WS_VSCROLL  S & C   SB_VERT     WINSBCTL.C  Set or cleared as scroll
                                            bar range changed (for
                                            window scroll bar, not the
                                            SCROLL BAR class).

WS_VSCROLL  S & C   List boxes  LBOXCTL1.C  Set if scroll bar required
                                            to see entire contents.

WS_VSCROLL  S & C   MDI frame   MDIWIN.C    Set if required to see
                                            children.

WS_VSCROLL  S & C   SB_VERT     SBRARE.C    Set/cleared in
                                            ShowScrollBar (for window
                                            scroll bar, not the SCROLL
                                            BAR class).

In addition to the information above, the GetWindowLong function always reports some style bits to be clear, as follows:
  • Combo boxes always report the following styles as clear:

          CBS_HASSTRINGS, CBS_SORT, WS_BORDER, WS_HSCROLL, and WS_VSCROLL
    
  • All edit controls report the WS_BORDER style clear.
  • Multiline edit controls report the WS_HSCROLL style clear if the control contains centered or right-justified text.


Additional reference words: 3.00 3.10 3.50 3.51 4.00 95
KBCategory: kbui
KBSubcategory: UsrWndw


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: November 2, 1995
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.