废话不多说直接上代码
void dockerQuitHandler(id self,SEL _cmd,...)
{
Q_UNUSED(self)
Q_UNUSED(_cmd)
//这里写要在退出的时候 *** 作 *** 作
cout<<"docker quit";
}
Class cls = objc_getClass("NSApplication");
objc_object *app=pobjc_msgSend((objc_object*)cls,sel_registerName("sharedApplication"));
if(app != NULL) {
SEL shouldterminate = sel_registerName("applicationShouldTerminate:");
objc_object* delegate = objc_msgSend(app, sel_registerName("delegate"));
Class delClass = (Class)objc_msgSend(delegate, sel_registerName("class"));
if (class_getInstanceMethod(delc, shouldterminate)) {
if (class_replaceMethod(delc, shouldterminate, (IMP)dockerQuitHandler, "L@:@"))
cout << "Registered dock quit handler success";
else
cout << "Failed";
}
}
这里https://developer.apple.com/documentation/appkit/nsapplication/有详细的接口说明,具体需求看具体的函数。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)