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

Started by
7 comments, last by Evil Steve 19 years, 4 months ago
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
Advertisement
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.
"I am a donut! Ask not how many tris/batch, but rather how many batches/frame!" -- Matthias Wloka & Richard Huddy, (GDC, DirectX 9 Performance)

http://www.silvermace.com/ -- My personal website
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".
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.

Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]

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 ;)
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 =-)
"Walk not the trodden path, for it has borne it's burden." -John, Flying Monk
Quote:Original post by JuNC
Are you positive it is actually truely global and not application or process global?
Types of Window Classes answers your question.
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!'.

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...

This topic is closed to new replies.

Advertisement