我如何知道它是有效的 gdi 区域句柄?
或其他 GDI 句柄,例如笔刷。我怎么知道它是否有效?
or other gdi handle, such as pen brush. how do i know is it valid?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
或其他 GDI 句柄,例如笔刷。我怎么知道它是否有效?
or other gdi handle, such as pen brush. how do i know is it valid?
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(3)
您永远不应该让自己陷入可能持有无效句柄的情况。如有必要,请在调用DeleteObject()后将句柄设置为NULL,这样就完全显而易见了。假设 GDI 函数会因为传递了错误句柄而给您 FALSE 返回值,这是不安全的。
You should never get yourself into a situation where you might be holding onto a handle that isn't valid. If necessary, set the handle to NULL after calling DeleteObject() so it is completely obvious. Assuming that a GDI function will give you a FALSE return value because you passed a bad handle isn't safe.
答案是:你从哪里得到句柄?
简单来说,就像艺术品一样:你怎么知道它是真的,而不是赝品?
有一些“启发式方法”,但唯一 100% 有效的方法是知道它来自哪里。
因此,关于 GDI 区域:您应该只信任 GDI 函数返回的那些区域句柄。
:)
The answer is: where did you get the handle from?
Simply speaking, it's like with the art: how do you know it's authentic, not a fake?
There're some "heuristics", but the only 100%-working way is to know where is it from.
So, regarding the GDI regions: you should only trust those region handles that are returned by GDI functions.
:)
尝试
GetObject()
或GetObjectType()
。如果对象句柄无效,它们应该返回 NULL。我可以看到您想在哪里使用它进行调试。在完美的世界中,我们可以跟踪我们的物体并随时知道它们在哪里。
我们的世界并不完美。
Try
GetObject()
orGetObjectType()
. They should return NULL if the object handle is invalid.I can see where you'd want to use this for debugging. In a perfect world, we keep track of our objects and know where they are at all times.
Ours is not a perfect world.