`
testcs_dn
  • 浏览: 103708 次
  • 性别: Icon_minigender_1
  • 来自: 北京
文章分类
社区版块
存档分类
最新评论

关于RegisterClass的注册位置

 
阅读更多

昨天在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

分享到:
评论

相关推荐

    C++Builder函数库

    RegisterClass 过程 注册一个从TPersistent继承的类,使她的类的类型能够被识别。 RegisterClassAlias 过程 注册一个和另一个除了名字外都相同的类。 RegisterClasses 过程 注册一组类 RegisterComponents 过程 ...

    c++builder6 常用函数

    RegisterClass 过程 注册一个从TPersistent继承的类,使她的类的类型能够被识别。 RegisterClassAlias 过程 注册一个和另一个除了名字外都相同的类。 RegisterClasses 过程 注册一组类 RegisterComponents 过程 ...

    从CWnd自绘第一课之按钮 续

    CWnd直接自绘各种控件,这是第一个案例,针对按钮这种控件作简单的实现。 其他控件如法炮制,完成鼠标响应和发送消息即完成控件制作,这一次变成动画图片

    java 实现成员方法的ajax自动注册类

    ajax.registerClass(JavaBeanClassName); ajax.processRequests(); ajax.getJavascript();//获取head嵌入head中的javascript语句 在JavaBean中以on开始的方法中,返回处理结果调用如下: class testAjax{ ...

    SCAutoResizeCellDemo:在 tableview 上使用自动布局

    使用tableview的registerClass方法来进行cell的注册b. 若有多种类型的cell,则要用registerClass注册多个cell####3、初始化cell,并返回cell高度a. 在heightForRowAtIndexPath方法里,进行cell的初始化b. 使用...

    asp.net AJAX注册类

    就是将wallis加入window中,然后就可以直接在任何地方使用该命名空间(window是全局的,而且使用时可以省略) 2、注册类 wallis.Animal.registerClass(“wallis.Animal”); 在MicrosoftAjax.js中可以找到 Type....

    iOS安全之拦截http请求 ( 为小白用户定制的精简版本)

    HTTP 请求开始时,URL 加载系统创建一个合适的 NSURLProtocol 对象处理对应的 URL 请求,因此我们只需写一个继承自 NSURLProtocol 的类,并通过 - registerClass: 方法注册我们的协议类,然后 URL 加载系统就会在...

    Frank D. Luna龙书第二版第7章习题1答案

    Introduction to 3D Game Programming with DirectX 9.0c —— A Shader Approach第7章习题1的答案,只给了源码,使用方式参见ReadMe.txt文件。

    PHP模拟测试框架AspectMock.zip

    AspectMock 不是一个普通的 PHP 模拟测试框架,通过强大的 AOP 面向方面编程理念和神奇的 Go-AOP 库, AspectMock 可以让你在 PHP 代码中进行任意的模拟测试。 示例代码: <?...function testUserCreate() ...

    利用MS AJAX注册Javascript命名空间并创建类

    Demo.Person.registerClass(‘Demo.sample ‘, null, Sys.IDisposable); 下面是一个具体的实例: Namespace.js Type.registerNamespace(“Demo”); Demo.Person = function(firstName, lastName, email...

    ios-CPBinnerView.zip

    [_binnerView registerClass:[CPBinnerCell class] forCellWithReuseIdentifier:@"cell"]; // 你也可以使用nib注册cell [_binnerView registerNib:[UINib nibWithNibName:@"BinnerCell2" bundle:nil] ...

    C语言创建windows窗口实例

    2.注册窗口类RegisterClass 3.创建窗口CreateWindow 4.显示窗口和更新窗口 代码如下: ShowWindow (hwnd, iCmdShow) ;  UpdateWindow (hwnd) ; 5.消息循环 代码如下: while (GetMessage (&msg, NULL, 0, 0))  { ...

    MFC源码剖析之——MFC来龙去脉

    码中检验出一个Windows 程序原本该有的程序进入点(WinMain)、视窗类别注册 (RegisterClass)、窗口产生(CreateWindow)、消息循环(Message Loop)、窗口函数 (WindowProcedure)等等动作,抽丝剥茧彻底了解一...

    用API编写简单的Windows程序

    注册窗口类,即RegisterClass(…) 函数的使用 C.创建窗口,即CreateWindow(…) 函数的使用 D.显示及更新窗口,即ShowWindow(…) 及UpdateWindow(…) 的使用 (4) 进行消息循环,用GetMessage(…) 取出消息,分别用...

    自己写的lua 封装 简单易用,需要示例的可以mail: xieaiwanli@hotmail.com

    RegisterLuaClass::RegisterClass(l); char current_dir[260] = {0}; DWORD ret = GetCurrentDirectory(260, current_dir); std::string strTmp(current_dir); std::stringstream strS; strS; //加载一个LUA...

    深入解析C++的WNDCLASS结构体及其在Windows中的应用

     RegisterClass()就是在系统注册某一类型的窗体。也就是将你提供的WNDCLASS数据注册为一个窗口类,在WNDCLASS.lpszClassName中定义该WNDCLASS的标识,无论CreateWindow或CreateWindowEx创建的窗口都必须对应一个...

    ios-瀑布流tableview可以扔了.zip

    //注册要复用的cell [test registerClass:[NSClassFromString(@"JayCollectionViewCell") class] forCellWithModel:[NSCollectionBaseModel class]]; //添加数据源 可以继承NSCollectionListModel、...

    iOS安全之【拦截请求,实现特定目的 】(修改HTTPHeaderField、不走全局proxy、设置代理IP和端口、对网络请求的数据进行报文级别的加密)

    2、应用场景: 2.1、 自定义请求头的HTTPHeaderField 2.2、针对...通过[NSURLProtocol registerClass: [NetworkInject class]];注入了自定义的NSURLProtocol类 3、原理:利用NSURLProtocol 拦截 HTTP 请求

    CppDiFactory:一个简单的C ++ 11单头依赖注入容器

    registerClass 每次需要一个实例时都创建一个新实例。 单身人士班 registerInstance 始终使用预定义的实例。 按需单人课程 registerSingleton 首次使用实例时创建一个实例,并为每个请求返回该实例。 一旦不再...

Global site tag (gtag.js) - Google Analytics