views:

32

answers:

1

Hi,

i have simple question: How to get position of window on screen in cocoa? I try using frame from NSWindow but in result i have x and y of window always 0, but my window isn't on this position.

Best regards Chudziutki

+1  A: 

How to get position of window on screen in cocoa?

Send it a frame message and look at the result's origin member.

I try using frame from NSWindow but in result i have x and y of window always 0, but my window isn't on this position.

You forgot to hook up the outlet to your window, so you're sending that frame message to nil.

Frankly, it's surprising that the frame rectangle makes any sense at all instead of being a geometrically-impossible random set of numbers. Messages to nil return 0 for scalar types, such as pointers and single numbers, but a message that returns a structure (such as a rectangle) is not guaranteed to return anything.

Or you're talking to the wrong window—perhaps you created one in a nib and then created another one in code.

Peter Hosey
IIRC, structures small enough to fit into some integral type are treated as integers in the context of how a value is returned.
Chuck
Thanks, i got frame from wrong window
Chudziutki