7 out of 8 rated this helpful - Rate this topic

WM_CREATE message

Applies to: desktop apps only

Sent when an application requests that a window be created by calling the CreateWindowEx or CreateWindow function. (The message is sent before the function returns.) The window procedure of the new window receives this message after the window is created, but before the window becomes visible.

A window receives this message through its WindowProc function.

#define WM_CREATE                       0x0001

Parameters

wParam

This parameter is not used.

lParam

A pointer to a CREATESTRUCT structure that contains information about the window being created.

Return value

Type: LRESULT

If an application processes this message, it should return zero to continue creation of the window. If the application returns –1, the window is destroyed and the CreateWindowEx or CreateWindow function returns a NULL handle.

Requirements

Minimum supported client

Windows 2000 Professional

Minimum supported server

Windows 2000 Server

Header

Winuser.h (include Windows.h)

See also

Reference
CreateWindow
CreateWindowEx
CREATESTRUCT
WM_NCCREATE
Conceptual
Windows

 

 

Send comments about this topic to Microsoft

Build date: 2/3/2012

Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
?? what happend to the "add community" editor??
?? what happend to the "add community" editor?? All linefeeds are removed and the markup functions are gone to indicate code...
not possible to create windows anymore if a window fails WM_CREATE with -1 and then PostQuitMessage
If the WM_CREATE of your window fails with -1 and then does a PostQuitMessage from its WM_DESTROY then it is impossible anymore to create any other window like for instance a MessageBox. This has been tested on W2K, XP and Win7 Why? dunno. You need to keep an indicator not to call PostQuitMessage if your WM_CREATE fails. Example to demostrate this. Like this code is the messagebox does not get displayed and returns immediately with IDOK. If you remove the PostQuitMessage the messagebox gets displayed --- LRESULT CALLBACK TestWndProc ( HWND in_hWnd, UINT in_uMsg, WPARAM in_wParam, LPARAM in_lParam ) { // which message? switch (in_uMsg) { // the test case: let it fail case WM_CREATE: return -1; // then post quit message case WM_DESTROY: PostQuitMessage(0); break; } // default processing return DefWindowProc(in_hWnd, in_uMsg, in_wParam, in_lParam); } VOID TestFailWnd(VOID) { /* locals */ HWND lv_hWnd; WNDCLASS lv_WndClass; // register the class memset(&lv_WndClass, 0, sizeof(WNDCLASS)); lv_WndClass.style = CS_DBLCLKS; lv_WndClass.lpfnWndProc = TestWndProc; lv_WndClass.hInstance = GetModuleHandle(0); lv_WndClass.hIcon = LoadIcon(0, IDI_APPLICATION); lv_WndClass.hCursor = LoadCursor(NULL, IDC_ARROW); lv_WndClass.lpszClassName = TEXT("CLASSXX"); RegisterClass(&lv_WndClass); // create window lv_hWnd = CreateWindowEx( 0, TEXT("CLASSXX"), "ABC", WS_MINIMIZEBOX | WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN | WS_CAPTION, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, GetModuleHandle(0), NULL); // result is NULL printf("lv_hWnd=%08X\n", lv_hWnd); // this is the problem: the messagebox will not get displayed because of the // WM_CREATE failed with -1 and the PostQuitMessage in WM_DESTROY MessageBox(0,"ABC","ABC",0); // halt the app printf("DONE\n"); getchar(); } void main(void) { TestFailWnd(); }
The order of received messages
Although the WM_CREATE message is sent before CreateWindow or CreateWindowEx returns, it might not be the first message that is received by the window procedure. On my machine, for instance, I received a WM_GETMINMAXINFO message, a WM_NCCREATE message, and a WM_NCCALCSIZE message before receiving the WM_CREATE message.
hint

If you are using the macro HANDLE_MSG defined in windowsx.h, your code to process the message must not return 0 to continue creation of the window. This is because the macro change the return value. 0 into -1 and any other value into 0.

Value
WM_CREATE = &H1