CWnd::OnCreate

Syntax

afx_msg int OnCreate( LPCREATESTRUCT lpCreateStruct );

Parameters

lpCreateStruct

Points to a CREATESTRUCT structure containing information about the CWnd object being created.

Remarks

Called when an application requests that the CWnd object be created by calling the Create or CreateEx member function. The new CWnd object receives this call after the CWnd object is created but before it becomes visible. OnCreate is called before the Create or CreateEx member function returns.

Override this member function to perform any needed initialization of a derived class.

The CREATESTRUCT structure contains copies of the parameters used to create the window.

A CREATESTRUCT structure has the following form:

typedef struct tagCREATESTRUCT {

LPSTR lpCreateParams;

HANDLE hInstance;

HANDLE hMenu;

HWND hwndParent;

int cy;

int cx;

int y;

int x;

LONG style;

LPSTR lpszName;

LPSTR lpszClass;

DWORD dwExStyle;

} CREATESTRUCT;

Members

lpCreateParams

Points to data to be used for creating the window.

hInstance

Identifies the module-instance handle of the module that owns the new window.

hMenu

Identifies the menu to be used by the new window. If a child window, contains the integer ID.

hwndParent

Identifies the window that owns the new window. This member is NULL if the new window is a top-level window.

cy

Specifies the height of the new window.

cx

Specifies the width of the new window.

y

Specifies the y-coordinate of the upper-left corner of the new window. Coordinates are relative to the parent window if the new window is a child window. Otherwise, the coordinates are relative to the screen origin.

x

Specifies the x-coordinate of the upper-left corner of the new window. Coordinates are relative to the parent window if the new window is a child window. Otherwise, the coordinates are relative to the screen origin.

style

Specifies the new window's style.

lpszName

Points to a null-terminated string that specifies the new window's name.

lpszClass

Points to a null-terminated string that specifies the new window's Windows class name (a WNDCLASS struct).

dwExStyle

Specifies the extended style for the new window.

This message-handler member function calls the Default member function. Override this member function in your derived class to handle the WM_CREATE message.

Return Value

OnCreate must return 0 to continue the creation of the CWnd object. If the application returns -1, the CWnd will be destroyed.

See Also

CWnd::CreateEx, CWnd::OnNcCreate, WM_CREATE, CWnd::Default, CWnd::FromHandle