Click here to Skip to main content
13,050,429 members (81,758 online)
Rate this:
Please Sign up or sign in to vote.

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 12-Feb-13 18:59pm
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.
Pranit Kothari 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.
Pranit Kothari 13-Feb-13 1:29am
Alas! not able to get answer on simple looking question.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

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.
SoMad 13-Feb-13 3:56am
:thumbsup: Welcome back :).

Soren Madsen
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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
Pranit Kothari 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]
Pranit Kothari 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)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.170713.1 | Last Updated 13 Feb 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100