Win32 API 日本語リファレンス
ホームUI.WindowsAndMessaging › CreateWindowExW

CreateWindowExW

関数
拡張スタイル指定でウィンドウを作成する(Unicode)。
DLLUSER32.dll文字セットUnicode (-W)呼出規約winapiSetLastErrorあり対応OSWindows 2000 以降

シグネチャ

// USER32.dll  (Unicode / -W)
#include <windows.h>

HWND CreateWindowExW(
    WINDOW_EX_STYLE dwExStyle,
    LPCWSTR lpClassName,   // optional
    LPCWSTR lpWindowName,   // optional
    WINDOW_STYLE dwStyle,
    INT X,
    INT Y,
    INT nWidth,
    INT nHeight,
    HWND hWndParent,   // optional
    HMENU hMenu,   // optional
    HINSTANCE hInstance,   // optional
    void* lpParam   // optional
);

パラメーター

名前方向
dwExStyleWINDOW_EX_STYLEin
lpClassNameLPCWSTRinoptional
lpWindowNameLPCWSTRinoptional
dwStyleWINDOW_STYLEin
XINTin
YINTin
nWidthINTin
nHeightINTin
hWndParentHWNDinoptional
hMenuHMENUinoptional
hInstanceHINSTANCEinoptional
lpParamvoid*inoptional

戻り値の型: HWND

各言語での呼び出し定義

// USER32.dll  (Unicode / -W)
#include <windows.h>

