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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With