1.窗口类WNDCLASS和窗口实例CreateWindow
1.1 这两者怎么联系起来的?
使用WNDCLASS的最后一个成员lpszClassName和CreateWindow第一个参数classname联系起来,正如MSDN所说:
- Search the list of application local classes for a class with the specified name whose instance handle matches the module's instance handle. (Several modules can use the same name to register local classes in the same process.)
- If the name is not in the application local class list, search the list of application global classes.
- If the name is not in the application global class list, search the list of system classes.
1.2 窗口类的作用范围?全局,进程还是线程?
由style成员决定,如果wndClass.style = CS_GLOBALCLASS,则表示这个窗口类是全局的。如果希望在其他进程中使用:
load拥有这个窗口类的dll或者可执行性文件
CreateWindow(类名,.......,dll的句柄,......)
1.3 CreateWindow为什么需要hInstance参数
由 1.2 可知,当程序加载了多个dll的时候,是有可能出现类名冲突的,例如
HINSTANCE | Class name | |
---|---|---|
1. | USER32.DLL | Static |
2. | USER32.DLL | Button |
3. | USER32.DLL | Listbox |
4. | USER32.DLL | Combobox |
5. | USER32.DLL | Edit |
6. | A.DLL | MyClass |
7. | B.DLL | MyClass |
A.dll和B.dll都注册了为MyClass的窗口类,因此,需要hInstance区别不同的dll来唯一指定窗口类。
博文http://blogs.msdn.com/b/oldnewthing/archive/2005/04/18/409205.aspx有详细解答