Click here to Skip to main content
Click here to Skip to main content
Articles » Languages » C# » PInvoke » Downloads
 
Add your own
alternative version
Go to top

Window Tray Minimizer

, 26 Oct 2007
An article showing how to minimize any Window to the system tray
article_demo.zip
Demo
About.dll
Tray minimizer.exe
article_src.zip
Tray minimizer
Tray minimizer
About.dll
exeicon.ico
icon.ico
Properties
Settings.settings
Thumbs.db
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Tray_minimizer
{
    public partial class Options : Form
    {
        uint showmod;
        uint showkey;
        uint hidemod;
        uint hidekey;
        bool startup;
        bool ignoretitle;

        public bool Ignoretitle
        {
            get { return ignoretitle; }
            set { ignoretitle = value; }
        }

        public bool Startup
        {
            get { return startup; }
            set { startup = value; }
        }

        public uint Showmod
        {
            get { return showmod; }
            set { showmod = value; }
        }

        public uint Showkey
        {
            get { return showkey; }
            set { showkey = value; }
        }

        public uint Hidemod
        {
            get { return hidemod; }
            set { hidemod = value; }
        }

        public uint Hidekey
        {
            get { return hidekey; }
            set { hidekey = value; }
        }

        public Options()
        {
            InitializeComponent();
        }

        private void Options_Load(object sender, EventArgs e)
        {
            for (int i = 65; i < 91; i++)
            {
                showkeycombo.Items.Add((char)i);
                hidekeycombo.Items.Add((char)i);
            }

            if (System.IO.File.Exists("Tray minimizer.exe.config"))
            {
                showctrlcheck.Checked = ((int)winapi.KeyModifiers.Control & showmod) > 0;
                showaltcheck.Checked = ((int)winapi.KeyModifiers.Alt & showmod) > 0;
                showshiftcheck.Checked = ((int)winapi.KeyModifiers.Shift & showmod) > 0;

                hidectrlcheck.Checked = ((int)winapi.KeyModifiers.Control & hidemod) > 0;
                hidealtcheck.Checked = ((int)winapi.KeyModifiers.Alt & hidemod) > 0;
                hideshiftcheck.Checked = ((int)winapi.KeyModifiers.Shift & hidemod) > 0;

                showkeycombo.SelectedIndex = (int)showkey;
                hidekeycombo.SelectedIndex = (int)hidekey; 
            }

            startcheck.Checked = startup;
            ignoretitlecheck.Checked = ignoretitle;
        }

        private void getnewhotkey()
        {
            showmod = 0;
            hidemod = 0;

            if (this.showshiftcheck.Checked)
            {
                showmod = showmod | (uint)winapi.KeyModifiers.Shift;
            }
            if (this.showctrlcheck.Checked)
            {
                showmod = showmod | (uint)winapi.KeyModifiers.Control;
            }
            if (this.showaltcheck.Checked)
            {
                showmod = showmod | (uint)winapi.KeyModifiers.Alt;
            }

            if (this.hideshiftcheck.Checked)
            {
                hidemod = hidemod | (uint)winapi.KeyModifiers.Shift;
            }
            if (this.hidectrlcheck.Checked)
            {
                hidemod = hidemod | (uint)winapi.KeyModifiers.Control;
            }
            if (this.hidealtcheck.Checked)
            {
                hidemod = hidemod | (uint)winapi.KeyModifiers.Alt;
            }

            showkey = (uint)this.showkeycombo.SelectedIndex;
            hidekey = (uint)this.hidekeycombo.SelectedIndex;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            getnewhotkey();

            if (showkeycombo.SelectedIndex > 0 && showkeycombo.SelectedIndex == hidekeycombo.SelectedIndex && showmod==hidemod && showmod>0)
            {
                MessageBox.Show("Hotkeys cannot be the same", "Error", MessageBoxButtons.OKCancel, MessageBoxIcon.Error);
                return;
            }

            this.DialogResult = DialogResult.OK;
            startup = startcheck.Checked;
            ignoretitle = ignoretitlecheck.Checked;
            this.Close();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}

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

Giorgi Dalakishvili
Software Developer
Georgia Georgia
No Biography provided
Follow on   Google+

| Advertise | Privacy | Mobile
Web04 | 2.8.140916.1 | Last Updated 26 Oct 2007
Article Copyright 2007 by Giorgi Dalakishvili
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid