Click here to Skip to main content
15,882,017 members
Articles / Programming Languages / C#

Window Tabifier

Rate me:
Please Sign up or sign in to vote.
4.91/5 (88 votes)
29 Mar 2008CPOL9 min read 313.7K   9.9K   294  
A simple application for hosting several Windows in one parent window
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.Win32;
using System.Security.Permissions;
using System.Security;

namespace WindowTabifier
{
    public partial class Main : Form
    {
        Properties.Settings set = Properties.Settings.Default;
        About.AboutBox box = new About.AboutBox("Window Tabifier");

        public Main()
        {
            InitializeComponent();

            rdbExeIcon.Checked = !rdbWindowIcon.Checked;

            box.programname = "Window Tabifier";
            box.StartPosition = FormStartPosition.CenterScreen;
            box.BackColor = Color.SandyBrown;
        }

        private bool isstartup()
        {
            bool result = false;
            RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run", true);
            result = key.GetValue("Window Tabifier") != null;
            key.Close();
            return result;
        }

        [RegistryPermissionAttribute(SecurityAction.LinkDemand, Write = @"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run")]
        private void startup(bool add)
        {
            RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run", true);
            if (add)
            {
                key.SetValue("Window Tabifier", "\"" + Application.ExecutablePath + "\"");
            }
            else
                key.DeleteValue("Window Tabifier", false);

            key.Close();
        }

        private void Exit_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            if (!System.IO.File.Exists(Application.StartupPath + "\\Window Tabifier.exe.config"))
            {
                MessageBox.Show("Configuration file not found.", "Error", MessageBoxButtons.OKCancel, MessageBoxIcon.Error);
                Application.Exit();
            }
            System.IO.Directory.SetCurrentDirectory(Application.StartupPath);
            winapi.statusbar = winapi.FindWindow("Shell_TrayWnd", "");

            set.Startup = isstartup();
            Tray.ShowBalloonTip(5);
            this.Hide();
        }

        private void Tab_Click(object sender, EventArgs e)
        {
            WindowList wnd = new WindowList();
            if (wnd.ShowDialog() == DialogResult.OK && wnd.SelectedWindows.Count>0)
            {
                Host hostform = new Host(wnd.SelectedWindows);
                hostform.Show();
                wnd.Dispose();
            }
        }

        private void tabAll_Click(object sender, EventArgs e)
        {
            Host hostwindow = null;
            if (Properties.Settings.Default.Ignore)
            {
                hostwindow = new Host(window.GetOpenWindows().FindAll(delegate(window wnd) { return wnd.Title.Length > 0 && wnd.GetExecutablePath() != Application.ExecutablePath; }));
            }
            else
            {
                hostwindow = new Host(window.GetOpenWindows().FindAll(delegate(window wnd) { return wnd.GetExecutablePath() != Application.ExecutablePath; }));
            }
            hostwindow.Show();
        }

        private void Tray_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            if (!this.Visible)
            {
                this.Show();
                this.WindowState = FormWindowState.Normal;
            }
        }

        private void Main_FormClosing(object sender, FormClosingEventArgs e)
        {
            startup(startupCheck.Checked);

            set.Save();

            if (e.CloseReason == CloseReason.UserClosing)
            {
                this.Hide();
                e.Cancel = true;
            }
        }

        private void About_Click(object sender, EventArgs e)
        {
            if (!box.Visible)
            {
                box.ShowDialog();
            }
        }
    }
}

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)


Written By
Software Developer
Georgia Georgia
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions