关于RegisterClass的注册位置

来源:互联网 发布:电商美工设计 编辑:程序博客网 时间:2024/05/01 16:50

昨天在smth,有人问起RegisterClass函数到底将窗口类注册到哪里了,想了一下,应该是一个系统级的存储空间里,但是却没有一个明确的说法,msdn上看了半天,基本上没有提到具体注册的位置。倒是返回值给了不少提示,ATOM,查ATOM终于找到如下的一段描述

中文翻译:

该系统提供了一个原子表的数量。每个原子表提供不同的目的。例如,动态数据交换(DDE)应用程序使用全局原子表与其他应用共享的项目名称和主题名称字符串。而不是通过实际的字符串,一个DDE应用程序传递全局原子,其合作伙伴应用程序。合作伙伴使用的原子,从原子表获得的字符串。应用程序可以使用本地原子表来存储自己的项目名称协会。该系统使用的应用程序不能直接访问的原子表。然而,应用程序使用这些原子时调用各种功能。例如,注册剪贴板格式存储在原子内部系统所使用的表。应用程序中添加原子原子表使用RegisterClipboardFormat函数。此外,注册类存储在原子内部系统所使用的表。应用程序中添加原子原子表使用RegisterClass或RegisterClassEx函数。

原文:

 The system provides a number of atom tables. Each atom table serves a different purpose. For example, dynamic data exchange (DDE) applications use the global atom table to share item-name and topic-name strings with other applications. Rather than passing actual strings, a DDE application passes global atoms to its partner application. The partner uses the atoms to obtain the strings from the atom table.

Applications can use local atom tables to store their own item-name associations.

The system uses atom tables that are not directly accessible to applications. However, the application uses these atoms when calling a variety of functions. For example, registered clipboard formats are stored in an internal atom table used by the system. An application adds atoms to this atom table using the RegisterClipboardFormat function. Also, registered classes are stored in an internal atom table used by the system. An application adds atoms to this atom table using the RegisterClass or RegisterClassEx function.


也就是说应该在一个原子表中,于是google之,终于找到一片像样的文章。转贴如下:

中文翻译:

registerClass返回原子有什么用?

通过registerClass和RegisterClassEx函数返回一个原子。什么是原子?所有注册窗口类的名字被保存在一个原子表的内部,以USER32。由类注册函数的返回值是原子。您还可以检索一个窗口类,该类的窗口通过GetClassWord(HWND,GCW_ATOM)要求其类原子的原子。原子可以转换为整数的原子通过的MAKEINTATOM的宏,然后就可以使用函数接受字符串或原子的形式中的类名。最常见的情况是lpClassName参数CreateWindow的宏观和CreateWindowEx函数。不太常用,你也可以作为的lpClassName的getClassInfo并GetClassInfoEx功能参数使用。 (虽然你为什么会做到这一点我无法弄清楚。为了使原子传递到摆在首位GetClassInfo,你必须注册类(因为那是什么返回原子),在这种情况下,为什么你要求有关类的信息,你注册了吗?)转换类原子的类的名称,你可以创建一个该类的虚拟窗口,然后做上述GetClassWord(HWND,GCW_ATOM)的。或者您可以采取的事实,从GetClassInfoEx函数的返回值是原子类,转换为一个BOOL的优势。这可以让你做转换,而无需创建一个虚拟的窗口。 (请注意,然而,GetClassInfoEx的返回值是不是原子在Windows 95的派生操作系统。)但是,什么是原子?不多,真的。当然,它可以节省你不必像CreateWindow的函数传递一个字符串,但它确实是替换字符串与一个整数,你现在有一个全局变量中保存供以后使用。什么是一个字符串,你可以硬编码现在是一个原子,你必须跟踪。目前还不清楚,你实际上有赢得什么。我想你可以用它快速检查一个窗口是否属于一个特定的类。你得到这个类的原子(通过GetClassInfo,说),然后得到窗口的原子,并加以比较。但你不能缓存类的原子,因为类可能会得到未注册和重新注册(这将给它一个新的原子数)。你不能预取类原子,因为类可能尚未被登记在你预取点。 (如上所述,你可以不缓存预取的价值了。),所以这种情况是相当多的非起动无论如何,你可能也使用GetClassName函数和比较你要找的类生成的类名为。换句话说,窗口类的原子是不合时宜的。替换对话框类一样,这是一个Win32 API的那些泛泛从未真正得到掉在地上,但必须进行向前向后兼容性。但至少现在,你知道它们是什么。

原文:

What's the atom returned by RegisterClass useful for?

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 of that class for its class atom via GetClassWord(hwnd, GCW_ATOM).

The atom can be converted to an integer atom via the MAKEINTATOM macro, which then can be used by functions that accept class names in the form of strings or atoms. The most common case is the lpClassName parameter to the CreateWindow macro and the CreateWindowEx function. Less commonly, you can also use it as the lpClassName parameter for the GetClassInfo and GetClassInfoEx functions. (Though why you would do this I can't figure out. In order to have the atom to pass to GetClassInfo in the first place, you must have registered the class (since that's what returns the atom), in which case why are you asking for information about a class that you registered?)

To convert a class name to a class atom, you can create a dummy window of that class and then do the aforementioned GetClassWord(hwnd, GCW_ATOM). Or you can take advantage of the fact that the return value from the GetClassInfoEx function is the atom for the class, cast to a BOOL. This lets you do the conversion without having to create a dummy window. (Beware, however, that GetClassInfoEx's return value is not the atom on Windows 95-derived operating systems.)

But what good is the atom?

Not much, really. Sure, it saves you from having to pass a string to functions like CreateWindow, but all it did was replace a string with with an integer you now have to save in a global variable for later use. What used to be a string that you could hard-code is now an atom that you have to keep track of. Unclear that you actually won anything there.

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 GetClassInfo, say) and then get the atom for the window and compare them. But you can't cache the class atom since the class might get unregistered and then re-registered (which will give it a new atom number). And you can't prefetch the class atom since the class may not yet be registered at the point you prefetch it. (And as noted above, you can't cache the prefetched value anyway.) So this case is pretty much a non-starter anyway; you may as well use the GetClassName function and compare the resulting class name against the class you're looking for.

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.

最终的结论,RegisterClass应该是将窗口类的数据放在User32.dll维护的一个原子表中了:)

 

本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/Hamxj/archive/2007/05/09/1601758.aspx