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作成するウィンドウの拡張ウィンドウスタイル。指定可能な値の一覧については、Extended Window Styles を参照してください。
lpClassNameLPCWSTRinoptional

null で終わる文字列、またはクラスアトム。

null で終わる文字列の場合、ウィンドウクラス名を指定します。クラス名には、RegisterClass または RegisterClassEx 関数で登録された任意の名前を指定できます。ただし、クラスを登録したモジュールがウィンドウを作成するモジュールと同一である必要があります。クラス名には、定義済みの システムクラス 名のいずれかを指定することもできます。

以前の RegisterClass または RegisterClassEx の呼び出しで作成されたクラスアトムの場合、MAKEINTATOM マクロを使用して変換する必要があります。(アトムは lpClassName の下位ワードに格納し、上位ワードはゼロにする必要があります。)

lpWindowNameLPCWSTRinoptionalウィンドウ名。ウィンドウスタイルでタイトルバーを指定している場合、lpWindowName が指すウィンドウタイトルがタイトルバーに表示されます。CreateWindow を使用してボタン、チェックボックス、スタティックコントロールなどのコントロールを作成する場合は、lpWindowName でコントロールのテキストを指定します。SS_ICON スタイルのスタティックコントロールを作成する場合は、lpWindowName でアイコン名または識別子を指定します。識別子を指定するには、「#num」という構文を使用します。
dwStyleWINDOW_STYLEin作成するウィンドウのスタイル。このパラメーターには、ウィンドウスタイルの値 と、「解説」セクションに示すコントロールスタイルを組み合わせて指定できます。
XINTinウィンドウの初期水平位置。オーバーラップウィンドウまたはポップアップウィンドウの場合、x パラメーターはウィンドウの左上隅の初期 x 座標(スクリーン座標)です。子ウィンドウの場合、x は親ウィンドウのクライアント領域の左上隅を基準としたウィンドウの左上隅の x 座標です。xCW_USEDEFAULT を設定すると、システムがウィンドウの左上隅の既定位置を選択し、y パラメーターは無視されます。CW_USEDEFAULT はオーバーラップウィンドウに対してのみ有効です。ポップアップウィンドウまたは子ウィンドウに指定した場合、x および y パラメーターはゼロに設定されます。
YINTin

ウィンドウの初期垂直位置。オーバーラップウィンドウまたはポップアップウィンドウの場合、y パラメーターはウィンドウの左上隅の初期 y 座標(スクリーン座標)です。子ウィンドウの場合、y は親ウィンドウのクライアント領域の左上隅を基準とした子ウィンドウの左上隅の初期 y 座標です。リストボックスの場合、y は親ウィンドウのクライアント領域の左上隅を基準としたリストボックスのクライアント領域の左上隅の初期 y 座標です。

オーバーラップウィンドウを WS_VISIBLE スタイルビットを設定して作成し、x パラメーターに CW_USEDEFAULT を設定した場合、y パラメーターによってウィンドウの表示方法が決まります。y パラメーターが CW_USEDEFAULT の場合、ウィンドウマネージャーはウィンドウ作成後に ShowWindowSW_SHOW フラグで呼び出します。y パラメーターがそれ以外の値の場合、ウィンドウマネージャーはその値を nCmdShow パラメーターとして ShowWindow を呼び出します。

nWidthINTinウィンドウの幅(デバイス単位)。オーバーラップウィンドウの場合、nWidth はウィンドウの幅(スクリーン座標)または CW_USEDEFAULT です。nWidthCW_USEDEFAULT の場合、システムはウィンドウの既定の幅と高さを選択します。既定の幅は初期 x 座標から画面の右端までとなり、既定の高さは初期 y 座標からアイコン領域の上端までとなります。CW_USEDEFAULT はオーバーラップウィンドウに対してのみ有効です。ポップアップウィンドウまたは子ウィンドウに CW_USEDEFAULT を指定した場合、nWidth および nHeight パラメーターはゼロに設定されます。
nHeightINTinウィンドウの高さ(デバイス単位)。オーバーラップウィンドウの場合、nHeight はウィンドウの高さ(スクリーン座標)です。nWidth パラメーターが CW_USEDEFAULT に設定されている場合、システムは nHeight を無視します。
hWndParentHWNDinoptional

