Objective c 全局隐藏光标(从后台应用程序)
我想在statusbar应用程序中隐藏光标,我做了一些研究。似乎这个问题的解决方案是在不久前找到的: 或 但是引用的代码不会编译。你们中有谁知道如何使代码编译(通过导入一些旧的API或其他东西)或实现这一点的另一种方法(某种黑客) (我知道在后台应用程序中隐藏光标通常不是一个好主意,但我正在制作一个非常重要的应用程序) 编辑: 这是老一套,已经不管用了Objective c 全局隐藏光标(从后台应用程序),objective-c,cocoa,macos,Objective C,Cocoa,Macos,我想在statusbar应用程序中隐藏光标,我做了一些研究。似乎这个问题的解决方案是在不久前找到的: 或 但是引用的代码不会编译。你们中有谁知道如何使代码编译(通过导入一些旧的API或其他东西)或实现这一点的另一种方法(某种黑客) (我知道在后台应用程序中隐藏光标通常不是一个好主意,但我正在制作一个非常重要的应用程序) 编辑: 这是老一套,已经不管用了 long sysVers = GetSystemVersion(); // This trick doesn't work on 10.1
long sysVers = GetSystemVersion();
// This trick doesn't work on 10.1
if (sysVers >= 0x1020)
{
void CGSSetConnectionProperty(int, int, int, int);
int CGSCreateCString(char *);
int CGSCreateBoolean(BOOL);
int _CGSDefaultConnection();
void CGSReleaseObj(int);
int propertyString, boolVal;
// Hack to make background cursor setting work
propertyString = CGSCreateCString("SetsCursorInBackground");
boolVal = CGSCreateBoolean(TRUE);
CGSSetConnectionProperty(_CGSDefaultConnection(), _CGSDefaultConnection(), propertyString, boolVal);
CGSReleaseObj(propertyString);
CGSReleaseObj(boolVal);
}
它给了我4个错误:
“_CGSCreateBoolean”,引用自:
-MyClass.o中的[MyClass myMethod]
“\u GetSystemVersion”,引用自:
-MyClass.o中的[MyClass myMethod]
“_CGSCreateCString”,引用自:
-MyClass.o中的[MyClass myMethod]
“_CGSReleaseObj”,引用自:
-[MyClass myMethod]在MyClass.o中,您需要针对应用程序服务框架进行链接,以消除链接器错误 下面是一个完整的黑客示例(更新为使用Core Foundation):
cat>t.c请编辑您的问题,以包括您正在使用的确切代码以及由此产生的错误。我修复了在执行Windows server/dock任务时,通过使用NSTimer反复调用-hideCursor
来重新显示光标的问题。即使应用程序不在前台,也有人知道为什么在使用C++编译器时代码会中断吗?本例工作正常,如上所述,但在执行“clang++-framework ApplicationServices t.c”时出现以下错误:架构x86的未定义符号\u 64:“\u CGSDefaultConnection()”,引用自:_mainin testCursor-p78PsB.o“CGSSetConnectionProperty(int,int,\u CFString const*,\u CFBoolean const*)”,引用自:_mainin testCursor-p78PsB.o ld:symbol未找到体系结构x86_64 clang:错误:链接器命令失败,退出代码为1(使用-v查看调用)
有人知道如何将此代码转换为Swift 2吗?我很难让它工作。
cat >t.c<<EOF
#include <ApplicationServices/ApplicationServices.h>
int main(void)
{
void CGSSetConnectionProperty(int, int, CFStringRef, CFBooleanRef);
int _CGSDefaultConnection();
CFStringRef propertyString;
// Hack to make background cursor setting work
propertyString = CFStringCreateWithCString(NULL, "SetsCursorInBackground", kCFStringEncodingUTF8);
CGSSetConnectionProperty(_CGSDefaultConnection(), _CGSDefaultConnection(), propertyString, kCFBooleanTrue);
CFRelease(propertyString);
// Hide the cursor and wait
CGDisplayHideCursor(kCGDirectMainDisplay);
pause();
return 0;
}
EOF
gcc -framework ApplicationServices t.c
./a.out