本文介绍了获取WindowRef的边界?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试找到一个Carbon API,该API可以从窗口ID中为我提供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?

我找到了APIextern WindowRef HIWindowFromCGWindowID(CGWindowID inWindowID);但是我无法使用它.我包括了carbon标头,并且还将其框架添加到了项目中. HI API是否还有其他要求?

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.

推荐答案

以下应做-

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

这篇关于获取WindowRef的边界?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 07:48