Click here to Skip to main content
12,756,298 members (34,323 online)
Click here to Skip to main content

Stats

295.5K views
5.1K downloads
115 bookmarked
Posted 24 Jan 2008

Create a system tray icon and a dialog for a Windows Service

, 25 Jan 2008 CPOL
This article shows how to create a system tray icon and a dialog for a Windows Service.
Interop.SensEvents.dll
SystemTrayIconInSvc.exe
SystemTrayIconInSvc.vshost.exe
Interop.COMAdmin.dll
Interop.SensEvents.dll
SystemTrayIconInSvc.exe
SystemTrayIconInSvc.vshost.exe
Interop.COMAdmin.dll
SystemTrayIconInSvc.csproj.user
SystemTrayIconInSvc.suo
obj
Debug
Interop.COMAdmin.dll
Interop.SensEvents.dll
Refactor
SystemTrayIconInSvc.csproj.GenerateResource.Cache
SystemTrayIconInSvc.csproj.ResolveComReference.cache
SystemTrayIconInSvc.exe
SystemTrayIconInSvc.pdb
SystemTrayIconInSvc.SettingDlg.resources
TempPE
Release
Interop.COMAdmin.dll
Interop.SensEvents.dll
SystemTrayIconInSvc.csproj.GenerateResource.Cache
SystemTrayIconInSvc.csproj.ResolveComReference.cache
SystemTrayIconInSvc.exe
SystemTrayIconInSvc.pdb
SystemTrayIconInSvc.SettingDlg.resources
TempPE
Properties
SystemTrayIconInSvc.csproj.user
bin
Release
Interop.COMAdmin.dll
Interop.SensEvents.dll
SystemTrayIconInSvc.exe
SystemTrayIconInSvc.vshost.exe
SystemTrayIconInSvc.csproj.user
SystemTrayIconInSvc.suo
Interop.COMAdmin.dll
Interop.SensEvents.dll
SystemTrayIconInSvc.csproj.GenerateResource.Cache
SystemTrayIconInSvc.csproj.ResolveComReference.cache
SystemTrayIconInSvc.exe
SystemTrayIconInSvc.pdb
SystemTrayIconInSvc.SettingDlg.resources
Interop.COMAdmin.dll
Interop.SensEvents.dll
SystemTrayIconInSvc.csproj.GenerateResource.Cache
SystemTrayIconInSvc.csproj.ResolveComReference.cache
SystemTrayIconInSvc.exe
SystemTrayIconInSvc.pdb
SystemTrayIconInSvc.SettingDlg.resources
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.ServiceProcess;
using System.Text;

namespace SystemTrayIconInSvc
{
    public partial class Svc : ServiceBase
    {
        private SensAdvisor m_Advisor = new SensAdvisor();
        private SettingDlg m_Dlg = null;

        public Svc()
        {
            InitializeComponent();

            m_Advisor.OnShellStarted += this.PostShell;
        }

        internal void DebugStart()
        {
            OnStart(null);
        }

        protected override void OnStart(string[] args)
        {
            // if the service started after the windows logon
            CloseDlg();
            m_Dlg = SettingDlg.StartUIThread();
        }

        protected override void OnStop()
        {
            CloseDlg();
        }

        /// <summary>
        /// Called when the shell is ready
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void PostShell(object sender, SensLogon2EventArgs e)
        {
            CloseDlg();
            m_Dlg = SettingDlg.StartUIThread();
        }

        protected void CloseDlg()
        {
            if (m_Dlg != null)
            {
                try
                {
                    m_Dlg.Close();
                    m_Dlg.Dispose();
                }
                catch { }
                m_Dlg = null;
            }
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Jerry.Wang
Team Leader
China China
Jerry is from China. He was captivated by computer programming since 13 years old when first time played with Q-Basic.



  • Windows / Linux & C++

  • iOS & Obj-C

  • .Net & C#

  • Flex/Flash & ActionScript

  • HTML / CSS / Javascript

  • Gaming Server programming / video, audio processing / image & graphics



Contact: vcer(at)qq.com
Chinese Blog: http://blog.csdn.net/wangjia184

You may also be interested in...

Pro
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170217.1 | Last Updated 25 Jan 2008
Article Copyright 2008 by Jerry.Wang
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid