User32CreateWindowEx Method

Creates an overlapped, pop-up, or child window with an extended window style.

Definition

Namespace: DevCase.Win32.NativeMethods
Assembly: DevCase.net48 (in DevCase.net48.dll) Version: 6.0.0.0 (6.0)
XMLNS for XAML: Not mapped to an xmlns.
[DllImportAttribute("User32.dll", CharSet = CharSet.Auto, BestFitMapping = false, 
	ThrowOnUnmappableChar = true, SetLastError = true)]
public static IntPtr CreateWindowEx(
	WindowStylesEx exStyle,
	string className,
	string windowName,
	WindowStyles style,
	int x,
	int y,
	int width,
	int height,
	[OptionalAttribute] IntPtr hWndParent,
	[OptionalAttribute] IntPtr hMenu,
	IntPtr hInstance,
	[OptionalAttribute] IntPtr param
)

Parameters

exStyle  WindowStylesEx
The extended window style of the window being created.
className  String
A null-terminated string or a class atom created by a previous call to the RegisterClass or RegisterClassEx function.

The atom must be in the low-order word of className; the high-order word must be zero.

If className is a string, it specifies the window class name.

The class name can be any name registered with RegisterClass or RegisterClassEx, provided that the module that registers the class is also the module that creates the window.

The class name can also be any of the predefined system class names.

windowName  String
The window name.

If the window style specifies a title bar, the window title pointed to by lpWindowName is displayed in the title bar.

When using CreateWindowEx(WindowStylesEx, String, String, WindowStyles, Int32, Int32, Int32, Int32, IntPtr, IntPtr, IntPtr, IntPtr) to create controls, such as buttons, check boxes, and static controls, use windowName to specify the text of the control.

When creating a static control with the SS_ICON style, use windowName to specify the icon name or identifier.

To specify an identifier, use the syntax "#num".

style  WindowStyles
The style of the window being created.
x  Int32
The initial horizontal position of the window.

For an overlapped or pop-up window, the x parameter is the initial x-coordinate of the window's upper-left corner, in screen coordinates.

For a child window, x is the x-coordinate of the upper-left corner of the window relative to the upper-left corner of the parent window's client area.

If x is set to CW_USEDEFAULT, the system selects the default position for the window's upper-left corner and ignores the y parameter.

CW_USEDEFAULT is valid only for overlapped windows; if it is specified for a pop-up or child window, the x and y parameters are set to zero.

y  Int32
The initial vertical position of the window.

For an overlapped or pop-up window, the y parameter is the initial y-coordinate of the window's upper-left corner, in screen coordinates.

For a child window, y is the initial y-coordinate of the upper-left corner of the child window relative to the upper-left corner of the parent window's client area.

For a list box y is the initial y-coordinate of the upper-left corner of the list box's client area relative to the upper-left corner of the parent window's client area.

If an overlapped window is created with the WS_VISIBLE style bit set and the x parameter is set to CW_USEDEFAULT, then the y parameter determines how the window is shown.

If the y parameter is CW_USEDEFAULT, then the window manager calls ShowWindow with the SW_SHOW flag after the window has been created.

If the y parameter is some other value, then the window manager calls ShowWindow(IntPtr, NativeWindowState) with that value as the windowState (nCmdShow) parameter.

width  Int32
The width, in device units, of the window.

For overlapped windows, nWidth is the window's width, in screen coordinates, or CW_USEDEFAULT.

If width is CW_USEDEFAULT, the system selects a default width and height for the window; the default width extends from the initial x-coordinates to the right edge of the screen; the default height extends from the initial y-coordinate to the top of the icon area.

CW_USEDEFAULT is valid only for overlapped windows; if CW_USEDEFAULT is specified for a pop-up or child window, the nWidth and nHeight parameter are set to zero.

height  Int32
The height, in device units, of the window.

For overlapped windows, nHeight is the window's height, in screen coordinates.

If the width parameter is set to CW_USEDEFAULT, the system ignores nHeight.

hWndParent  IntPtr  (Optional)
A handle to the parent or owner window of the window being created.

To create a child window or an owned window, supply a valid window handle.

This parameter is optional for pop-up windows.

To create a message-only window, supply HWND_MESSAGE or a handle to an existing message-only window.

hMenu  IntPtr  (Optional)
A handle to a menu, or specifies a child-window identifier, depending on the window style.

For an overlapped or pop-up window, hMenu identifies the menu to be used with the window; it can be NULL if the class menu is to be used.

For a child window, hMenu specifies the child-window identifier, an integer value used by a dialog box control to notify its parent about events.

The application determines the child-window identifier; it must be unique for all child windows with the same parent window.

hInstance  IntPtr
A handle to the instance of the module to be associated with the window.
param  IntPtr  (Optional)
Pointer to a value to be passed to the window through the CREATESTRUCT structure (lpCreateParams member) pointed to by the lParam param of the WM_Create message. This message is sent to the created window by this function before it returns.

If an application calls CreateWindowEx(WindowStylesEx, String, String, WindowStyles, Int32, Int32, Int32, Int32, IntPtr, IntPtr, IntPtr, IntPtr) to create a MDI client window, param should point to a CLIENTCREATESTRUCT structure.

If an MDI client window calls CreateWindowEx(WindowStylesEx, String, String, WindowStyles, Int32, Int32, Int32, Int32, IntPtr, IntPtr, IntPtr, IntPtr) to create an MDI child window, param should point to a MDICREATESTRUCT structure.

param may be Zero if no additional data is needed.

Return Value

IntPtr
If the function succeeds, the return value is a handle to the new window.

If the function fails, the return value is Zero.

Remarks

See Also