Sign in to follow this  
johnnyBravo

When creating a window, does it matter what I call the wndclass class name?

Recommended Posts

Hi, you know when you create a window, I was wondering if it matters what you call the class name. eg WNDCLASSEX wnd; wnd.lpszClassName = ""; Like could I just call it "", or "mainwindow", as long as there is only one class registered with that name? ....Right now I just name it the same as my current window's name, but I had to store that somewhere, and I'm just trying to minimalise my window class. Thanks

Share this post


Link to post
Share on other sites
yes it does matter, try to make it something unique, just something as simple as "MyOpenGLWindowClass" will probably do.
i can't quite remember why, if i remember in the morning i will try post the reason, just know that it is, infact important.

Share this post


Link to post
Share on other sites
Its because the classname is global - all applications get access to your window class (I could be wrong here, it might only be DLLs your app loads). You can specify "BUTTON" in CreateWindow() to create a button (oddly enough), and similarly for a load of other common controls. "" will probably fail because I expect that Windows checks the string isn't NULL or an empty string, but "mainwindow" should be ok. Although as silvermace said, try to go for something a little more unique.

I usually use the application name + "WindowClass", E.g. "DruinkIMWindowClass" or "TestRPGWindowClass".

Share this post


Link to post
Share on other sites
Your class name is global throughout all of Windows. A lot of libraries (such as the common controls) use window classes to indentify their components. Many programs use window classes to help determine where to route messages.

Unique is good. If you accidentally use a window class that another program uses, it might start sending you weird gibberish messages and other data. Believe me, that's one of the most incredibly difficult things to debug you'll ever come up against.

Share this post


Link to post
Share on other sites
Are you positive it is actually truely global and not application or process global?

The MSDN docs suggest that:

Quote:

A window class is a set of attributes that the system uses as a template to create a window. Every window is a member of a window class. All window classes are process specific.


But then, it gives me a headache sometimes even trying to decypher the contradictory content in parts of the MS docs ;)

Share this post


Link to post
Share on other sites
It is process global by default, but there is a flag somewhere that makes it windows-global. You want to try something likely to be unique because if you use ButtonX for example, a component library might also register a window class of ButtonX globally and (iirc) the register class function would fail with 'already registered' or something like that on systems where that other component library is installed.
With good logging it wouldn't be hard to find, but most people seem to forgo the logging of windows error info which makes such problems a pain =-)

Share this post


Link to post
Share on other sites
It was more rhetorical than an actual question, I couldn't care less. I guess the answer to the OP is 'no it doesn't matter, Windows won't let you register two classes with the same name - check your return values!'.

Share this post


Link to post
Share on other sites
And to make things more interesting, if you don't check the return value of RegisterWindowClass[Ex], and assume it worked, then when you crate your window, it'll use the information from the other window class, including the address of the message handler. Which means your window message handler won't ever be called...

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this