【问题标题】:Events when dock is showing or hiding停靠栏显示或隐藏时的事件
【发布时间】:2011-05-26 07:43:32
【问题描述】:

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

【问题讨论】:

    标签: objective-c cocoa macos dock


    【解决方案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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-06-12
      • 1970-01-01
      • 2014-02-06
      • 1970-01-01
      • 2015-01-15
      • 1970-01-01
      • 2010-11-26
      • 2012-01-23
      相关资源
      最近更新 更多