Date: | October 11, 2004 / year-entry #363 |
Tags: | history |
Orig Link: | https://blogs.msdn.microsoft.com/oldnewthing/20041011-00/?p=37603 |
Comments: | 8 |
Summary: | The RegisterClass and RegisterClassEx functions return an ATOM. What is that ATOM good for? The names of all registered window classes is kept in an atom table internal to USER32. The value returned by the class registration functions is that atom. You can also retrieve the atom for a window class by asking a window... |
The The names of all registered window classes is kept in an atom table internal to USER32. The value returned by the class registration functions is that atom. You can also retrieve the atom for a window class by asking a window of that class for its class atom via The atom can be converted to an integer atom via the To convert a class name to a class atom, you can create a dummy window of that class and then do the aforementioned But what good is the atom? Not much, really. Sure, it saves you from having to pass a string to functions like I guess you could use it to check quickly whether a window belongs to a particular class. You get the atom for that class (via In other words, window class atoms are an anachronism. Like replacement dialog box classes, it's one of those generalities of the Win32 API that never really got off the ground, but which must be carried forward for backwards compatibility. But at least now you know what they are. [Typos fixed October 12.] |
Comments (8)
Comments are closed. |
Yeah, I was wondering the same thing about casting to BOOL yesterday. The dialog procedure is supposed to handle some messages by casting the return value to BOOL instead of using DWL_MSGRESULT (WM_CTLCOLORBTN, WM_CTLCOLORSTATIC, etc, probably others). How does that translate to 64 bit? Is BOOL 64 bit, or is HBRUSH 32 bit on a 64 bit system?
http://weblogs.asp.net/oldnewthing/archive/2004/01/15/58973.aspx#59082
GetClassInfoEx is useful for superclassing.
Right, but why would you superclass a class that you yourself registered? Wouldn’t you just fix your original class? I can see superclassing somebody else’s class, but in that case you don’t have their atom since you didn’t call RegisterClass originally.
I’m using the ATOM as a handle when writing my win32 wrapper classes. Saves having to deal with string allocation, especially since the names were auto generated anyway.
But why can’t I patch a window class without creating an actual window instance?
This feels kinda strange since I can get a handle (i.e. the ATOM) and even retreive it’s data (GetClassInfoEx) without having a window around. Not to mention that I have to create a dummy window to subclass standard controls.
I use it for a similar reason to doynax. If you’re making a C++ wrapper for a window class and want to delete the wrapper as part of the destructor, you have to keep around either the name of the class or the atom returned by RegisterClassEx. Although I didn’t know about the legacy reasons for atoms — that might lead me to store it as a string instead.
I find it terribly helpful/useful to use the GCW_ATOM to determine the window class during the WM_NOTIFY processing of my C appication. Prior to using GCW_ATOM we used a strcmp loop through all the currently supported window classes we’ve implemented. The overhead of 30 or more strcmp and a strcpy seems much worse that a loop comparing 30 ATOMS.