开发者

Get a bounds of WindowRef?

I am trying to find a Carbon API which can give me the WindowRef from window id and with that windowref I want to have bounds?

EDIT: I found API extern WindowRef HIWindowFromCGWindowID(CGWindowID inWindowID); But开发者_开发问答 I am not able to use it. I have included carbon header and have also added its framework to project. Is there something else required to HI apis?

Any help is appreciated. Thank you for your time.


Following should do -

        CGRect rect;
        uint32_t windowid[1] = {windowID};
        CFArrayRef windowArray = CFArrayCreate ( NULL, (const void **)windowid, 1 ,NULL);
        CFArrayRef windowsdescription = CGWindowListCreateDescriptionFromArray(windowArray);
        CFDictionaryRef windowdescription = (CFDictionaryRef)CFArrayGetValueAtIndex ((CFArrayRef)windowsdescription, 0);
        if(CFDictionaryContainsKey(windowdescription, kCGWindowBounds))
        {
            CFDictionaryRef bounds = (CFDictionaryRef)CFDictionaryGetValue (windowdescription, kCGWindowBounds);
            if(bounds)
            {
                CGRectMakeWithDictionaryRepresentation(bounds, &rect);
            }
        }
        CFRelease(windowArray);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