Class HwndExtensions
A set of HWND Helper Methods
Inheritance
Inherited Members
Namespace: WinUIEx
Assembly: WinUIEx.dll
Syntax
public static class HwndExtensions
Methods
| Improve this Doc View SourceCenterOnScreen(IntPtr, Nullable<Double>, Nullable<Double>)
Centers the window on the current monitor
Declaration
public static void CenterOnScreen(IntPtr hwnd, double? width = null, double? height = null)
Parameters
Type | Name | Description |
---|---|---|
System.IntPtr | hwnd | Window handle |
System.Nullable<System.Double> | width | Width of the window in device independent pixels, or |
System.Nullable<System.Double> | height | Height of the window in device independent pixels, or |
GetActiveWindow()
Retrieves the window handle to the active window attached to the calling thread's message queue.
Declaration
public static IntPtr GetActiveWindow()
Returns
Type | Description |
---|---|
System.IntPtr | The return value is the handle to the active window attached to the calling thread's message queue. Otherwise, the return value is IntPtr.Zero. |
Remarks
| Improve this Doc View SourceGetDesktopWindow()
Retrieves a handle to the desktop window. The desktop window covers the entire screen. The desktop window is the area on top of which other windows are painted.
Declaration
public static IntPtr GetDesktopWindow()
Returns
Type | Description |
---|---|
System.IntPtr | The return value is a handle to the desktop window. |
Remarks
| Improve this Doc View SourceGetDpiForWindow(IntPtr)
Returns the dots per inch (dpi) value for the associated window.
Declaration
public static uint GetDpiForWindow(IntPtr hwnd)
Parameters
Type | Name | Description |
---|---|---|
System.IntPtr | hwnd | The window you want to get information about. |
Returns
Type | Description |
---|---|
System.UInt32 | The DPI for the window which depends on the DPI_AWARENESS of the window. See the Remarks for more information. An invalid hwnd value will result in a return value of 0. |
Remarks
| Improve this Doc View SourceGetDpiForWindowsMonitor(IntPtr)
Gets the DPI for the monitor that the Window is on
Declaration
public static uint GetDpiForWindowsMonitor(IntPtr hwnd)
Parameters
Type | Name | Description |
---|---|---|
System.IntPtr | hwnd |
Returns
Type | Description |
---|---|
System.UInt32 |
GetExtendedWindowStyle(IntPtr)
Gets the current window style
Declaration
public static ExtendedWindowStyle GetExtendedWindowStyle(IntPtr hWnd)
Parameters
Type | Name | Description |
---|---|---|
System.IntPtr | hWnd |
Returns
Type | Description |
---|---|
ExtendedWindowStyle |
GetWindowStyle(IntPtr)
Gets the current window style
Declaration
public static WindowStyle GetWindowStyle(IntPtr hWnd)
Parameters
Type | Name | Description |
---|---|---|
System.IntPtr | hWnd |
Returns
Type | Description |
---|---|
WindowStyle |
HideWindow(IntPtr)
Hides the window and activates another window.
Declaration
public static bool HideWindow(IntPtr hWnd)
Parameters
Type | Name | Description |
---|---|---|
System.IntPtr | hWnd | Window handle |
Returns
Type | Description |
---|---|
System.Boolean |
|
MaximizeWindow(IntPtr)
Maximizes the specified window.
Declaration
public static bool MaximizeWindow(IntPtr hWnd)
Parameters
Type | Name | Description |
---|---|---|
System.IntPtr | hWnd | Window handle |
Returns
Type | Description |
---|---|
System.Boolean |
|
MinimizeWindow(IntPtr)
Minimizes the specified window and activates the next top-level window in the Z order.
Declaration
public static bool MinimizeWindow(IntPtr hWnd)
Parameters
Type | Name | Description |
---|---|---|
System.IntPtr | hWnd | Window handle |
Returns
Type | Description |
---|---|
System.Boolean |
|
RestoreWindow(IntPtr)
Activates and displays the window. If the window is minimized or maximized, the system restores it to its original size and position. An application should specify this flag when restoring a minimized window.
Declaration
public static bool RestoreWindow(IntPtr hWnd)
Parameters
Type | Name | Description |
---|---|---|
System.IntPtr | hWnd | Window handle |
Returns
Type | Description |
---|---|
System.Boolean |
|
SetAlwaysOnTop(IntPtr, Boolean)
Configures whether the window should always be displayed on top of other windows or not
Declaration
public static void SetAlwaysOnTop(IntPtr hwnd, bool enable)
Parameters
Type | Name | Description |
---|---|---|
System.IntPtr | hwnd | Window handle |
System.Boolean | enable | Whether to display on top |
SetExtendedWindowStyle(IntPtr, ExtendedWindowStyle)
Sets the current window style
Declaration
public static void SetExtendedWindowStyle(IntPtr hWnd, ExtendedWindowStyle newStyle)
Parameters
Type | Name | Description |
---|---|---|
System.IntPtr | hWnd | Window handle |
ExtendedWindowStyle | newStyle |
SetForegroundWindow(IntPtr)
Brings the thread that created the specified window into the foreground and activates the window.
Declaration
public static bool SetForegroundWindow(IntPtr hWnd)
Parameters
Type | Name | Description |
---|---|---|
System.IntPtr | hWnd | A handle to the window that should be activated and brought to the foreground. |
Returns
Type | Description |
---|---|
System.Boolean |
|
Remarks
| Improve this Doc View SourceSetIcon(IntPtr, IconId)
Sets the icon for the window, using the specified icon ID.
Declaration
public static void SetIcon(IntPtr hwnd, IconId iconId)
Parameters
Type | Name | Description |
---|---|---|
System.IntPtr | hwnd | Window handle |
IconId | iconId | The ID of the icon. |
SetIcon(IntPtr, String)
Sets the icon for the window, using the specified icon path.
Declaration
public static void SetIcon(IntPtr hwnd, string iconPath)
Parameters
Type | Name | Description |
---|---|---|
System.IntPtr | hwnd | Window handle |
System.String | iconPath | The path of the icon. |
SetTaskBarIcon(IntPtr, Icon)
Sets the task bar icon to the provided icon
Declaration
public static void SetTaskBarIcon(IntPtr hWnd, Icon icon)
Parameters
Type | Name | Description |
---|---|---|
System.IntPtr | hWnd | Window handle |
Icon | icon | Icon |
SetWindowOpacity(IntPtr, Byte)
Sets the opacity of a layered window.
Declaration
public static void SetWindowOpacity(IntPtr hWnd, byte alpha)
Parameters
Type | Name | Description |
---|---|---|
System.IntPtr | hWnd | Window handle |
System.Byte | alpha | Alpha value used to describe the opacity of the layered window. When |
SetWindowPositionAndSize(IntPtr, Double, Double, Double, Double)
Positions and resizes the window
Declaration
public static void SetWindowPositionAndSize(IntPtr hwnd, double x, double y, double width, double height)
Parameters
Type | Name | Description |
---|---|---|
System.IntPtr | hwnd | Window handle |
System.Double | x | Left side of the window in device independent pixels |
System.Double | y | Top side of the window in device independent pixels |
System.Double | width | Width of the window in device independent pixels, or |
System.Double | height | Height of the window in device independent pixels, or |
SetWindowSize(IntPtr, Double, Double)
Sets the width and height of the window in device-independent pixels
Declaration
public static void SetWindowSize(IntPtr hwnd, double width, double height)
Parameters
Type | Name | Description |
---|---|---|
System.IntPtr | hwnd | |
System.Double | width | |
System.Double | height |
SetWindowStyle(IntPtr, WindowStyle)
Sets the current window style
Declaration
public static void SetWindowStyle(IntPtr hWnd, WindowStyle newStyle)
Parameters
Type | Name | Description |
---|---|---|
System.IntPtr | hWnd | Window handle |
WindowStyle | newStyle |
ShowWindow(IntPtr)
Activates the window and displays it in its current size and position.
Declaration
public static bool ShowWindow(IntPtr hWnd)
Parameters
Type | Name | Description |
---|---|---|
System.IntPtr | hWnd | Window handle |
Returns
Type | Description |
---|---|
System.Boolean |
|
ToggleExtendedWindowStyle(IntPtr, Boolean, ExtendedWindowStyle)
Disables or enables the window style
Declaration
public static void ToggleExtendedWindowStyle(IntPtr hWnd, bool visible, ExtendedWindowStyle style)
Parameters
Type | Name | Description |
---|---|---|
System.IntPtr | hWnd | |
System.Boolean | visible | |
ExtendedWindowStyle | style |
ToggleWindowStyle(IntPtr, Boolean, WindowStyle)
Disables or enables the window style
Declaration
public static void ToggleWindowStyle(IntPtr hWnd, bool visible, WindowStyle style)
Parameters
Type | Name | Description |
---|---|---|
System.IntPtr | hWnd | |
System.Boolean | visible | |
WindowStyle | style |