Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Need to find which window is active



On Oct 31, 2003, at 9:20 PM, Eric Schlegel wrote:
Using the accessibility APIs, you'd do something like this:

- get the pid_t of an application
- call AXUIElementCreateApplication with that pid
- call AXObserverCreate with that pid
- call AXObserverAddNotification with that AXUIElementRef and observer, passing kAXMainWindowChangedNotification as the notification
- call AXObserverGetRunLoopSource on that observer
- call CFRunLoopAddSource( GetCFRunLoopFromEventLoop( GetMainEventLoop() ), passing that run loop source

Now your callback proc should be called when the main window (i.e., the active window) of that application changes.

-eric

I put together the code, but every time it runs, AXObserverAddNotification always returns the error kAXErrorCannotComplete. I've tried several modifications, but nothing changes. Is that most likely because of a code error my part, or is it because these calls are still in "draft" mode?

ProcessSerialNumber psn = UProcess::GetPSN( "\pmail");

pid_t pid = psn.lowLongOfPSN;
AXUIElementRef elementRef = ::AXUIElementCreateApplication (pid);

AXObserverRef observerRef;
AXError err = ::AXObserverCreate ( pid,
(*(AXObserverCallback)MyObserverCallback),
&observerRef);

err = ::AXObserverAddNotification ( observerRef,
elementRef,
kAXMainWindowChangedNotification,
nil );
// err always returns kAXErrorCannotComplete

Thanks,
Bill
_______________________________________________
carbon-development mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/carbon-development
Do not post admin requests to the list. They will be ignored.



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.