作成するウィンドウの親ウィンドウまたはオーナーウィンドウへのハンドル。子ウィンドウまたは所有されたウィンドウを作成するには、有効なウィンドウハンドルを指定します。このパラメーターはポップアップウィンドウの場合は省略可能です。

メッセージ専用ウィンドウ を作成するには、HWND_MESSAGE または既存のメッセージ専用ウィンドウへのハンドルを指定します。

hMenuHMENUinoptionalメニューへのハンドル、またはウィンドウスタイルに応じて子ウィンドウ識別子を指定します。オーバーラップウィンドウまたはポップアップウィンドウの場合、hMenu はウィンドウで使用するメニューを識別します。クラスメニューを使用する場合は NULL にできます。子ウィンドウの場合、hMenu は子ウィンドウ識別子(ダイアログボックスコントロールがイベントを親に通知するために使用する整数値)を指定します。子ウィンドウ識別子はアプリケーションが決定し、同じ親ウィンドウを持つすべての子ウィンドウの間で一意である必要があります。
hInstanceHINSTANCEinoptionalウィンドウに関連付けるモジュールのインスタンスへのハンドル。
lpParamvoid*inoptional

WM_CREATE メッセージの lParam パラメーターが指す CREATESTRUCT 構造体(lpCreateParams メンバー)を通じてウィンドウに渡される値へのポインター。このメッセージは、本関数がリターンする前に、作成されたウィンドウへ送信されます。

アプリケーションが CreateWindow を呼び出して MDI クライアントウィンドウを作成する場合、lpParamCLIENTCREATESTRUCT 構造体を指す必要があります。MDI クライアントウィンドウが CreateWindow を呼び出して MDI 子ウィンドウを作成する場合、lpParamMDICREATESTRUCT 構造体を指す必要があります。追加データが不要な場合、lpParamNULL にできます。

戻り値の型: HWND

公式ドキュメント

拡張ウィンドウスタイルを指定して、オーバーラップ、ポップアップ、または子ウィンドウを作成します。それ以外の点では、この関数は CreateWindow 関数と同一です。(Unicode)

戻り値

型: HWND

関数が成功した場合、戻り値は新しいウィンドウへのハンドルです。

関数が失敗した場合、戻り値は NULL です。拡張エラー情報を取得するには、GetLastError を呼び出します。

この関数は通常、次のいずれかの理由で失敗します。

解説(Remarks)

CreateWindowEx 関数は、作成中のウィンドウへ WM_NCCREATEWM_NCCALCSIZEWM_CREATE メッセージを送信します。

作成されたウィンドウが子ウィンドウの場合、その既定位置は Z オーダーの最下位です。作成されたウィンドウがトップレベルウィンドウの場合、その既定位置は Z オーダーの最上位です(ただし、作成されたウィンドウ自体が最前面ウィンドウでない限り、すべての最前面ウィンドウの下になります)。

作成されたウィンドウに対してタスクバーがボタンを表示するかどうかを制御する方法については、Managing Taskbar Buttons を参照してください。

ウィンドウの削除については、DestroyWindow 関数を参照してください。

lpClassName パラメーターには、次の定義済みコントロールクラスを指定できます。dwStyle パラメーターで使用できる対応するコントロールスタイルにも注意してください。

クラス 意味
BUTTON ユーザーがクリックしてオンまたはオフを切り替えられるボタンを表す、小さな長方形の子ウィンドウを指定します。ボタンコントロールは単独でもグループでも使用でき、ラベル付きまたはテキストなしで表示できます。ボタンコントロールは通常、ユーザーがクリックすると外観が変化します。詳細については、Buttons を参照してください。

dwStyle パラメーターで指定できるボタンスタイルの一覧については、Button Styles を参照してください。

