views:

236

answers:

1

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  A: 

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.)

David Gelhar
So, There is any way from my application to get a handle ( pointer or whatever ) to the window/control at certain screen coordinates?I need to get a ref to the window/control at screen coordinate an then use that ref to get the window/control rectangle, for reading purposes( read-only ):in windows the code will look like this:<pre><code>POINT pt;pt.x = 100;//for examplept.y = 200;//for exampleHWND wnd = WindowFromPoint( pt );RECT r;GerWindowRect( wnd, // use for reading r.left, r.right.....</code></pre>thank you in advance
JxXx
so, as you comment, the only way to get the width and height of, for example, a textbox under the mouse(or at any position), is listing all the windows, find the one that is in the most top position and within the desired location, list all the controls of that window and find the one that is under the mouse, then retrieve it's dimensions. I think this is very time consuming and should be another way to do it, for example inside the operating system, when the mouse is moved events are sent to the right window and this is done many times per second, should be there a optimized function for that
JxXx
Actually, if you want to start delving inside the contents of the window (assuming it does not belong to your application), then you must use the accessibility APIs, not the window list functions.
David Gelhar
Thanks David, OK, I should use the accessibility API but How should I use it for this purpose? Also I´ve read that the user has to activate the accesibility functions and I need this to be able for all the users without bother 'em. Can I activate it by code?Thank you!
JxXx
As far as I know, you can't activate the accessibility API without user approval, because of security (it allows you complete power to remote-control other applications). This sample code: http://developer.apple.com/mac/library/samplecode/UIElementInspector demonstrates using the accessibility API to log info about the element currently under the mouse.
David Gelhar