CreateWindowEx function
Synopsis
HWND CreateWindowEx(
DWORD dwExStyle,
LPCTSTR lpClassName,
LPCTSTR lpWindowName,
DWORD dwStyle,
int x,
int y,
int nWidth,
int nHeight,
HWND hWndParent,
HMENU hMenu,
HINSTANCE hInstance,
LPVOID lpParam
);
Parameters
| dwExStyle | Extended window style. |
|---|---|
| lpClassName | Pointer to a null-terminated string or a class atom. |
| lpWindowName | Window title. |
| dwStyle | Window style. |
| x | Initial horizontal position. |
| y | Initial vertical position. |
| nWidth | Initial width. |
| nHeight | Initial height. |
| hWndParent | Handle to parent or owner window. |
| hMenu | Handle to a menu, or child-window identifier. |
| hInstance | Handle to the instance of the module creating the window. |
| lpParam | Pointer to window-creation data. |
Return value
If the function succeeds, the return value is a handle to the new window. If it fails, the return value is NULL. Call GetLastError for more information.
Remarks
Show tips
- Use
WS_OVERLAPPEDWINDOWfor a typical top-level window. - Extended styles such as
WS_EX_TOPMOSTaffect Z-order. - Pass a pointer to a
CREATESTRUCTvialpParamto provide additional creation data.
Example
#include <windows.h>
LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
case WM_DESTROY: PostQuitMessage(0); return 0;
}
return DefWindowProc(hWnd, msg, wParam, lParam);
}
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmdLine, int nShowCmd)
{
const wchar_t CLASS_NAME[] = L"SampleWindowClass";
WNDCLASS wc = {0};
wc.lpfnWndProc = WndProc;
wc.hInstance = hInst;
wc.lpszClassName = CLASS_NAME;
RegisterClass(&wc);
HWND hWnd = CreateWindowEx(
0,
CLASS_NAME,
L"CreateWindowEx Demo",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, 500, 400,
NULL, NULL, hInst, NULL);
if (hWnd == NULL) return 0;
ShowWindow(hWnd, nShowCmd);
UpdateWindow(hWnd);
MSG msg = {0};
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return (int)msg.wParam;
}