gpt4 book ai didi

c++ - 在 C++ 中注册 WindowServer CGScreenRefreshCallback CGScreenUpdateMoveCallback

转载 作者:行者123 更新时间:2023-11-28 03:56:53 25 4
gpt4 key购买 nike

我正在尝试注册 CGScreenRefreshCallback 和 CGScreenUpdateMoveCallback(这是苹果对 http://developer.apple.com/mac/library/documentation/GraphicsImaging/Reference/Quartz_Services_Ref/Reference/reference.html#//apple_ref/doc/uid/TP30001070-CH1g-F16970 的说法)仅使用 C++。

我为刷新回调编写了这个简单的测试器,以检索不断变化的矩形:

#include "ApplicationServices/ApplicationServices.h"
#include <iostream>

using namespace std;

/////////////HEADER
static void DHRefreshCallback (CGRectCount count,const CGRect * rectArray,void * userParameter);
///////////////////

int main (int argc, char * const argv[]) {

CGRegisterScreenRefreshCallback(DHRefreshCallback, NULL);

while (true) {
// just hanging
}
return 0;
}


static void DHRefreshCallback (CGRectCount count,const CGRect * rectArray,void * userParameter){
cout << "something changed" << endl;
return;
}

...但是没用。

我知道我需要与 WindowServer 建立连接(Quartz Compositor\Quartz Extreme\Quartz Extreme 2D ... 仍然无法弄清楚其中的区别)和一个正在运行的线程才能获得这些回调,但我真的不知道只知道如何在 C++ 中执行此操作(根本没有 Objective-C)。

有什么方向吗?

提前谢谢,小 pig

最佳答案

这与使用/不使用 Objective-C 无关。这是关于一般 OS X 应用程序中的事件循环,由 CFRunloop 完成。 ,这是一个 C API。参见 Run Loop managementCFRunLoop reference .您还需要一个到窗口服务器的连接,可以通过调用

代替

while (true) {
// just hanging
}

就这样

extern "C" void NSApplicationLoad(void);
NSApplicationLoad(); // establish a connection to the window server. In <Cocoa/Cocoa.h>
CFRunLoopRun(); // run the event loop

不要忘记链接 Cocoa.framework;只需添加 -framework Cocoa在编译器的命令行中。你可以#import <Cocoa/Cocoa.h>但是由于其中声明的 Objective-C 类,您需要使用 Objective-C++。

你可以使用

 RunApplicationEventLoop(); //establish a connection to the window server 
//and runs the event loop. In <Carbon/Carbon.h>

在 32 位应用程序中,而不是 NSApplicationLoad + CFRunLoopRun ,但它在 64 位应用程序中不可用。

关于c++ - 在 C++ 中注册 WindowServer CGScreenRefreshCallback CGScreenUpdateMoveCallback,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3205442/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com