简体   繁体   English

我怎么知道它是有效的gdi区域句柄?

[英]How do I know it's a valid gdi region handle?

or other gdi handle, such as pen brush. 或其他gdi手柄,例如笔刷。 how do i know is it valid? 我怎么知道这是有效的?

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. 如有必要,在调用DeleteObject()之后将句柄设置为NULL,这样就很明显了。 Assuming that a GDI function will give you a FALSE return value because you passed a bad handle isn't safe. 假设由于传递了错误的句柄,GDI函数将为您提供FALSE返回值是不安全的。

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. 因此,关于GDI区域:您应该只信任GDI函数返回的那些区域句柄。

:) :)

Try GetObject() or GetObjectType() . 尝试GetObject()GetObjectType() They should return NULL if the object handle is invalid. 如果对象句柄无效,则它们应返回NULL。

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. 我们的世界不是一个完美的世界。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM