Home

CreateWindow

CreateWindow is a Win32 API function in the User32 library that creates a window and returns a handle to it (HWND). It requires a previously registered window class and is commonly used to instantiate top-level and child windows in a Windows desktop application.

The function signature takes parameters that specify the window class, window title, style flags, position, size,

On success, the function returns a valid HWND. If it fails, it returns NULL and the error

A window procedure associated with the registered class handles messages for the window. The lpParam value

Notes: Use CreateWindowEx when you need extended styles or to be explicit about Unicode or ANSI variants.

Example:

HWND hwnd = CreateWindow("MyClass", "My Window", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 800, 600, NULL, NULL, hInstance, NULL);

ShowWindow(hwnd, SW_SHOW);

UpdateWindow(hwnd);

parent
window,
menu
handle,
application
instance,
and
an
optional
pointer
that
is
passed
to
the
window
procedure.
CreateWindow
is
equivalent
to
calling
CreateWindowEx
with
dwExStyle
set
to
0.
code
can
be
retrieved
with
GetLastError.
The
created
window
is
not
shown
by
default;
developers
typically
call
ShowWindow
and
UpdateWindow
after
creation.
is
accessible
to
the
WM_CREATE
message
via
CREATESTRUCT,
and
can
be
used
to
pass
initialization
data
to
the
window.
Ensure
the
window
class
is
registered,
and
use
the
proper
instance
handle
(hInstance).
For
Unicode
builds,
prefer
CreateWindowW
with
a
wide-class
name.