Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 571
RLT Avatar asked Jul 06 '11 08:07

RLT


1 Answers

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);
like image 197
RLT Avatar answered Oct 03 '22 02:10

RLT