问题
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