注册WindowServer CGScreenRefreshCallback CGScreenUpdateMoveCallback在C ++ [英] register for WindowServer CGScreenRefreshCallback CGScreenUpdateMoveCallback in C++
问题描述
我想注册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 ++。
以检索更改的矩形:
#includeApplicationServices / 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){
//刚挂起
}
return 0;
}
static void DHRefreshCallback(CGRectCount count,const CGRect * rectArray,void * userParameter){
cout< 某事改变了< endl;
return;
}
...但没有工作。
我知道我需要一个连接WindowServer(Quartz Compositor \ Quartz Extreme \ Quartz Extreme 2D ...仍然不能弄清楚差别)和一个正在运行的线程,以获得这些回调,但是我真的不知道如何在C ++中做这个(没有Objective-C)。
任何方向?
thx,
pigiuz
C。它是关于OS X应用程序中的事件循环,通常由 CFRunloop
(这是一个C API)完成。请参见 Run Loop管理和 CFRunLoop参考。您还需要连接到窗口服务器,可以通过调用
而不是
建立 while(true){
// just hanging
}
$ b b
只是做
externCvoid NSApplicationLoad(void);
NSApplicationLoad(); //建立到窗口服务器的连接。在< Cocoa / Cocoa.h>
CFRunLoopRun(); //运行事件循环
不要忘记链接Cocoa.framework;只需在编译器的命令行中添加 -framework Cocoa
即可。
你可以 #import< Cocoa / Cocoa.h>
但是你需要使用Objective-C ++,因为它在其中声明了Objective-C类。 / p>
您可以使用
RunApplicationEventLoop //建立到窗口服务器的连接
//并运行事件循环。在< Carbon / Carbon.h>在32位应用程式中使用
,而不是 NSApplicationLoad
+ CFRunLoopRun
,但它不适用于64位应用程式。
I'm trying to register for CGScreenRefreshCallback and CGScreenUpdateMoveCallback ( here's what apple's saying about http://developer.apple.com/mac/library/documentation/GraphicsImaging/Reference/Quartz_Services_Ref/Reference/reference.html#//apple_ref/doc/uid/TP30001070-CH1g-F16970 ) using C++ only.
I wrote this simple tester for the refresh callback in order to retrieve the changing rectangles:
#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;
}
...but didn't work.
I know I need a connection with WindowServer (Quartz Compositor \ Quartz Extreme \ Quartz Extreme 2D...still can't figure out the difference) and a running thread in order to get these callbacks, but I really don't know how to do this in C++ only (no Objective-C at all).
any direction?
thx in advance, pigiuz
It's not about using/not using Objective-C. It's about the event loop in OS X apps in general, which is done by CFRunloop
, which is a C API. See Run Loop management and CFRunLoop reference. You also need a connection to the window server, which can be established by calling
Instead of
while (true) {
// just hanging
}
just do
extern "C" void NSApplicationLoad(void);
NSApplicationLoad(); // establish a connection to the window server. In <Cocoa/Cocoa.h>
CFRunLoopRun(); // run the event loop
Don't forget to link against Cocoa.framework; just add -framework Cocoa
in the command line of the compiler.
You can #import <Cocoa/Cocoa.h>
but then you need to use Objective-C++ because of the Objective-C classes declared in it.
You could use
RunApplicationEventLoop(); //establish a connection to the window server
//and runs the event loop. In <Carbon/Carbon.h>
in an 32 bit app, instead of NSApplicationLoad
+ CFRunLoopRun
, but it's not available in an 64 bit app.
这篇关于注册WindowServer CGScreenRefreshCallback CGScreenUpdateMoveCallback在C ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!