NSStatusItem?

Discussion in 'Mac Programming' started by semaja2, Feb 1, 2007.

  1. macrumors 6502a

    Joined:
    Dec 12, 2005
    Messages:
    574
    Location:
    Adelaide
    #1
    Hey, it seems the only guide that worked and everyone liked is giving me a 404, so does anyone know of some good guides or examples that are very easy to understand?

    Im at the moment trying to read the growl source code but im lost in the code
     
  2. macrumors 603

    whooleytoo

    Joined:
    Aug 2, 2002
    Messages:
    6,257
    Location:
    Cork, Ireland.
    #2
    I've the source code of mine at home, I can post it tomorrow, if no one else has answered by then.
     
  3. macrumors 603

    whooleytoo

    Joined:
    Aug 2, 2002
    Messages:
    6,257
    Location:
    Cork, Ireland.
    #3
    You could use the following. _systemMenu is an instance NSStatusItem* variable, and _menu is an IBOutlet pointing to a menu in the app's nib file.

    Code:
    - (void) showMenubarIcon
    {
    	NSImage*	icon = [NSImage imageNamed:@"MenuIcon"] ;
    	
    	NSStatusBar*	bar = [NSStatusBar systemStatusBar] ;
    	_systemMenu = [bar statusItemWithLength:NSSquareStatusItemLength] ;
    	[_systemMenu retain] ;
    	
    	[_systemMenu setTitle: nil] ;
    	[_systemMenu setImage:icon] ;
    	[_systemMenu setHighlightMode:YES] ;
    	[_systemMenu setMenu:_menu] ;	
    }
    
    - (void) hideMenubarIcon
    {	
    	[_systemMenu release] ;
    	_systemMenu = nil ;
    }
     
  4. macrumors 6502a

    Joined:
    Dec 12, 2005
    Messages:
    574
    Location:
    Adelaide
    #4
    Thanks Whooelytoo, greatly appreciated. I used your code and some other examples to finally come up with my solution but i thought i should write a guide up for anyone else that might want to do this and is also a extreme n00b at ObjC :p

    So if anyone wants to check out my first guide ive ever written : http://files.semaja2.net/NSStatusItem - ObjC.html

    Comments appreciated and so is constructive criticism (I know about the missing bits in the @interface i will fix these up when i learn about them :p )
     
  5. macrumors regular

    Joined:
    Jan 17, 2007
    Messages:
    170
    #5
    Hey great guide Semaja, I'm sure once I learn more about Obj-C and Cocoa I'll be using it =].
     
  6. macrumors 6502a

    Joined:
    Dec 12, 2005
    Messages:
    574
    Location:
    Adelaide
    #6
    Thanks ill be making it into a proper HTML page and stuff later on, the one in that link is just a export from pages so its kinda bloaty ;)
     
  7. macrumors 603

    janey

    Joined:
    Dec 20, 2002
    Messages:
    5,322
    Location:
    sunny los angeles
    #7
    thanks whooleytoo and semaja2 :D
    i've been looking around for guides and sample code, not much luck. great timing, as i was about to give up too :p

    One thing though, the screenshots on the guide are really blurry - I know what you're doing and i get the point from the shots, but it's still blurry :(

    on second thought, i just looked at an image and it's only blurry because it's enlarged in the guide..nevermind :D :eek:
     
  8. Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    Messages:
    7,743
    #8
    I would suggest posting your guide at cocoadev.com also, so that others can find it easily, and if your site goes down or something, it'll always be accessible on cocoadev.com :)
     
  9. macrumors 6502a

    Joined:
    Dec 12, 2005
    Messages:
    574
    Location:
    Adelaide
    #9
    kainjow: thanks for the suggestion, once i finish the guide (few little bits needed cleaning) ill either post the link or have them host it

    janey: i have a upcoming guide that explains how to interface with the Apple Remote, but im might increase the required base knowledge so that i can cut down on the confusion caused by the many screenshots i know have in the new guide :p

    as for the screenshots, they were only added for a quick reference not to actually be read but your not the only one bringing up the point on bad quality
     

Share This Page