typedef struct _WNDCLASSEX {
UINT cbSize;
UINT style;
WNDPROC lpfnWndProc;
int cbClsExtra;
int cbWndExtra;
HINSTANCE hInstance;
HICON hIcon;
HCURSOR hCursor;
HBRUSH hbrBackground;
LPCSTR lpszMenuName;
LPCSTR lpszClassName;
HICON hIconSm;
} WNDCLASSEX, *PWNDCLASSEX;WNDCLASSEX Structure
The WNDCLASSEX structure contains information about a window class. It is used with the RegisterClassEx function to register a window class for subsequent use in creating windows.
Definition
Members
| Member | Type | Description |
|---|---|---|
cbSize | UINT | Size of this structure, in bytes. Must be set to sizeof(WNDCLASSEX). |
style | UINT | Class style(s) (e.g., CS_VREDRAW, CS_HREDRAW). |
lpfnWndProc | WNDPROC | Pointer to the window procedure for this class. |
cbClsExtra | int | Number of extra bytes to allocate following the class structure. |
cbWndExtra | int | Number of extra bytes to allocate following the window instance. |
hInstance | HINSTANCE | Handle to the instance that contains the window procedure. |
hIcon | HICON | Handle to the class icon. |
hCursor | HCURSOR | Handle to the class cursor. |
hbrBackground | HBRUSH | Handle to the class background brush. |
lpszMenuName | LPCSTR | Resource name of the class menu, or NULL. |
lpszClassName | LPCSTR | String or atom that uniquely identifies the window class. |
hIconSm | HICON | Handle to a small icon associated with the class. |
C++ Example
#include <windows.h>
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
switch (msg) {
case WM_DESTROY:
PostQuitMessage(0);
return 0;
default:
return DefWindowProc(hwnd, msg, wParam, lParam);
}
}
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmdLine, int nShowCmd) {
WNDCLASSEX wc = {0};
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInst;
wc.hIcon = LoadIcon(nullptr, IDI_APPLICATION);
wc.hCursor = LoadCursor(nullptr, IDC_ARROW);
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wc.lpszMenuName = nullptr;
wc.lpszClassName = "MyWindowClass";
wc.hIconSm = LoadIcon(nullptr, IDI_APPLICATION);
if (!RegisterClassEx(&wc)) {
MessageBox(nullptr, "Window Registration Failed!", "Error", MB_ICONERROR);
return 0;
}
HWND hwnd = CreateWindowEx(
0,
wc.lpszClassName,
"Sample Window",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, 640, 480,
nullptr, nullptr, hInst, nullptr);
if (!hwnd) {
MessageBox(nullptr, "Window Creation Failed!", "Error", MB_ICONERROR);
return 0;
}
ShowWindow(hwnd, nShowCmd);
UpdateWindow(hwnd);
MSG msg;
while (GetMessage(&msg, nullptr, 0, 0) > 0) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return (int)msg.wParam;
}
For more details, see the related pages: