What is the HINSTANCE passed to CreateWindow and RegisterClass used for?
来源:互联网 发布:ubuntu jdk gz 安装 编辑:程序博客网 时间:2024/06/06 07:20
原文链接:
https://blogs.msdn.microsoft.com/oldnewthing/20050418-59/?p=35873
One of the less-understood parameters to the CreateWindow
function and the RegisterClass
function is the HINSTANCE
(either passed as a parameter or as part of the WNDCLASS
structure).
The window class name is not sufficient to identify the class uniquely. Each process has its own window class list, and each entry in the window class list consists of an instance handle and a class name. For example, here’s what the window class list might look like if a program has two DLLs, both of which register a class name “MyClass”, passing the DLL’s handle as the HINSTANCE
.
When it comes time to create a window, each module then passes its own HINSTANCE
when creating the window, and the window manager uses the combination of the instance handle and the class name to look up the class.
CreateWindow("MyClass", ..., hinstA, ...); // creates class 6CreateWindow("MyClass", ..., hinstB, ...); // creates class 7CreateWindow("MyClass", ..., hinstC, ...); // fails
This is why it is okay if multiple DLLs all register a class called “MyClass”; the instance handle is used to tell them apart.
There is an exception to the above rule, however. If you pass the CS_GLOBALCLASS
flag when registering the class, then the window manager will ignore the instance handle when looking for your class. All of the USER32 classes are registered as global. Consequently, all of the following calls create the USER32 edit control:
CreateWindow("edit", ..., hinstA, ...);CreateWindow("edit", ..., hinstB, ...);CreateWindow("edit", ..., hinstC, ...);
If you are registering a class for other modules to use in dialog boxes, you need to register asCS_GLOBALCLASS
, because as we saw earlier the internal CreateWindow
call performed during dialog box creation to create the controls passes the dialog’s HINSTANCE
as the HINSTANCE
parameter. Since the dialog instance handle is typically the DLL that is creating the dialog (since that same HINSTANCE
is used to look up the template), failing to register with the CS_GLOBALCLASS
flag means that the window class lookup will not find the class since it’s registered under the instance handle of the DLL that provided the class, not the one that is using it.
In 16-bit Windows, the instance handle did other things, too, but they are no longer relevant to Win32.
A common mistake is to pass the HINSTANCE
of some other module (typically, the primary executable) when registering a window class. Now that you understand what the HINSTANCE
is used for, you should be able to explain the consequences of registering a class with the wrong HINSTANCE
.
- What is the HINSTANCE passed to CreateWindow and RegisterClass used for?
- What is and how to calculate 'cumulative gas used'?
- 传递给 CreateWindow 和 RegisterClass 的 HINSTANCE 有什么用?
- what is DECODE function used for?
- 【html】What is href=“#” and why is it used?
- What is Observer and Observable and when we used these?
- This program is used to explain how PCA works and the idea behind the method.
- Cisco IOS: What Is VLAN 1002 – 1005 Used for ?
- what is AttributeOverride annotation used for in Hibernate
- The report is used to find enhancement and badi in sap.
- Failed to connect to Xilinx hw_server. Check if the hw_server is running and correct TCP port is used.
- Failed to connect to Xilinx hw_server. Check if the hw_server is running and correct TCP port is used.
- What is svchost.exe And Why Is It Running? :: the How-To Geek
- What is the best way to implement a heartbeat in C++ to check for socket connectivity?
- What the hell is mon and mun?
- What is the difference between test, [ and [[ ?
- What is the copy-and-swap idiom?
- What is the copy-and-swap idiom?
- 使用 matlab 数字图像处理(一)—— 归一化直方图
- 射线及其碰撞检测 [代码清单6-7]
- Android开源之BaseRecyclerViewAdapterHelper(持续更新!)
- 第七周总结及Boostrap框架demo
- angularstrap typeahead 处理异步数据
- What is the HINSTANCE passed to CreateWindow and RegisterClass used for?
- 线程与进程
- 怎样使用nat和桥接方式解决虚拟机联网问题(一)
- 安装eclipse的JRebel6.0.3的插件
- spring框架整合ibatis的项目实例代码
- iOS调用系统闪光灯以及实时修改屏幕亮度
- IOS摇晃处理流程
- VBA批量调整图片宽度
- 工厂方法模式