问题
As I said in some questions today I´m looking for the way to get window or windowPart references at a certain location. Although I know I could use Cocoa for this purpose (I don´t know how to do it yet) I prefer (and probably need) to do this using Carbon because the entire application that needs this functionality is written in C++ but I´ve found many problems trying it.
Does anyone get a valid windowPtr or windowRef using one of the following functions? FindWindow, MacFindWindow, HIWindowFindAtLocation or FindWindowOfClass
I always get 0 as the windowRef or windowPtr that I´m looking for. What I´m doing wrong? Any ideas?
It´s true that now if you want to create a 64-bit application for Mac OS X, you need to use Cocoa to implement its user interface because some APIs commonly used by Carbon applications are not available in 64-bit applications?
Thank you.
JxXx
回答1:
Based on your response to this question it appears that you are trying to get a WindowRef to another application's window.
As this posting to the carbon-dev list says:
You can't access memory in other programs. A WindowRef from another program would be meaningless in your program's memory space.
And the word on 64-bit carbon is this:
If you want to create a 64-bit application for Mac OS X, you need to use Cocoa to implement its user interface.
EDIT -
You can get the mouse location with [NSEvent mouseLocation]
(Cocoa) or GetMouse()
(Carbon). If you want to interact with windows belonging to another application, you'll need to use something like the Accessibility API (Cocoa), or the low-level Quartz Window list functions. The Quartz function returns a list of all windows (belonging to all applications) and limited information about each (bounds, owning PID, etc.)
来源:https://stackoverflow.com/questions/2628921/find-window-at-location-using-carbon-and-carbon-problems-in-64-bit-applications