COMBOBOX リストボックスと、エディットコントロールに似た選択フィールドで構成されるコントロールを指定します。このスタイルを使用する場合、アプリケーションはリストボックスを常に表示するか、ドロップダウンリストボックスを有効にする必要があります。リストボックスが表示されている場合、選択フィールドに文字を入力すると、入力した文字に一致する最初のリストボックス項目が強調表示されます。逆に、リストボックスで項目を選択すると、選択したテキストが選択フィールドに表示されます。詳細については、Combo Boxes を参照してください。

dwStyle パラメーターで指定できるコンボボックススタイルの一覧については、Combo Box Styles を参照してください。

EDIT ユーザーがキーボードからテキストを入力できる長方形の子ウィンドウを指定します。ユーザーはコントロールをクリックするか、TAB キーを押して移動することでコントロールを選択し、キーボードフォーカスを与えます。エディットコントロールが点滅するキャレットを表示しているときにユーザーはテキストを入力できます。マウスを使用してカーソルを移動したり、置換する文字を選択したり、文字を挿入する位置にカーソルを配置したりできるほか、キーを使用して文字を削除できます。詳細については、Edit Controls を参照してください。

dwStyle パラメーターで指定できるエディットコントロールスタイルの一覧については、Edit Control Styles を参照してください。

LISTBOX 文字列のリストを指定します。ファイル名など、ユーザーが選択できる名前の一覧をアプリケーションが提示する必要がある場合は、必ずこのコントロールを指定します。ユーザーは文字列をクリックして選択できます。選択された文字列は強調表示され、通知メッセージが親ウィンドウに渡されます。詳細については、List Boxes を参照してください。

dwStyle パラメーターで指定できるリストボックススタイルの一覧については、List Box Styles を参照してください。

MDICLIENT MDI クライアントウィンドウを指定します。このウィンドウは、MDI アプリケーションの子ウィンドウを制御するメッセージを受信します。推奨されるスタイルビットは WS_CLIPCHILDRENWS_CHILD です。WS_HSCROLLWS_VSCROLL スタイルを指定すると、ユーザーが MDI 子ウィンドウをスクロールして表示できる MDI クライアントウィンドウを作成できます。詳細については、Multiple Document Interface を参照してください。
RichEdit Microsoft Rich Edit 1.0 コントロールを指定します。このウィンドウでは、ユーザーは文字および段落の書式設定を伴うテキストを表示および編集でき、埋め込みの Component Object Model (COM) オブジェクトを含めることができます。詳細については、Rich Edit Controls を参照してください。

dwStyle パラメーターで指定できるリッチエディットコントロールスタイルの一覧については、Rich Edit Control Styles を参照してください。

RICHEDIT_CLASS Microsoft Rich Edit 2.0 コントロールを指定します。このコントロールでは、ユーザーは文字および段落の書式設定を伴うテキストを表示および編集でき、埋め込みの COM オブジェクトを含めることができます。詳細については、Rich Edit Controls を参照してください。

dwStyle パラメーターで指定できるリッチエディットコントロールスタイルの一覧については、Rich Edit Control Styles を参照してください。

SCROLLBAR スクロールボックスを含み、両端に方向矢印を持つ長方形を指定します。スクロールバーは、ユーザーがコントロールをクリックするたびに親ウィンドウへ通知メッセージを送信します。親ウィンドウは、必要に応じてスクロールボックスの位置を更新する責任を負います。詳細については、Scroll Bars を参照してください。

dwStyle パラメーターで指定できるスクロールバーコントロールスタイルの一覧については、Scroll Bar Control Styles を参照してください。

STATIC 他のコントロールにラベルを付けたり、枠で囲んだり、区切ったりするために使用する、単純なテキストフィールド、ボックス、または長方形を指定します。スタティックコントロールは入力を受け取らず、出力も提供しません。詳細については、Static Controls を参照してください。

dwStyle パラメーターで指定できるスタティックコントロールスタイルの一覧については、Static Control Styles を参照してください。

