Dock显示或隐藏时的事件

时间:2011-05-26 07:43:32

标签: objective-c cocoa macos dock

如何在Dock显示或隐藏时获取事件?

1 个答案:

答案 0 :(得分:1)

如果底座可见或不使用Carbon,您可以收到通知。我不知道在Cocoa中有什么办法。

(我没有测试过这个;它来自代码here

创建回调方法:

#import <Carbon/Carbon.h>

static const EventTypeSpec appEvents[] = {
    { kEventClassApplication, kEventAppSystemUIModeChanged }
};

OSStatus DockChangedHandler(EventHandlerCallRef inCallRef, EventRef event, void *userData) {
    OSStatus status = eventNotHandledErr;
    switch(GetEventClass(event)) {
        case kEventClassApplication: {
            SystemUIMode *outMode;
            SystemUIOptions *outOptions;
            GetSystemUIMode(outMode, outOptions);
            status = noErr;
        }
            break;

        default: 
            return;

    }

    /*Insert whatever you want to do when you're notified of a dock change*/

    return status;
}

然后将其放在您想要开始收听通知的任何地方:

    InstallApplicationEventHandler(NewEventHandlerUPP(DockChangedHandler), GetEventTypeCount(appEvents), appEvents, 0, NULL);


更多信息:http://developer.apple.com/library/mac/#technotes/tn2002/tn2062.html