2013-06-15 1 views
1

선택한 응용 프로그램을 출력하는 programm를 빌드하려고합니다. 하지만 어떤 이유로 AXError : -25204가 표시됩니다. 참조에 따르면이 오류는 내가 중재하려고하는 앱이 ether busy이거나 응답하지 않음을 의미합니다. 나는Mac에서 FocuesApp를 사용하려고 시도했습니다.

나는이 튜토리얼에서 안내하고 있어요 ... 이유를 이해 해달라고 : http://cocoatutorial.grapewave.com/2010/01/retrieving-the-window-that-has-focus/

#import <Foundation/Foundation.h> 
#import <AppKit/NSAccessibility.h> 

int main (int argc, const char * argv[]) { 
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; 

if(!AXAPIEnabled()){ 
    NSLog(@"AXAPI not Enabled"); 
    return 0; 
} 

AXUIElementRef _systemWideElement; 
AXUIElementRef _focusedApp; 
CFTypeRef _focusedWindow; 
CFTypeRef _position; 
CFTypeRef _size; 
AXError e; 


//Get the window that has the focus 
//Get the app that has the focus 
_systemWideElement = AXUIElementCreateSystemWide(); 
NSLog(@"%d",_systemWideElement); 
e=AXUIElementCopyAttributeValue(_systemWideElement, 
           (CFStringRef)kAXFocusedApplicationAttribute, 
           (CFTypeRef*)&_focusedApp); 
NSLog(@"%d,%d",kAXErrorSuccess,e); 

e=AXUIElementCopyAttributeValue((AXUIElementRef)_focusedApp,(CFStringRef)NSAccessibilityFocusedWindowAttribute,(CFTypeRef*)&_focusedWindow); 
if(e == kAXErrorSuccess) { 
    NSLog(@"App ausgewaehlt"); 

    if(CFGetTypeID(_focusedWindow) == AXUIElementGetTypeID()) { 
     //Get the Window's Current Position 
     if(AXUIElementCopyAttributeValue((AXUIElementRef)_focusedWindow, 
             (CFStringRef)NSAccessibilityPositionAttribute, 
             (CFTypeRef*)&_position) != kAXErrorSuccess) { 
      NSLog(@"Can't Retrieve Window Position"); 
     } 
     //Get the Window's Current Size 
     if(AXUIElementCopyAttributeValue((AXUIElementRef)_focusedWindow, 
             (CFStringRef)NSAccessibilitySizeAttribute, 
             (CFTypeRef*)&_size) != kAXErrorSuccess) { 
      NSLog(@"Can't Retrieve Window Size"); 
     } 
    } 
    //NSLog(@"%@",_size); 

}else { 
    NSLog(@"%d",e); 
} 
[pool drain]; 
return 0; 

}

누군가가 아이디어가있다?

답변

0

NSAccessibility 개의 API 대신에 kAXFocusedWindowAttribute이고 아마도 kAXSizeAttribute이고 here으로되어 있습니다. 내 경험에 비추어 볼 때, 2 개의 API를 섞어서는 안되며 C API를 사용하여 다른 응용 프로그램의 요소에 액세스하려고합니다.