dwExStyleWS_EX_NOACTIVATE 値は、システムによる前面へのアクティブ化を防ぎます。ユーザーがウィンドウをクリックしたときのキューアクティブ化を防ぐには、WM_MOUSEACTIVATE メッセージを適切に処理する必要があります。ウィンドウをプログラムで前面に移動またはアクティブ化するには、SetForegroundWindow または SetActiveWindow を使用します。WM_NCACTIVATE に対して FALSE を返すと、ウィンドウがキューアクティブ化を失うのを防げます。ただし、アクティブ化時には戻り値は無視されます。

WS_EX_COMPOSITED を設定すると、ウィンドウのすべての子孫はダブルバッファリングを使用して下から上への描画順序になります。下から上への描画順序により、子孫ウィンドウは半透明(アルファ)および透過(カラーキー)効果を持つことができますが、これは子孫ウィンドウにも WS_EX_TRANSPARENT ビットが設定されている場合に限られます。ダブルバッファリングにより、ウィンドウとその子孫をちらつきなく描画できます。

次のサンプルコードは、CreateWindowExA の使用方法を示しています。

BOOL Create(
        PCWSTR lpWindowName,
        DWORD dwStyle,
        DWORD dwExStyle = 0,
        int x = CW_USEDEFAULT,
        int y = CW_USEDEFAULT,
        int nWidth = CW_USEDEFAULT,
        int nHeight = CW_USEDEFAULT,
        HWND hWndParent = 0,
        HMENU hMenu = 0
        )
    {
        WNDCLASS wc = {0};

        wc.lpfnWndProc   = DERIVED_TYPE::WindowProc;
        wc.hInstance     = GetModuleHandle(NULL);
        wc.lpszClassName = ClassName();

        RegisterClass(&wc);

        m_hwnd = CreateWindowEx(
            dwExStyle, ClassName(), lpWindowName, dwStyle, x, y,
            nWidth, nHeight, hWndParent, hMenu, GetModuleHandle(NULL), this
            );

        return (m_hwnd ? TRUE : FALSE);
    }
メモ

winuser.h ヘッダーは、UNICODE プリプロセッサ定数の定義に基づいて、この関数の ANSI 版または Unicode 版を自動的に選択するエイリアスとして CreateWindowEx を定義します。エンコード非依存のエイリアスの使用を、エンコード非依存でないコードと混在させると、コンパイルエラーまたは実行時エラーを引き起こす不一致につながる可能性があります。詳細については、Conventions for Function Prototypes を参照してください。

出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)

各言語での呼び出し定義

// 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 版の利用を推奨。
const std = @import("std");

extern "user32" fn CreateWindowExW(
    dwExStyle: u32, // WINDOW_EX_STYLE
    lpClassName: [*c]const u16, // LPCWSTR optional
    lpWindowName: [*c]const u16, // LPCWSTR optional
    dwStyle: u32, // WINDOW_STYLE
    X: i32, // INT
    Y: i32, // INT
    nWidth: i32, // INT
    nHeight: i32, // INT
    hWndParent: ?*anyopaque, // HWND optional
    hMenu: ?*anyopaque, // HMENU optional
    hInstance: ?*anyopaque, // HINSTANCE optional
    lpParam: ?*anyopaque // void* optional
) callconv(std.os.windows.WINAPI) ?*anyopaque;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。
proc CreateWindowExW(
    dwExStyle: uint32,  # WINDOW_EX_STYLE
    lpClassName: WideCString,  # LPCWSTR optional
    lpWindowName: WideCString,  # LPCWSTR optional
    dwStyle: uint32,  # WINDOW_STYLE
    X: int32,  # INT
    Y: int32,  # INT
    nWidth: int32,  # INT
    nHeight: int32,  # INT
    hWndParent: pointer,  # HWND optional
    hMenu: pointer,  # HMENU optional
    hInstance: pointer,  # HINSTANCE optional
    lpParam: pointer  # void* optional
): pointer {.importc: "CreateWindowExW", stdcall, dynlib: "USER32.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。
pragma(lib, "user32");
extern(Windows)
void* CreateWindowExW(
    uint dwExStyle,   // WINDOW_EX_STYLE
    const(wchar)* lpClassName,   // LPCWSTR optional
    const(wchar)* lpWindowName,   // LPCWSTR optional
    uint dwStyle,   // WINDOW_STYLE
    int X,   // INT
    int Y,   // INT
    int nWidth,   // INT
    int nHeight,   // INT
    void* hWndParent,   // HWND optional
    void* hMenu,   // HMENU optional
    void* hInstance,   // HINSTANCE optional
    void* lpParam   // void* optional
);
ccall((:CreateWindowExW, "USER32.dll"), stdcall, Ptr{Cvoid},
      (UInt32, Cwstring, Cwstring, UInt32, Int32, Int32, Int32, Int32, Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Cvoid}),
      dwExStyle, lpClassName, lpWindowName, dwStyle, X, Y, nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam)
