Get a bounds of WindowRef?

a 夏天 提交于 2019-12-12 07:27:50

问题


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.


回答1:


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);


来源:https://stackoverflow.com/questions/6593710/get-a-bounds-of-windowref

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!