Windows API问题 [英] Issue with Windows API

查看:133
本文介绍了Windows API问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问候编码员,



我有与Windows API相关的问题,似乎很难寻求澄清。我希望这不是太多问题,因为这是我的第一次。我的问题与以下内容有关:



1. GetClassLong API。是否有必要:



*从GetClassLong(hwnd,GCL_HICON)或GetClassLong(hwnd,GCL_HSMICON)返回的hicon调用DestroyIcon



*从GetClassLong(hwnd,GCL_HCURSOR)返回的hcursor调用DestroyCursor



*调用从GetClassLong返回的hbrush的DeleteObject(hwnd,GCL_HBRBACKGROUND)



*如果函数调用者不这样做会引入内存泄漏还是狂放(未闭合)句柄?



2. GetClassInfoEx API



我发现WNDCLASSEX结构的lpfnwndProc成员返回与GetClassLong(hwnd,GCL_WNDPROC)返回的值不同的值。我对这个API感兴趣以获得更好的性能,而不是为每个字段调用GetClassLong我觉得最好使用它并拥有我需要的所有类信息。但是看到这个以及从非系统类获取信息的失败让我气馁。



3. EnumThreadWindows API



我在EnumThreadWindows中发现不一致,如果命令提示符窗口打开,EnumThreadWindows会发现该窗口属于在csrss.exe进程下运行的线程,但是EnumWindows或EnumChildWindows(将桌面hwnd作为hwndParent传递)没有这么说。 GetWindowThreadProcessId与EnumWindows和EnumChildWindows达成一致。这个事实可以在WinXP SP2上找到,对于拥有XP机器的人,请你验证一下你的系统是否也会出现这种情况。很清楚哪些API是正确的。



4. GetWindowInfo API



为什么WINDOWINFO结构的dwExStyle成员使用GetWindowLong(hwnd,GWL_EXSTYLE)返回的值获取不同的值。我看到值相差0x20000000,ex风格的未知值,我找不到具有此类值的ex风格的任何常量。

Greetings coders,

I have questions related to Windows API, that seems difficult to seek for clarification. I hope this isn't too much to ask, since this is my first. My questions are related to:

1. GetClassLong API. Is it necessary to:

*Call DestroyIcon for hicon returned from GetClassLong(hwnd, GCL_HICON) or GetClassLong(hwnd,GCL_HSMICON)

*Call DestroyCursor for hcursor returned from GetClassLong(hwnd, GCL_HCURSOR)

*Call DeleteObject for hbrush returned from GetClassLong(hwnd, GCL_HBRBACKGROUND)

*If function callers didn't do that would it introduce memory leak or wild (unclosed) handle?

2. GetClassInfoEx API

I found that the lpfnwndProc member of the WNDCLASSEX structure returns different value with value returned by GetClassLong(hwnd, GCL_WNDPROC). I'm interested in this API in a thought for better performance, instead of calling GetClassLong for each field I figure it'll be better off to use this and have all class info I need. But to see this and the failures obtaining info from non system classes discouraged me.

3. EnumThreadWindows API

I found inconsistency in EnumThreadWindows where if the command prompt window is open EnumThreadWindows find the window to belong to a thread running under the csrss.exe process, but EnumWindows or EnumChildWindows (passing desktop hwnd as hwndParent) didn't say so. GetWindowThreadProcessId agreed with EnumWindows & EnumChildWindows. This fact is found on WinXP SP2, for you who has XP machines could you please verify if this occurs in your system too. It would be nice to have clear info of which API is correct.

4. GetWindowInfo API

Why the dwExStyle member of WINDOWINFO structure gets a different value with the value returned by GetWindowLong(hwnd, GWL_EXSTYLE). I see the value differs by 0x20000000, an unknown value for ex style, I couldn't find any constant for ex style having such value.

推荐答案

1。不,返回的信息属于已注册的类,因此您不应该更改它,因为它可能会影响其他活动的Windows。

2.相同的评论。

3.这些功能有时会返回有关系统使用的不可见窗口的信息。

4.其中一些使用操作系统内部使用的额外未记录值。



最好的建议,除非你完全理解它们,否则不要使用任何这些功能。这并不容易,除非您注册MSDN开发人员计划,否则您所需的信息将无法使用。
1. No, the information returned belongs to the registered class so you should not change it, as it could affect other active Windows.
2. Same comment.
3. These functions sometimes return information about non-visible windows used by the system.
4. Some of these use extra undocumented values that are used internally by the OS.

Best advice, don't use any of these functions unless you fully understand them. And that is not easy as much of the information you need is not available unless you sign up to the MSDN developer program.


除了Richard已经讲过的关于第2点的信息:值由GetClassInfoEx和GetClassLong返回。

这些函数可以无差别地返回窗口过程的实际地址或句柄(原因在某种程度上与过程及其过程的内存映射有关)。句柄和地址之间的转换由函数 CallWindowProc() [ ^ ],这就是为什么你应该总是使用这个函数而不是直接调用返回的地址的原因。
In addition to what already told by Richard about the point 2: values returned by GetClassInfoEx and GetClassLong.
These functions can return indifferently a real address or an handle to the window procedure (the reason is someway related to memory mapping of the procedure and its process). The translation between handle and address is made by the function CallWindowProc()[^], and this is the reason why you should always use this function instead of calling directly the address returned.


这篇关于Windows API问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