HWND CreateWindowExW(
    WINDOW_EX_STYLE dwExStyle,
    LPCWSTR lpClassName,   // optional
    LPCWSTR lpWindowName,   // optional
    WINDOW_STYLE dwStyle,
    INT X,
    INT Y,
    INT nWidth,
    INT nHeight,
    HWND hWndParent,   // optional
    HMENU hMenu,   // optional
    HINSTANCE hInstance,   // optional
    void* lpParam   // optional
);
[DllImport("USER32.dll", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
static extern IntPtr CreateWindowExW(
    uint dwExStyle,   // WINDOW_EX_STYLE
    [MarshalAs(UnmanagedType.LPWStr)] string lpClassName,   // LPCWSTR optional
    [MarshalAs(UnmanagedType.LPWStr)] string lpWindowName,   // LPCWSTR optional
    uint dwStyle,   // WINDOW_STYLE
    int X,   // INT
    int Y,   // INT
    int nWidth,   // INT
    int nHeight,   // INT
    IntPtr hWndParent,   // HWND optional
    IntPtr hMenu,   // HMENU optional
    IntPtr hInstance,   // HINSTANCE optional
    IntPtr lpParam   // void* optional
);
<DllImport("USER32.dll", CharSet:=CharSet.Unicode, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function CreateWindowExW(
    dwExStyle As UInteger,   ' WINDOW_EX_STYLE
    <MarshalAs(UnmanagedType.LPWStr)> lpClassName As String,   ' LPCWSTR optional
    <MarshalAs(UnmanagedType.LPWStr)> lpWindowName As String,   ' LPCWSTR optional
    dwStyle As UInteger,   ' WINDOW_STYLE
    X As Integer,   ' INT
    Y As Integer,   ' INT
    nWidth As Integer,   ' INT
    nHeight As Integer,   ' INT
    hWndParent As IntPtr,   ' HWND optional
    hMenu As IntPtr,   ' HMENU optional
    hInstance As IntPtr,   ' HINSTANCE optional
    lpParam As IntPtr   ' void* optional
) As IntPtr
End Function
' dwExStyle : WINDOW_EX_STYLE
' lpClassName : LPCWSTR optional
' lpWindowName : LPCWSTR optional
' dwStyle : WINDOW_STYLE
' X : INT
' Y : INT
' nWidth : INT
' nHeight : INT
' hWndParent : HWND optional
' hMenu : HMENU optional
' hInstance : HINSTANCE optional
' lpParam : void* optional
Declare PtrSafe Function CreateWindowExW Lib "user32" ( _
    ByVal dwExStyle As Long, _
    ByVal lpClassName As LongPtr, _
    ByVal lpWindowName As LongPtr, _
    ByVal dwStyle As Long, _
    ByVal X As Long, _
    ByVal Y As Long, _
    ByVal nWidth As Long, _
    ByVal nHeight As Long, _
    ByVal hWndParent As LongPtr, _
    ByVal hMenu As LongPtr, _
    ByVal hInstance As LongPtr, _
    ByVal lpParam As LongPtr) As LongPtr
' Unicode(W): 文字列は ByVal As LongPtr とし StrPtr(unicodeStr) を渡す
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

CreateWindowExW = ctypes.windll.user32.CreateWindowExW
CreateWindowExW.restype = ctypes.c_void_p
CreateWindowExW.argtypes = [
    wintypes.DWORD,  # dwExStyle : WINDOW_EX_STYLE
    wintypes.LPCWSTR,  # lpClassName : LPCWSTR optional
    wintypes.LPCWSTR,  # lpWindowName : LPCWSTR optional
    wintypes.DWORD,  # dwStyle : WINDOW_STYLE
    ctypes.c_int,  # X : INT
    ctypes.c_int,  # Y : INT
    ctypes.c_int,  # nWidth : INT
    ctypes.c_int,  # nHeight : INT
    wintypes.HANDLE,  # hWndParent : HWND optional
    wintypes.HANDLE,  # hMenu : HMENU optional
    wintypes.HANDLE,  # hInstance : HINSTANCE optional
    ctypes.POINTER(None),  # lpParam : void* optional
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('USER32.dll')
CreateWindowExW = Fiddle::Function.new(
  lib['CreateWindowExW'],
  [
    -Fiddle::TYPE_INT,  # dwExStyle : WINDOW_EX_STYLE
    Fiddle::TYPE_VOIDP,  # lpClassName : LPCWSTR optional
    Fiddle::TYPE_VOIDP,  # lpWindowName : LPCWSTR optional
    -Fiddle::TYPE_INT,  # dwStyle : WINDOW_STYLE
    Fiddle::TYPE_INT,  # X : INT
    Fiddle::TYPE_INT,  # Y : INT
    Fiddle::TYPE_INT,  # nWidth : INT
    Fiddle::TYPE_INT,  # nHeight : INT
    Fiddle::TYPE_VOIDP,  # hWndParent : HWND optional
    Fiddle::TYPE_VOIDP,  # hMenu : HMENU optional
    Fiddle::TYPE_VOIDP,  # hInstance : HINSTANCE optional
    Fiddle::TYPE_VOIDP,  # lpParam : void* optional
  ],
  Fiddle::TYPE_VOIDP)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "user32")]
extern "system" {
    fn CreateWindowExW(
        dwExStyle: u32,  // WINDOW_EX_STYLE
        lpClassName: *const u16,  // LPCWSTR optional
        lpWindowName: *const u16,  // LPCWSTR optional
        dwStyle: u32,  // WINDOW_STYLE
        X: i32,  // INT
        Y: i32,  // INT
        nWidth: i32,  // INT
        nHeight: i32,  // INT
        hWndParent: *mut core::ffi::c_void,  // HWND optional
        hMenu: *mut core::ffi::c_void,  // HMENU optional
        hInstance: *mut core::ffi::c_void,  // HINSTANCE optional
        lpParam: *mut ()  // void* optional
    ) -> *mut core::ffi::c_void;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("USER32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern IntPtr CreateWindowExW(uint dwExStyle, [MarshalAs(UnmanagedType.LPWStr)] string lpClassName, [MarshalAs(UnmanagedType.LPWStr)] string lpWindowName, uint dwStyle, int X, int Y, int nWidth, int nHeight, IntPtr hWndParent, IntPtr hMenu, IntPtr hInstance, IntPtr lpParam);
"@
$api = Add-Type -MemberDefinition $sig -Name 'USER32_CreateWindowExW' -Namespace Win32 -PassThru
# $api::CreateWindowExW(dwExStyle, lpClassName, lpWindowName, dwStyle, X, Y, nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam)
#uselib "USER32.dll"
#func global CreateWindowExW "CreateWindowExW" wptr, wptr, wptr, wptr, wptr, wptr, wptr, wptr, wptr, wptr, wptr, wptr
; CreateWindowExW dwExStyle, lpClassName, lpWindowName, dwStyle, X, Y, nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam   ; 戻り値は stat
; dwExStyle : WINDOW_EX_STYLE -> "wptr"
; lpClassName : LPCWSTR optional -> "wptr"
; lpWindowName : LPCWSTR optional -> "wptr"
; dwStyle : WINDOW_STYLE -> "wptr"
; X : INT -> "wptr"
; Y : INT -> "wptr"
; nWidth : INT -> "wptr"
; nHeight : INT -> "wptr"
; hWndParent : HWND optional -> "wptr"
; hMenu : HMENU optional -> "wptr"
; hInstance : HINSTANCE optional -> "wptr"
; lpParam : void* optional -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "USER32.dll"
#cfunc global CreateWindowExW "CreateWindowExW" int, wstr, wstr, int, int, int, int, int, sptr, sptr, sptr, sptr
; res = CreateWindowExW(dwExStyle, lpClassName, lpWindowName, dwStyle, X, Y, nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam)
; dwExStyle : WINDOW_EX_STYLE -> "int"
; lpClassName : LPCWSTR optional -> "wstr"
; lpWindowName : LPCWSTR optional -> "wstr"
; dwStyle : WINDOW_STYLE -> "int"
; X : INT -> "int"
; Y : INT -> "int"
; nWidth : INT -> "int"
; nHeight : INT -> "int"
; hWndParent : HWND optional -> "sptr"
; hMenu : HMENU optional -> "sptr"
; hInstance : HINSTANCE optional -> "sptr"
; lpParam : void* optional -> "sptr"
; HWND CreateWindowExW(WINDOW_EX_STYLE dwExStyle, LPCWSTR lpClassName, LPCWSTR lpWindowName, WINDOW_STYLE dwStyle, INT X, INT Y, INT nWidth, INT nHeight, HWND hWndParent, HMENU hMenu, HINSTANCE hInstance, void* lpParam)
#uselib "USER32.dll"
#cfunc global CreateWindowExW "CreateWindowExW" int, wstr, wstr, int, int, int, int, int, intptr, intptr, intptr, intptr
; res = CreateWindowExW(dwExStyle, lpClassName, lpWindowName, dwStyle, X, Y, nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam)
; dwExStyle : WINDOW_EX_STYLE -> "int"
; lpClassName : LPCWSTR optional -> "wstr"
; lpWindowName : LPCWSTR optional -> "wstr"
; dwStyle : WINDOW_STYLE -> "int"
; X : INT -> "int"
; Y : INT -> "int"
; nWidth : INT -> "int"
; nHeight : INT -> "int"
; hWndParent : HWND optional -> "intptr"
; hMenu : HMENU optional -> "intptr"
; hInstance : HINSTANCE optional -> "intptr"
; lpParam : void* optional -> "intptr"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	user32 = windows.NewLazySystemDLL("USER32.dll")
	procCreateWindowExW = user32.NewProc("CreateWindowExW")
)

// dwExStyle (WINDOW_EX_STYLE), lpClassName (LPCWSTR optional), lpWindowName (LPCWSTR optional), dwStyle (WINDOW_STYLE), X (INT), Y (INT), nWidth (INT), nHeight (INT), hWndParent (HWND optional), hMenu (HMENU optional), hInstance (HINSTANCE optional), lpParam (void* optional)
r1, _, err := procCreateWindowExW.Call(
	uintptr(dwExStyle),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpClassName))),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpWindowName))),
	uintptr(dwStyle),
	uintptr(X),
	uintptr(Y),
	uintptr(nWidth),
	uintptr(nHeight),
	uintptr(hWndParent),
	uintptr(hMenu),
	uintptr(hInstance),
	uintptr(lpParam),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HWND
