Show / Hide Table of Contents

Class HwndExtensions

A set of HWND Helper Methods

Inheritance
System.Object
HwndExtensions
Inherited Members
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.ToString()
Namespace: WinUIEx
Assembly: WinUIEx.dll
Syntax
public static class HwndExtensions

Methods

| Improve this Doc View Source

CenterOnScreen(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 null if keeping the current size

System.Nullable<System.Double> height

Height of the window in device independent pixels, or null if keeping the current size

| Improve this Doc View Source

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

Learn more about this API from docs.microsoft.com.

| Improve this Doc View Source

GetDesktopWindow()

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

Learn more about this API from docs.microsoft.com.

| Improve this Doc View Source

GetDpiForWindow(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

Learn more about this API from docs.microsoft.com.

| Improve this Doc View Source

GetDpiForWindowsMonitor(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
| Improve this Doc View Source

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
| Improve this Doc View Source

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
| Improve this Doc View Source

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

true if the window was previously visible, or false if the window was previously hidden.

| Improve this Doc View Source

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

true if the window was previously visible, or false if the window was previously hidden.

| Improve this Doc View Source

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

true if the window was previously visible, or false if the window was previously hidden.

| Improve this Doc View Source

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

true if the window was previously visible, or false if the window was previously hidden.

| Improve this Doc View Source

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

| Improve this Doc View Source

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
| Improve this Doc View Source

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

true if the window was brought to the foreground.

false if the window was not brought to the foreground.

Remarks

Learn more about this API from docs.microsoft.com.

| Improve this Doc View Source

SetIcon(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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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

| Improve this Doc View Source

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 alpha is 0, the window is completely transparent. When alpha is 255, the window is opaque.

| Improve this Doc View Source

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 null if keeping the current size

System.Double height

Height of the window in device independent pixels, or null if keeping the current size

| Improve this Doc View Source

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
| Improve this Doc View Source

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
| Improve this Doc View Source

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

true if the window was previously visible, or false if the window was previously hidden.

| Improve this Doc View Source

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
| Improve this Doc View Source

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
  • Improve this Doc
  • View Source
In This Article
Back to top Generated by DocFX