# dwExStyle : WINDOW_EX_STYLE -> UInt32
# lpClassName : LPCWSTR optional -> Cwstring
# lpWindowName : LPCWSTR optional -> Cwstring
# dwStyle : WINDOW_STYLE -> UInt32
# X : INT -> Int32
# Y : INT -> Int32
# nWidth : INT -> Int32
# nHeight : INT -> Int32
# hWndParent : HWND optional -> Ptr{Cvoid}
# hMenu : HMENU optional -> Ptr{Cvoid}
# hInstance : HINSTANCE optional -> Ptr{Cvoid}
# lpParam : void* optional -> Ptr{Cvoid}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。
local ffi = require("ffi")
ffi.cdef[[
void* CreateWindowExW(
    uint32_t dwExStyle,
    const uint16_t* lpClassName,
    const uint16_t* lpWindowName,
    uint32_t dwStyle,
    int32_t X,
    int32_t Y,
    int32_t nWidth,
    int32_t nHeight,
    void* hWndParent,
    void* hMenu,
    void* hInstance,
    void* lpParam);
]]
local user32 = ffi.load("user32")
-- user32.CreateWindowExW(dwExStyle, lpClassName, lpWindowName, dwStyle, X, Y, nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam)
-- 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
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
-- Unicode(-W): uint16_t* には UTF-16LE のバッファ(ffi.new("uint16_t[?]", ...))を渡す。
const koffi = require('koffi');
const lib = koffi.load('USER32.dll');
const CreateWindowExW = lib.func('__stdcall', 'CreateWindowExW', 'void *', ['uint32_t', 'str16', 'str16', 'uint32_t', 'int32_t', 'int32_t', 'int32_t', 'int32_t', 'void *', 'void *', 'void *', 'void *']);
// CreateWindowExW(dwExStyle, lpClassName, lpWindowName, dwStyle, X, Y, nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam)
// dwExStyle : WINDOW_EX_STYLE -> 'uint32_t'
// lpClassName : LPCWSTR optional -> 'str16'
// lpWindowName : LPCWSTR optional -> 'str16'
// dwStyle : WINDOW_STYLE -> 'uint32_t'
// X : INT -> 'int32_t'
// Y : INT -> 'int32_t'
// nWidth : INT -> 'int32_t'
// nHeight : INT -> 'int32_t'
// hWndParent : HWND optional -> 'void *'
// hMenu : HMENU optional -> 'void *'
// hInstance : HINSTANCE optional -> 'void *'
// lpParam : void* optional -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("USER32.dll", {
  CreateWindowExW: { parameters: ["u32", "buffer", "buffer", "u32", "i32", "i32", "i32", "i32", "pointer", "pointer", "pointer", "pointer"], result: "pointer" },
});
// lib.symbols.CreateWindowExW(dwExStyle, lpClassName, lpWindowName, dwStyle, X, Y, nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam)
// dwExStyle : WINDOW_EX_STYLE -> "u32"
// lpClassName : LPCWSTR optional -> "buffer"
// lpWindowName : LPCWSTR optional -> "buffer"
// dwStyle : WINDOW_STYLE -> "u32"
// X : INT -> "i32"
// Y : INT -> "i32"
// nWidth : INT -> "i32"
// nHeight : INT -> "i32"
// hWndParent : HWND optional -> "pointer"
// hMenu : HMENU optional -> "pointer"
// hInstance : HINSTANCE optional -> "pointer"
// lpParam : void* optional -> "pointer"
// 文字列は "buffer"。Unicode(-W) は new TextEncoder() ではなく UTF-16LE のバイト列(末尾に \x00\x00)を Uint8Array で渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
void* CreateWindowExW(
    uint32_t dwExStyle,
    const uint16_t* lpClassName,
    const uint16_t* lpWindowName,
    uint32_t dwStyle,
    int32_t X,
    int32_t Y,
    int32_t nWidth,
    int32_t nHeight,
    void* hWndParent,
    void* hMenu,
    void* hInstance,
    void* lpParam);
