Search
Module:
Directory

   Desktop Functions:

   Smart Device Functions:


Show Recent Changes
Subscribe (RSS)
Misc. Pages
Comments
FAQ
Helpful Tools
Playground
Suggested Reading
Website TODO List
Download Visual Studio Add-In

getwindowlong (user32)
 
.
Summary

C# Signature:

[DllImport("user32.dll", SetLastError=true)]
static extern int GetWindowLong(IntPtr hWnd, int nIndex);

VB.NET Signature:

<DllImport("user32.dll", SetLastError:=True)> _
Private Shared Function GetWindowLong(hWnd As IntPtr, _
     <MarshalAs(UnmanagedType.I4)>nIndex As WindowLongFlags) As Integer
End Function

VB Signature:

Public Declare Function GetWindowLong Lib "user32.dll" Alias "GetWindowLongA" _
        (ByVal prmlngWindowHandle As Long, _
         ByVal prmlngIndex As WindowLongFlags) As Long

User Defined Structures

WindowLongFlags

Constants:

GWL_ID = (-12)
GWL_STYLE = (-16)
GWL_EXSTYLE = (-20)

// Window Styles
const UInt32 WS_OVERLAPPED = 0;
const UInt32 WS_POPUP = 0x80000000;
const UInt32 WS_CHILD = 0x40000000;
const UInt32 WS_MINIMIZE = 0x20000000;
const UInt32 WS_VISIBLE = 0x10000000;
const UInt32 WS_DISABLED = 0x8000000;
const UInt32 WS_CLIPSIBLINGS = 0x4000000;
const UInt32 WS_CLIPCHILDREN = 0x2000000;
const UInt32 WS_MAXIMIZE = 0x1000000;
const UInt32 WS_CAPTION = 0xC00000;      // WS_BORDER or WS_DLGFRAME  
const UInt32 WS_BORDER = 0x800000;
const UInt32 WS_DLGFRAME = 0x400000;
const UInt32 WS_VSCROLL = 0x200000;
const UInt32 WS_HSCROLL = 0x100000;
const UInt32 WS_SYSMENU = 0x80000;
const UInt32 WS_THICKFRAME = 0x40000;
const UInt32 WS_GROUP = 0x20000;
const UInt32 WS_TABSTOP = 0x10000;
const UInt32 WS_MINIMIZEBOX = 0x20000;
const UInt32 WS_MAXIMIZEBOX = 0x10000;
const UInt32 WS_TILED = WS_OVERLAPPED;
const UInt32 WS_ICONIC = WS_MINIMIZE;
const UInt32 WS_SIZEBOX = WS_THICKFRAME;

// Extended Window Styles
const UInt32 WS_EX_DLGMODALFRAME = 0x0001;
const UInt32 WS_EX_NOPARENTNOTIFY = 0x0004;
const UInt32 WS_EX_TOPMOST = 0x0008;
const UInt32 WS_EX_ACCEPTFILES = 0x0010;
const UInt32 WS_EX_TRANSPARENT = 0x0020;
const UInt32 WS_EX_MDICHILD = 0x0040;
const UInt32 WS_EX_TOOLWINDOW = 0x0080;
const UInt32 WS_EX_WINDOWEDGE = 0x0100;
const UInt32 WS_EX_CLIENTEDGE = 0x0200;
const UInt32 WS_EX_CONTEXTHELP = 0x0400;
const UInt32 WS_EX_RIGHT = 0x1000;
const UInt32 WS_EX_LEFT = 0x0000;
const UInt32 WS_EX_RTLREADING = 0x2000;
const UInt32 WS_EX_LTRREADING = 0x0000;
const UInt32 WS_EX_LEFTSCROLLBAR = 0x4000;
const UInt32 WS_EX_RIGHTSCROLLBAR = 0x0000;
const UInt32 WS_EX_CONTROLPARENT = 0x10000;
const UInt32 WS_EX_STATICEDGE = 0x20000;
const UInt32 WS_EX_APPWINDOW = 0x40000;
const UInt32 WS_EX_OVERLAPPEDWINDOW = (WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE);
const UInt32 WS_EX_PALETTEWINDOW = (WS_EX_WINDOWEDGE | WS_EX_TOOLWINDOW | WS_EX_TOPMOST);
const UInt32 WS_EX_LAYERED = 0x00080000;
const UInt32 WS_EX_NOINHERITLAYOUT = 0x00100000; // Disable inheritence of mirroring by children
const UInt32 WS_EX_LAYOUTRTL = 0x00400000; // Right to left mirroring
const UInt32 WS_EX_COMPOSITED = 0x02000000;
const UInt32 WS_EX_NOACTIVATE = 0x08000000;

Notes:

This function is NOT 64-bit safe when retrieving handle or pointer values. Use GetWindowLongPtr instead when retrieving an IntPtr.

Also, when compiling for a32 bit version, GetWindowsLongPtr still calls this version of the function. the actual GetWindowsLongPtr function is a 64 bit call. MSDN recommends using this method, because theres an internal macro that will choose the correct version to call.

Tips & Tricks:

Please add some!

Sample Code:

C#:

  static public class WndInfo
  {
    [DllImport("user32.dll", SetLastError = true)]
    static extern int GetWindowLong(IntPtr hWnd, int nIndex);

    ...
    public static bool IsWindowTopMost(IntPtr Handle)
    {
      return (GetWindowLong(Handle, GWL_EXSTYLE) & WS_EX_TOPMOST) != 0;
    }
    ...
  }

Alternative Managed API:

Do you know one? Please contribute it!

Documentation

Please edit this page!

Do you have...

  • helpful tips or sample code to share for using this API in managed code?
  • corrections to the existing content?
  • variations of the signature you want to share?
  • additional languages you want to include?

Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).

 
Access PInvoke.net directly from VS:
Terms of Use
Find References
Show Printable Version
Revisions