No announcement yet.

Tray Icon with NT Service

  • Filter
  • Time
  • Show
Clear All
new posts

  • Tray Icon with NT Service

    Hey all,

    I'm creating an NT Service that puts a tray icon into the system tray.
    When a user clicks my app's tray icon it is supposed to launch a dialog
    that allows the user to set some configuration settings.

    I'm almost there, but I think I'm missing something. My question(s) is
    this: Should the tray icon/configuration dialog be running in it's own
    thread from the rest of the tasks that my app is handling? Also, within
    the main entry point to the NT Service app is where I assume we put
    our main code. This seems to be working for me right now. Should this
    main code be put into it's own thread too?

    Thanks in advance!

    Scott Wolfington

    [This message has been edited by Scott Wolfington (edited March 05, 2003).]
    Scott Wolfington

  • #2
    I wrote a service last year using PB.  Here's what I found.
    -- Sample BASIC code for services can be found in various places on 
    the web, but problems exist with every example I looked at. Some was 
    incomplete, some was buggy or flawed in fundamental ways, and all of 
    it was a waste of my time to try to work with.  Microsoft makes 
    available some very useful examples in C, which proved far more 
    helpful to use as models. 
    -- Technically, services are not supposed to offer a user interface.  
    That's part of the whole idea behind a service as opposed to an 
    application.  The service API wasn't designed with the thought that 
    icons in the system tray would play any role in the way that a 
    service is manipulated.  That doesn't mean that such a feature is 
    impossible, but it does bring up the question of why a service, and 
    not a application, is intended at all. (I'm hardly obsessive about 
    always coloring within the lines.  I'm just pointing out that 
    although services offer certain features that applications do not, 
    the reverse is true as well.  I ended up writing a separate app to 
    handle user communication with the service whenever doing so became 
    -- Of the books I examined on the subject, Kevin  Miller's 
    [i]Professional NT Services [/i] (Wrox Press, 1998) offered the 
    clearest, most practical guide.  I bought it and have never regretted 
    the purchase. 
    -- If you're wondering about threads and where something belongs, you 
    probably will do well to dig up more information about this entire 
    subject.  Writing a service poses interesting challenges, some of 
    which have no parallel in other types of programming that I myself 
    had ever done. 
    -- Greg

    [This message has been edited by Greg Turgeon (edited February 10, 2001).]


    • #3
      Thanks Greg! I'll go check out that book. I found this article on
      the MSKB too.

      PRB: Common Controls Might Behave Unpredictably in an Interactive Service after Logoff

      "Implementing a user interface within a service process is not
      recommended. Whenever possible, a service process should be
      shielded from the actions of an interactive user. If a service
      needs to receive input or display output to the interactive
      user, a separate process should be implemented to run within
      the same logon session as the interactive user. That process
      can communicate with the service through the standard Win32
      methods of interprocess communication."

      Now I just need to figure out how to do "interprocess communication"
      with PowerBASIC. My service writes log data to an output file, and if
      the "user interface" (in this case a different app) is up, I'd like
      to write the same log data to a LISTBOX on the user interface dialog,
      so the user can monitor what's happening. What would be the best approach
      for something like this?


      Scott Wolfington

      [This message has been edited by Scott Wolfington (edited March 05, 2003).]
      Scott Wolfington


      • #4
        The task you describe obviously doesn't require tremendous 
        speed, so I'd just have the service pass data to display to 
        the interface app using %WM_COPYDATA.  Some time ago Semen 
        posted code that illustrates using this method of 
        interprocess communication.  It's relatively simple and can 
        do the job well.
        -- Greg

        -- Greg
        [email protected]


        • #5

          Once again, thank you. I'll give it a try. BTW, just got back from
          the bookstore with my own copy of "Professional NT Services". It looks
          pretty good.


          Scott Wolfington

          [This message has been edited by Scott Wolfington (edited March 05, 2003).]
          Scott Wolfington