Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the purpose of registering window classes?

Tags:

windows

winapi

What's the purpose of registering a window class via WNDCLASSEX and RegisterClassEx() when creating a window in a Windows API application?

like image 263
Vishnu Pedireddi Avatar asked Dec 14 '11 19:12

Vishnu Pedireddi


2 Answers

The separation of window attributes into CreateWindow() stuff and RegisterClass() stuff was done early on to enable the creation of uniformly-behaving windows. Dialog controls (buttons, listboxes, etc.) are a prime example - they all share a class. That means - they share a window procedure, that means - they share painting logic, input reactions, custom messages, notifications, etc.

On the app level, the most typical case when you have many windows of the same class is documents within a multiple-document interface. Sometimes people introduce app-specific controls. So the distinction serves its purpose.

like image 151
Seva Alekseyev Avatar answered Nov 17 '22 21:11

Seva Alekseyev


Main purpose is giving the system the right WndProc to call when there is something in the message queue to process.

There are some flags, but main point is the above.

Window classes correspond to types of 'widgets' on the UI:

  • button
  • checkbox
  • scrollbar
  • combobox
  • listbox

WndProc is the sole driver of the behavior of the widget.

Hence the mapping: widget (control type) -> wndclass -> WndProc

like image 37
Daniel Mošmondor Avatar answered Nov 17 '22 20:11

Daniel Mošmondor