C, "USER32.dll");
// $ffi->CreateWindowExW(dwExStyle, lpClassName, lpWindowName, dwStyle, X, Y, nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam);
// 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
// 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
// WINAPI(stdcall): x64 では呼出規約が統一されるため問題なし。x86 では __stdcall 対応のラッパが必要な場合あり。
import com.sun.jna.*;
import com.sun.jna.ptr.*;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;

public interface User32 extends StdCallLibrary {
    User32 INSTANCE = Native.load("user32", User32.class, W32APIOptions.UNICODE_OPTIONS);
    Pointer CreateWindowExW(
        int dwExStyle,   // WINDOW_EX_STYLE
        WString lpClassName,   // LPCWSTR optional
        WString lpWindowName,   // LPCWSTR optional
        int dwStyle,   // WINDOW_STYLE
        int X,   // INT
        int Y,   // INT
        int nWidth,   // INT
        int nHeight,   // INT
        Pointer hWndParent,   // HWND optional
        Pointer hMenu,   // HMENU optional
        Pointer hInstance,   // HINSTANCE optional
        Pointer lpParam   // void* optional
    );
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。
@[Link("user32")]
lib LibUSER32
  fun CreateWindowExW = CreateWindowExW(
    dwExStyle : UInt32,   # WINDOW_EX_STYLE
    lpClassName : UInt16*,   # LPCWSTR optional
    lpWindowName : UInt16*,   # LPCWSTR optional
    dwStyle : UInt32,   # WINDOW_STYLE
    X : Int32,   # INT
    Y : Int32,   # INT
    nWidth : Int32,   # INT
    nHeight : Int32,   # INT
    hWndParent : Void*,   # HWND optional
    hMenu : Void*,   # HMENU optional
    hInstance : Void*,   # HINSTANCE optional
    lpParam : Void*   # void* optional
  ) : Void*
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef CreateWindowExWNative = Pointer<Void> Function(Uint32, Pointer<Utf16>, Pointer<Utf16>, Uint32, Int32, Int32, Int32, Int32, Pointer<Void>, Pointer<Void>, Pointer<Void>, Pointer<Void>);
typedef CreateWindowExWDart = Pointer<Void> Function(int, Pointer<Utf16>, Pointer<Utf16>, int, int, int, int, int, Pointer<Void>, Pointer<Void>, Pointer<Void>, Pointer<Void>);
final CreateWindowExW = DynamicLibrary.open('USER32.dll')
    .lookupFunction<CreateWindowExWNative, CreateWindowExWDart>('CreateWindowExW');
// dwExStyle : WINDOW_EX_STYLE -> Uint32
// lpClassName : LPCWSTR optional -> Pointer<Utf16>
// lpWindowName : LPCWSTR optional -> Pointer<Utf16>
// dwStyle : WINDOW_STYLE -> Uint32
// X : INT -> Int32
// Y : INT -> Int32
// nWidth : INT -> Int32
// nHeight : INT -> Int32
// hWndParent : HWND optional -> Pointer<Void>
// hMenu : HMENU optional -> Pointer<Void>
// hInstance : HINSTANCE optional -> Pointer<Void>
// lpParam : void* optional -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
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';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "CreateWindowExW"
  c_CreateWindowExW :: Word32 -> CWString -> CWString -> Word32 -> Int32 -> Int32 -> Int32 -> Int32 -> Ptr () -> Ptr () -> Ptr () -> Ptr () -> IO (Ptr ())
-- dwExStyle : WINDOW_EX_STYLE -> Word32
-- lpClassName : LPCWSTR optional -> CWString
-- lpWindowName : LPCWSTR optional -> CWString
-- dwStyle : WINDOW_STYLE -> Word32
-- X : INT -> Int32
-- Y : INT -> Int32
-- nWidth : INT -> Int32
-- nHeight : INT -> Int32
-- hWndParent : HWND optional -> Ptr ()
-- hMenu : HMENU optional -> Ptr ()
-- hInstance : HINSTANCE optional -> Ptr ()
-- lpParam : void* optional -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let createwindowexw =
  foreign "CreateWindowExW"
    (uint32_t @-> (ptr uint16_t) @-> (ptr uint16_t) @-> uint32_t @-> int32_t @-> int32_t @-> int32_t @-> int32_t @-> (ptr void) @-> (ptr void) @-> (ptr void) @-> (ptr void) @-> returning (ptr void))
(* dwExStyle : WINDOW_EX_STYLE -> uint32_t *)
(* lpClassName : LPCWSTR optional -> (ptr uint16_t) *)
(* lpWindowName : LPCWSTR optional -> (ptr uint16_t) *)
(* dwStyle : WINDOW_STYLE -> uint32_t *)
(* X : INT -> int32_t *)
(* Y : INT -> int32_t *)
(* nWidth : INT -> int32_t *)
(* nHeight : INT -> int32_t *)
(* hWndParent : HWND optional -> (ptr void) *)
(* hMenu : HMENU optional -> (ptr void) *)
(* hInstance : HINSTANCE optional -> (ptr void) *)
(* lpParam : void* optional -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library user32 (t "USER32.dll"))
(cffi:use-foreign-library user32)

(cffi:defcfun ("CreateWindowExW" create-window-ex-w :convention :stdcall) :pointer
  (dw-ex-style :uint32)   ; WINDOW_EX_STYLE
  (lp-class-name (:string :encoding :utf-16le))   ; LPCWSTR optional
  (lp-window-name (:string :encoding :utf-16le))   ; LPCWSTR optional
  (dw-style :uint32)   ; WINDOW_STYLE
  (x :int32)   ; INT
  (y :int32)   ; INT
  (n-width :int32)   ; INT
  (n-height :int32)   ; INT
  (h-wnd-parent :pointer)   ; HWND optional
  (h-menu :pointer)   ; HMENU optional
  (h-instance :pointer)   ; HINSTANCE optional
  (lp-param :pointer))   ; void* optional
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $CreateWindowExW = Win32::API::More->new('USER32',
    'HANDLE CreateWindowExW(DWORD dwExStyle, LPCWSTR lpClassName, LPCWSTR lpWindowName, DWORD dwStyle, int X, int Y, int nWidth, int nHeight, HANDLE hWndParent, HANDLE hMenu, HANDLE hInstance, LPVOID lpParam)');
# my $ret = $CreateWindowExW->Call($dwExStyle, $lpClassName, $lpWindowName, $dwStyle, $X, $Y, $nWidth, $nHeight, $hWndParent, $hMenu, $hInstance, $lpParam);
# dwExStyle : WINDOW_EX_STYLE -> DWORD
# lpClassName : LPCWSTR optional -> LPCWSTR
# lpWindowName : LPCWSTR optional -> LPCWSTR
# dwStyle : WINDOW_STYLE -> DWORD
# X : INT -> int
# Y : INT -> int
# nWidth : INT -> int
# nHeight : INT -> int
# hWndParent : HWND optional -> HANDLE
# hMenu : HMENU optional -> HANDLE
# hInstance : HINSTANCE optional -> HANDLE
# lpParam : void* optional -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。

関連項目

文字セット違い
公式の関連項目
使用する型