How to make a system tray program in Windows?

Discussion in 'Ruby' started by Sung Soo Kim, Nov 26, 2005.

  1. Sung Soo Kim

    Sung Soo Kim Guest

    ------=_Part_19567_33024358.1132968415820
    Content-Type: text/plain; charset=ISO-8859-1
    Content-Transfer-Encoding: quoted-printable
    Content-Disposition: inline

    How can I make my program appear in the system tray of the Windows?

    What I want my program do is to keep track of time regularly (using
    timer) and do something behind the scene. (like a scheduler.)
    So, I want to make my program disappear from main desktop and appear in the
    system tray.

    What can I do?

    ------=_Part_19567_33024358.1132968415820--
     
    Sung Soo Kim, Nov 26, 2005
    #1
    1. Advertising

  2. Sung Soo Kim

    daz Guest

    Sung Soo Kim wrote:

    > How can I make my program appear in the system tray of the Windows?
    >
    > What I want my program do is to keep track of time regularly (using
    > timer) and do something behind the scene. (like a scheduler.)
    > So, I want to make my program disappear from main desktop and appear in the
    > system tray.
    >
    > What can I do?


    This puts a green tick in the SysTray, then changes it to a red minus
    (No Entry sign in UK), then removes it. Delays in between (sleep).

    I was going to send a traffic light sequence but I'm not certain whether
    it's using a generally available DLL. I think most will have INETCPL.CPL

    You can use any DLL that has icon(s), probably .EXE also ?

    Have fun,


    daz


    #-------------------------------------------------------------------------------

    require 'Win32API'

    RT_ICON = 3
    DIFFERENCE = 11
    RT_GROUP_ICON = RT_ICON + DIFFERENCE

    NIF_MESSAGE = 1
    NIF_ICON = 2
    NIF_TIP = 4
    NIM_ADD = 0
    NIM_MODIFY = 1
    NIM_DELETE = 2


    ExtractIcon = Win32API.new('shell32', 'ExtractIcon', 'LPI', 'L')
    Shell_NotifyIcon = Win32API.new('shell32', 'Shell_NotifyIconA', 'LP', 'I')


    hicoY = ExtractIcon.call(0, 'C:\WINDOWS\SYSTEM\INETCPL.CPL', 21) # Green tick
    hicoN = ExtractIcon.call(0, 'C:\WINDOWS\SYSTEM\INETCPL.CPL', 22) # Red minus

    tiptxt = 'test icon (ruby)'
    pnid = [6*4+64, 0, 'ruby'.hash, NIF_ICON | NIF_TIP, 0, hicoY].pack('LLIIIL') <<
    tiptxt << "\0"*(64 - tiptxt.size)
    ret = Shell_NotifyIcon.call(NIM_ADD, pnid)
    p 'Err: NIM_ADD' if ret == 0

    sleep(3) # <----<<

    pnid = [6*4+64, 0, 'ruby'.hash, NIF_ICON | NIF_TIP, 0, hicoN].pack('LLIIIL') <<
    tiptxt << "\0"*(64 - tiptxt.size)
    ret = Shell_NotifyIcon.call(NIM_MODIFY, pnid)
    p 'Err: NIM_MODIFY' if ret == 0

    sleep(6) # <----<<

    pnid = [6*4+64, 0, 'ruby'.hash, 0, 0, 0].pack('LLIIIL') << "\0"
    ret = Shell_NotifyIcon.call(NIM_DELETE, pnid)
    p 'Err: NIM_DELETE' if ret == 0

    #-------------------------------------------------------------------------------
     
    daz, Nov 26, 2005
    #2
    1. Advertising

  3. On 11/25/05, Sung Soo Kim <> wrote:
    > How can I make my program appear in the system tray of the Windows?
    >
    > What I want my program do is to keep track of time regularly (using
    > timer) and do something behind the scene. (like a scheduler.)
    > So, I want to make my program disappear from main desktop and appear in t=

    he
    > system tray.
    >
    > What can I do?


    VisualuRuby makes this pretty easy:

    http://www.osk.3web.ne.jp/~nyasu/vruby/vrproject-e.html

    Here is the example script for the tray icon stuff:

    http://www.osk.3web.ne.jp/~nyasu/vruby/sample/traytest.rb

    Ryan
     
    Ryan Leavengood, Nov 26, 2005
    #3
  4. Sung Soo Kim

    daz Guest

    Tom Ayerst wrote:
    > Hi,
    >
    > Very neat. I found the icons in C:\WINDOWS\SYSTEM32\INETCPL.CPL' though.
    >



    Ah, thanks. That may apply to the majority, then.

    > Do you have pointers to more info on this API? I am not really a
    > windows programmer.
    >



    On MSDN,
    http://qurl.net/o2
    http://qurl.net/o3

    I support Ryan's point about VRuby/SWin and I should have mentioned it.

    The traytest.rb example he linked to should be more appropriate to the
    original poster than I thought.

    My example would need a Windows message loop to do anything useful like
    minimizing a GUI or waking it up again by clicking on the tray icon.
    VRuby implements that and, of course, most Windows users will have it
    installed already if they used the RubyForge one-click installer.


    Cheers,

    daz
     
    daz, Nov 26, 2005
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. balu
    Replies:
    1
    Views:
    621
    Peter Jausovec
    Dec 18, 2004
  2. Manish Hatwalne

    Re: show icon in system tray?

    Manish Hatwalne, Jul 15, 2003, in forum: Java
    Replies:
    1
    Views:
    438
    Joona I Palaste
    Jul 15, 2003
  3. Alessandro
    Replies:
    1
    Views:
    439
    Roedy Green
    Aug 24, 2009
  4. aidy
    Replies:
    2
    Views:
    276
  5. Andy P.
    Replies:
    0
    Views:
    130
    Andy P.
    Feb 12, 2009
Loading...

Share This Page