Get Coordinates From Top Of Screen?

Discussion in 'Mac Programming' started by Darkroom, Dec 1, 2008.

  1. Darkroom Guest

    Darkroom

    Joined:
    Dec 15, 2006
    Location:
    Montréal, Canada
    #1
    i have a thin horizontal window that i want to extend from the left to right of the screen but always be, say, 20 pixels below the menu bar.

    in Interface builder the coordinates start at the bottom left of the screen, and since all screens can be different size, if i use IB to position my window on my 24" iMac, it will be positioned wrong on a 20" iMac.

    menubar has what, 22pixels? so how can i tell my code to find the top of the screen and move down 42 pixels?

    sorry if this is a dumb question. :eek:
     
  2. mkelly11 macrumors newbie

    Joined:
    Dec 1, 2008
    #2
    try using NSScreen

    Hi there-

    I remember having the exact same problem. If you're using Cocoa, try the NSScreen class (documentation here). You can use it to figure out screen dimensions and some other stuff. If you're not using Cocoa (e.g. Carbon or Java), I'm not too sure what to use, though.

    Good luck!
     
  3. Darkroom thread starter Guest

    Darkroom

    Joined:
    Dec 15, 2006
    Location:
    Montréal, Canada
    #3
    thanks mkelly11... you were right... it was necessairy to get the total size of the screen's frame and make calculations from that using NSSize and NSMakeRect... something like this:

    Code:
    NSSize theScreenSize = [[NSScreen mainScreen] frame].size;
    [self setFrame:NSMakeRect(0, (theScreenSize.height - 50), theScreenSize.width, 25) display:YES];
    
     

Share This Page