windows_programming_notes.nbk: Home | Index | Next Page: CreateWindowEx | Previous Page: CreateThread


 CreateWindow

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.

Syntax

    HWND CreateWindow(          
        LPCTSTR   lpClassName,
        LPCTSTR   lpWindowName,
        DWORD     dwStyle,
        int       x,
        int       y,
        int       nWidth,
        int       nHeight,
        HWND      hWndParent,
        HMENU     hMenu,
        HINSTANCE hInstance,
        LPVOID    lpParam
    );

Parameters

Return Value

If the function succeeds, the return value is a handle to the new window.

If the function fails, the return value is NULL. To get extended error information, call GetLastError.

This function typically fails for one of the following reasons:

Remarks

Before returning, CreateWindow sends a WM_CREATE message to the window procedure. For overlapped, pop-up, and child windows, CreateWindow sends WM_CREATE, WM_GETMINMAXINFO, and WM_NCCREATE messages to the window. The lParam parameter of the WM_CREATE message contains a pointer to a CREATESTRUCT structure. If the WS_VISIBLE style is specified, CreateWindow sends the window all the messages required to activate and show the window.

If the created window is a child window, its default position is at the bottom of the Z-order. If the created window is a top-level window, its default position is at the top of the Z-order (but beneath all topmost windows unless the created window is itself topmost).

For information on controlling whether the Taskbar displays a button for the created window, see Managing Taskbar Buttons.

The following predefined system classes can be specified in the lpClassName parameter. Note the corresponding control styles you can use in the dwStyle parameter.

For a table of the rich edit control styles you can specify in the dwStyle parameter, see [Rich Edit Control Styles].

Note If you specify Microsoft Windows version 4.x or later when linking your application, its windows cannot have caption buttons unless they also have window menus. This is not a requirement if you specify Windows version 3.x when linking your application.

Function Information


windows_programming_notes.nbk: Home | Index | Next Page: CreateWindowEx | Previous Page: CreateThread


Notebook exported on Monday, 7 July 2008, 18:56:50 PM Eastern Daylight Time