Click here to Skip to main content
15,884,629 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
Hi,

RegisterClass() or RegisterClassEx() are function to register Window Class, but why to register a window. I just wanted to know two things here, 'Register' and 'class' and what is its significance.

Answer is given but I am still confused, because it suggests just to accept it as it is.[^]

Thanks in advance
Posted
Comments
Sergey Alexandrovich Kryukov 13-Feb-13 1:04am    
Instead of answers, just read Microsoft documentation on related API; everything is clearly explained.
You don't explain why are you confusing, so there is nothing to answer about. It is registered because Windows is designed this way.
—SA
[no name] 13-Feb-13 1:06am    
Superficially I convince with answer and I am doing programming by registering windows many times, but still need to know what it internally does.
[no name] 13-Feb-13 1:29am    
Alas! not able to get answer on simple looking question.

When you register a window class, you associate it's _properties and behaviour_ with its class name. I.e it's font, colour, background and response to WM_ messages.

This then allows you to create a window of a particular type simply by referring to it by name. With the exception of 1/2 a dozen pre-defined windows classes (which may be reffered to with a number), this is the way that ms windows works.

By registering a class, you can re-use the behaviour and appearance of a particular control (or window, to continue with the terminology used here) for many different things within the same program.

You may have a bitmap-button class, that fades the image from colour to black and white in 50 steps. If you then want to use this type of button again, you either (a) re-write (copy/paste) it's code and change the images it references, finally setting the window proc of a new window to be the one that fades the image or (b) create a window procedure that will accept new images via a message sent to it, before registering the new window class.

Ms Windows then takes care of creating copies of the code used to control this type of window each time you create an instance of it. This means you can have 100 instances of the bitmap-button, each with different images - yet you only need to maintain storage for a single one inside the window-procedure that is associated with the window when you register it.
 
Share this answer
 
Comments
SoMad 13-Feb-13 3:56am    
:thumbsup: Welcome back :).

Soren Madsen
because you are creating a custom window and hence you need to register a class.

you do not need to register a class if using default windows such as Dialog, etc
 
Share this answer
 
Comments
[no name] 13-Feb-13 1:27am    
And what registering does? I know what you said. I am digging for details.
enhzflep 13-Feb-13 1:40am    
Text re-posted as an answer [enhzflep]
[no name] 13-Feb-13 1:42am    
Hey thanks enhzflep, why you cannot post it as answer. This is what I am exactly looking for.
enhzflep 13-Feb-13 1:43am    
Okay, no problem. Will do.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900