Type a page name and press Enter. You'll jump to the page if it exists, or you can create it if it doesn't.
To create a page in a module other than user32, prefix the name with the module name and a period.
CreateWindow (user32)
.
C# Signature:
[DllImport("user32.dll", SetLastError=true)]
static extern IntPtr CreateWindow(
string lpClassName,
string lpWindowName,
uint dwStyle,
int x,
int y,
int nWidth,
int nHeight,
IntPtr hWndParent,
IntPtr hMenu,
IntPtr hInstance,
IntPtr lpParam);
VB Signature:
C# Signature:
[DllImport("user32.dll", EntryPoint="CreateWindowStation", CharSet=CharSet.Unicode, SetLastError=true)]
public static extern IntPtr CreateWindowStation(
[MarshalAs(UnmanagedType.LPWStr)] string name,
[MarshalAs(UnmanagedType.U4)] int reserved, // must be zero.
[MarshalAs(UnmanagedType.U4)] WINDOWS_STATION_ACCESS_MASK desiredAccess,
[MarshalAs(UnmanagedType.LPStruct)] SecurityAttributes attributes);
User-Defined Types:
None.
Alternative Managed API:
Windows Forms (System.Windows)
Windows Presentation Foundation (System.Windows.Forms)
Notes:
None.
Tips & Tricks:
Please add some!
Sample Code:
[StructLayout(LayoutKind.Sequential)]
public class SecurityAttributes
{
#region Struct members
[MarshalAs(UnmanagedType.U4)]
private int mStuctLength;
/// <summary>
/// Base class for the safe handles used for Windows Station and Desktop API.
/// </summary>
public abstract class BaseSafeHandle : SafeHandleZeroOrMinusOneIsInvalid
{
protected BaseSafeHandle(IntPtr handle, bool ownsHandle)
: base(ownsHandle)
{
SetHandle(handle);
}
/// <summary>
/// Close the native handle. The real call is dependent on whether it is
/// a WindowsStation or a Desktop.
/// </summary>
/// <param name="handle">Handle to be closed.</param>
/// <returns>true if successful, false other wise.</returns>
protected abstract bool CloseNativeHandle(IntPtr handle);
public class SafeWindowStationHandle : BaseSafeHandle
{
public SafeWindowStationHandle(IntPtr handle, bool ownsHandle)
: base(handle, ownsHandle)
{ }
protected override bool CloseNativeHandle(IntPtr handle)
{
return WindowStationAndDesktop.CloseWindowStation(handle);
}
}
public static SafeWindowStationHandle CreateWindowStation(string name)
{
if (string.IsNullOrEmpty(name))
{
throw new ArgumentException("Invalid window station name", "name");
}
IntPtr handle = WindowStationAndDesktop.CreateWindowStation(name, 0,
WINDOWS_STATION_ACCESS_MASK.WINSTA_ALL_ACCESS, null);
if (handle == IntPtr.Zero)
{
int error = Marshal.GetLastWin32Error();
throw new Win32Exception(error);
}
SafeWindowStationHandle safeHandle = new SafeWindowStationHandle(handle, true);
return safeHandle;
}
Alternative Managed API:
Do you know one? Please contribute it!
The CreateWindow function creates an overlapped, pop-up, or child window. It specifies the window class, window title, window style, and (optionally) the initial position and size of the window. The function also specifies the window's parent or owner, if any, and the window's menu. To use extended window styles in addition to the styles supported by CreateWindow, use the CreateWindowEx function.
11/10/2022 5:10:32 AM - 2.35.150.218
The CreateWindow function creates an overlapped, pop-up, or child window. It specifies the window class, window title, window style, and (optionally) the initial position and size of the window. The function also specifies the window's parent or owner, if any, and the window's menu. To use extended window styles in addition to the styles supported by CreateWindow, use the CreateWindowEx function.
11/10/2022 5:10:32 AM - 2.35.150.218
Like CreateWindow, but creates the window with an extended window style.
12/23/2022 5:31:17 AM - 147.78.47.33
Click to read this page
11/30/2018 2:31:03 AM - -79.133.249.105
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).