{"id":228,"date":"2010-01-31T14:37:19","date_gmt":"2010-01-31T06:37:19","guid":{"rendered":"http:\/\/www.xujiwei.com\/blog\/?p=228"},"modified":"2011-05-29T12:29:39","modified_gmt":"2011-05-29T04:29:39","slug":"register-appleevent-in-realbasic","status":"publish","type":"post","link":"https:\/\/xujiwei.com\/blog\/2010\/01\/register-appleevent-in-realbasic\/","title":{"rendered":"\u5728 REALbasic \u4e2d\u6ce8\u518c AppleEvent"},"content":{"rendered":"<p>\u4e4b\u524d\u4e3a\u4e86\u6ce8\u518c\u4e00\u4e2a\u81ea\u5b9a\u4e49\u534f\u8bae\uff0c\u9700\u8981\u901a\u8fc7\u6ce8\u518c AppleEvent \u6765\u5b9e\u73b0\uff0c\u5728 Objective-C \u4e2d\uff0c\u53ef\u4ee5\u5f88\u65b9\u4fbf\u7684\u4f7f\u7528 NSAppleEventManager \u6765\u6ce8\u518c AppleEvent \u53e5\u67c4\uff0c\u4f46\u662f\u5728 REALbaisc \u4e2d\uff0c\u662f\u6ca1\u6709\u529e\u6cd5\u76f4\u63a5\u53bb\u8c03\u7528 NSAppleEventManager \u7684\uff0c\u6240\u4ee5\u9700\u8981\u901a\u8fc7\u58f0\u660e\u7136\u540e\u8c03\u7528 C API \u6765\u5b9e\u73b0\u76f8\u5e94\u7684\u529f\u80fd\u3002<\/p>\n<p>\u4e0e NSAppleEventManager \u4e2d\u529f\u80fd\u76f8\u5bf9\u5e94\u7684 C API \u6709 AEInstallEventHandler, NewAEEventHandlerUPP \u7b49\uff0c\u901a\u8fc7\u8fd9\u4e9b API \u6211\u4eec\u4e5f\u53ef\u4ee5\u5728 REALbasic \u4e2d\u6765\u6ce8\u518c AppleEvent \u4e86\uff0c\u518d\u914d\u5408 Info.plist \u4e2d\u7684 URLScheme \u58f0\u660e\uff0c\u5373\u53ef\u5b9e\u73b0 URL \u81ea\u5b9a\u4e49\u534f\u8bae\u5904\u7406\u53e5\u67c4\u3002<\/p>\n<pre lang=\"vb\">#if TargetCarbon\r\n    soft declare function AEInstallEventHandler Lib CarbonLib ( _\r\n    theAEEventClass as Integer, _\r\n    theAEEventID as Integer, _\r\n    handler as Integer, _\r\n    handlerRefcon as Integer, _\r\n    isSysHandler as Boolean) as Integer\r\n\r\n    Soft Declare Function NewAEEventHandlerUPP Lib CarbonLib (userRoutine as Ptr) as Integer\r\n\r\n    Static CallbackUPP as Integer = 0\r\n    If CallbackUPP = 0 then\r\n      dim m as MemoryBlock =  AddressOf ForwardCarbonAEEventToObject\r\n      If m is nil then\r\n        Return\r\n      End if\r\n      CallbackUPP = NewAEEventHandlerUPP(m)\r\n    End if\r\n\r\n    dim v as Variant = me\r\n\r\n    dim OSError as Integer = AEInstallEventHandler( _\r\n    OSTypeToUInt(kInternetEventClass), _\r\n    OSTypeToUInt(kAEGetURL), _\r\n    CallbackUPP, _\r\n    v.Hash, false)\r\n\r\n    msgbox str(OSError)\r\n#endif<\/pre>\n<p>\u5148\u4f7f\u7528 NewAEEventHandlerUPP \u6765\u751f\u6210\u4e00\u4e2a AppleEvent \u56de\u8c03\u51fd\u6570\u7684\u53e5\u67c4\uff0c\u7136\u540e\u8c03\u7528 AEInstallEventHandler \u6765\u6ce8\u518c\u4e00\u4e2a\u5171\u4eab\u51fd\u6570 ForwardCarbonAEEventToObject \u4e3a AppleEvent \u4e8b\u4ef6\u5904\u7406\u53e5\u67c4\u3002<\/p>\n<p>AEInstallEventHandler \u6240\u9700\u7684 AEEventClass \u548c AEEventID \u90fd\u662f\u4e00\u4e2a 4 \u5b57\u8282\u7684\u6574\u578b\uff0c\u4f46\u662f\u901a\u5e38\u6211\u4eec\u5728\u8c03\u7528\u7684\u65f6\u5019\uff0c\u662f\u7528\u7684\u4e00\u4e2a 4 \u5b57\u7b26\u7684\u5b57\u7b26\u4e32\uff0c\u56e0\u6b64\u9700\u8981\u4e00\u4e2a\u51fd\u6570\u6765\u5c06 4 \u5b57\u7b26\u8f6c\u6362\u4e3a 4 \u5b57\u8282\u7684\u6574\u5f62\u3002<\/p>\n<pre lang=\"vb\">\/\/ code from ToolbarSearchField by The ZAZ Studios\r\n\/\/ http:\/\/www.thezaz.com\/opensource\/realbasic\/macosx\/searchfield\/\r\nstatic m as new MemoryBlock(4)\r\nm.LittleEndian = false\r\nm.StringValue(0, 4) = s\r\nreturn m.UInt32Value(0)<\/pre>\n<p>\u5728 ForwardCartonAEEventToObject \u91cc\uff0c\u53c2\u6570 theEvent \u548c replyEvent \u90fd\u91cf\u4e2a\u6574\u5f62\uff0c\u4e3a\u4e86\u4ece\u8fd9\u4e24\u4e2a\u53c2\u6570\u91cc\u62ff\u5230\u6570\u636e\uff0c\u8fd8\u9700\u8981\u4f7f\u7528 AEGetParamPtr \u6765\u4ece AppleEvent \u4e2d\u62ff\u5230\u6570\u636e\u3002<\/p>\n<pre lang=\"vb\">soft declare function AEGetParamPtr lib CarbonLib ( _\r\n    theAppleEvent as Integer, theAEKeyword as Integer, _\r\n    desiredType as Integer, byref actualType as Integer, _\r\n    dataPtr as Ptr, maximumSize as Integer, _\r\n    byref actualSize as Integer) as Integer<\/pre>\n<p>\u5f53\u7136\u8fd8\u6709\u4e00\u7cfb\u5217\u7684 AEGetDataDesc\u3001AEGetDescSize \u7b49\u51fd\u6570\u53ef\u4ee5\uff0c\u5177\u4f53\u53ef\u4ee5\u67e5 Xocde \u968f\u5e26\u7684\u5e93\u6587\u6863\u3002<\/p>\n<p>\u5173\u4e8e\u6ce8\u518c\u81ea\u5b9a\u4e49\u534f\u8bae\uff0c\u53ef\u4ee5\u53c2\u8003<a href=\"http:\/\/stackoverflow.com\/questions\/49510\/how-do-you-set-your-cocoa-application-as-the-default-web-browser\">\u8fd9\u7bc7\u6587\u7ae0<\/a>\u3002<\/p>\n<p>\u901a\u8fc7 Core Foundation \u4e2d\u7684\u4e00\u4e9b C API\uff0c\u5728 REALbasic \u4e5f\u53ef\u4ee5\u5b8c\u6210\u4e00\u4e9b\u5e73\u53f0\u76f8\u5173\u7684\u5de5\u4f5c\uff0c\u867d\u7136\u9ebb\u70e6\u4e86\u4e9b\uff1a\uff09<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e4b\u524d\u4e3a\u4e86\u6ce8\u518c\u4e00\u4e2a\u81ea\u5b9a\u4e49\u534f\u8bae\uff0c\u9700\u8981\u901a\u8fc7\u6ce8\u518c AppleEvent \u6765\u5b9e\u73b0\uff0c\u5728 Ob &hellip;<\/p>\n<p class=\"read-more\"><a href=\"https:\/\/xujiwei.com\/blog\/2010\/01\/register-appleevent-in-realbasic\/\">\u7ee7\u7eed\u9605\u8bfb &raquo;<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[168],"tags":[124,59,55],"_links":{"self":[{"href":"https:\/\/xujiwei.com\/blog\/wp-json\/wp\/v2\/posts\/228"}],"collection":[{"href":"https:\/\/xujiwei.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/xujiwei.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/xujiwei.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/xujiwei.com\/blog\/wp-json\/wp\/v2\/comments?post=228"}],"version-history":[{"count":0,"href":"https:\/\/xujiwei.com\/blog\/wp-json\/wp\/v2\/posts\/228\/revisions"}],"wp:attachment":[{"href":"https:\/\/xujiwei.com\/blog\/wp-json\/wp\/v2\/media?parent=228"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xujiwei.com\/blog\/wp-json\/wp\/v2\/categories?post=228"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xujiwei.com\/blog\/wp-json\/wp\/v2\/tags?post=228"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}