function CreateWindowExW(
  dwExStyle: DWORD;   // WINDOW_EX_STYLE
  lpClassName: PWideChar;   // LPCWSTR optional
  lpWindowName: PWideChar;   // LPCWSTR optional
  dwStyle: DWORD;   // WINDOW_STYLE
  X: Integer;   // INT
  Y: Integer;   // INT
  nWidth: Integer;   // INT
  nHeight: Integer;   // INT
  hWndParent: THandle;   // HWND optional
  hMenu: THandle;   // HMENU optional
  hInstance: THandle;   // HINSTANCE optional
  lpParam: Pointer   // void* optional
): THandle; stdcall;
  external 'USER32.dll' name 'CreateWindowExW';
result := DllCall("USER32\CreateWindowExW"
    , "UInt", dwExStyle   ; WINDOW_EX_STYLE
    , "WStr", lpClassName   ; LPCWSTR optional
    , "WStr", lpWindowName   ; LPCWSTR optional
    , "UInt", dwStyle   ; WINDOW_STYLE
    , "Int", X   ; INT
    , "Int", Y   ; INT
    , "Int", nWidth   ; INT
    , "Int", nHeight   ; INT
    , "Ptr", hWndParent   ; HWND optional
    , "Ptr", hMenu   ; HMENU optional
    , "Ptr", hInstance   ; HINSTANCE optional
    , "Ptr", lpParam   ; void* optional
    , "Ptr")   ; return: HWND
●CreateWindowExW(dwExStyle, lpClassName, lpWindowName, dwStyle, X, Y, nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam) = DLL("USER32.dll", "void* CreateWindowExW(dword, char*, char*, dword, int, int, int, int, void*, void*, void*, void*)")
# 呼び出し: CreateWindowExW(dwExStyle, lpClassName, lpWindowName, dwStyle, X, Y, nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam)
# dwExStyle : WINDOW_EX_STYLE -> "dword"
# lpClassName : LPCWSTR optional -> "char*"
# lpWindowName : LPCWSTR optional -> "char*"
# dwStyle : WINDOW_STYLE -> "dword"
# X : INT -> "int"
# Y : INT -> "int"
# nWidth : INT -> "int"
# nHeight : INT -> "int"
# hWndParent : HWND optional -> "void*"
# hMenu : HMENU optional -> "void*"
# hInstance : HINSTANCE optional -> "void*"
# lpParam : void* optional -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。