RegisterClass

2.x

  ATOM RegisterClass(lpwc)    
  const WNDCLASS FAR* lpwc; /* address of structure with class data */

The RegisterClass function registers a window class for subsequent use in calls to the CreateWindow or CreateWindowEx function.

Parameters

lpwc

Points to a WNDCLASS structure. The structure must be filled with the appropriate class attributes before being passed to the function. The WNDCLASS structure has the following form:

typedef struct tagWNDCLASS {    /* wc */
    UINT      style;
    WNDPROC   lpfnWndProc;
    int       cbClsExtra;
    int       cbWndExtra;
    HINSTANCE hInstance;
    HICON     hIcon;
    HCURSOR   hCursor;
    HBRUSH    hbrBackground;
    LPCSTR    lpszMenuName;
    LPCSTR    lpszClassName;
} WNDCLASS;

For a full description of this structure, see the Microsoft Windows Programmer's Reference, Volume 3.

Return Value

The return value is an atom that uniquely identifies the class being registered. For Windows versions 3.0 and earlier, the return value is nonzero if the function is successful or zero if an error occurs.

Comments

An application cannot register a global class if either a global class or a task-specific class already exists with the given name.

An application can register a task-specific class with the same name as a global class. The task-specific class overrides the global class for the current task only. A task cannot register two local classes with the same name. However, two different tasks can register task-specific classes using the same name.

Example

The following example registers a window class, then creates a window of that class:

WNDCLASS wc;
HINSTANCE hinst;
char szMyClass[] = "MyClass";
HWND hwndMyWindow;

/* Register the window class. */

wc.style         = 0;
wc.lpfnWndProc   = MyWndProc;
wc.cbClsExtra    = 0;
wc.cbWndExtra    = 0;
wc.hInstance     = hinst;
wc.hIcon         = LoadIcon(hinst, "MyIcon");
wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1);
wc.lpszMenuName  = (LPCSTR) NULL;
wc.lpszClassName = szMyClass;



if (!RegisterClass(&wc))
    return FALSE;

/* Create the window. */

hwndMyWindow = CreateWindow(szMyClass, "MyApp",
    WS_OVERLAPPED | WS_SYSMENU, CW_USEDEFAULT, 0,
    CW_USEDEFAULT, 0, NULL, NULL,
    hinst, NULL );

See Also

CreateWindow, CreateWindowEx, GetClassInfo, GetClassName, UnregisterClass, WindowProc