Click here to Skip to main content
Click here to Skip to main content
Go to top

Window docker application

, 16 Aug 2012
Rate this:
Please Sign up or sign in to vote.
A versatile program that allows users to dock most windows into the program and keeps it in the topmost layer of the screen.

332564/Window_Docker_ScreenShot.png

Introduction

Hello everyone, I made this application to learn C#, this is my first application thus my first article. The main reason for this application is to allow it's users to multitask on the computer differently. It has the following features that make it so:

  1. Capture program windows: By clicking on the Browse button you will be prompted to open a file. Choose what you want the application to capture (preferably a program). The program will run and then be captured inside the application. Note: you can have as many programs as you want, but based on the program it may not dock into the application.
  2. Top-most: The application was designed to be always shown in front of all other windows so you can see what you are doing in the background while still being able to do things inside the application(NOTE based on what background programs your running the application may not stay in front of the screen).
  3. Opacity meter: On the bottom of the application shows a track bar that allows you to change the opacity of the application. This feature was intended to aid users in seeing the background and at the same time lessen the distraction of the application's presence. (Note: the application will not turn completely invisible so you can always find it).

Background

The idea for this application was to solve the problem of having to tab when multitasking for example, I wanted to see some information I wrote in notepad about an online game I was playing at the same time. Every time I had to play the game notepad would always hide in the background so I would have to tab back to Notepad (and you know how that went... my character may sometimes end up dead for not paying attention to the game Frown | :( ).

Capturing Programs

I had some help with this part from the CodeProject community, I give thanks to Rahul Dhoble, and OriginalGriff.

In order to capture a program into the application you must first add the following:

[DllImport("user32.dll")]
static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);

under InitializeComponent();.

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }

    [DllImport("user32.dll")]
    static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);

The first line is to import a dll file which is a system file. The program uses this file to call specific commands form within that file. For further details you may want to check this link http://msdn.microsoft.com/en-us/library/aa984739%28v=vs.71%29.aspx.

The second line sets the application as the parent for the child form (program of your choice).

The actual design for this project was to make the application capture any program you drag into it. But I didn't know how and frankly it was a good idea not to do that (would be a bad idea trust me). So I decided to make a button (toolstripbutton) that will prompt the user with an openfiledialog. This way users can have control over what they want to capture. Lets take a look at the code.

private void toolStripButton1_Click(object sender, EventArgs e)
{
    if (openFileDialog1.ShowDialog(this) == DialogResult.OK)
    {

        Process p = Process.Start(openFileDialog1.FileName);
        Thread.Sleep(500); 
        SetParent(p.MainWindowHandle, panel1.Handle);
    }

The first line handles the event, which is fired when the user clicks on the toolstripbutton. When that happens the program will perform the if statement. The if statement shows the openfiledialog and "if" the dialog's result is "OK" meaning that the user chose something then it will start the next block of code.

Heres where the magic starts, noticed the first line has a class called process. The letter "p" is what I named that class. In that code I told the program to start a process based on the openfiledialog file name that the user clicked on.

Process p = Process.Start(openFileDialog1.FileName);
Thread.Sleep(500); 
SetParent(p.MainWindowHandle, panel1.Handle);

The middle line simply gives the program time to load. after the wait the application sets the panel as the parent of the program. This makes the panel(grey area) capture the program.

332564/Window_Docker_opening_a_program_.png

Top-Most

In order to keep the application and the program thats inside the application from hiding in the background I simply went to the properties menu in the visual C# program and changed Top-Most from false to true.

332564/Article__TopMost_screenshot.png

If your not using Visual C# or you rather do it in code then here is the sample.

 private void Form1_Load(object sender, EventArgs e)
{
   this.Topmost = true;
} 

when the form loads it will automatically be Topmost so it wont hide if you click on the background.

332564/Window_Docker_TopMost_example_.png

Opacity Meter

One of my favorite features is the "Opacity Metor" or A.K.A trackbar. It changes the opacity of the application (including programs within). This allows users to see whats going on in the background, even when the application is in fullscreen. Let's see what made it happen. I got this information from Mahesh Chand he made a great article about this here is his link if you want to check it out. http://www.c-sharpcorner.com/uploadfile/mahesh/trackbar-in-C-Sharp/.

protected void trackBar1_Scroll(object sender, System.EventArgs e)
{
    Form1.ActiveForm.Opacity = ((float)this.trackBar1.Value) / 100;
}

Actually, I don't remember where I got code My apologies, if you want to use another way then I would suggest looking at Mahesh Chand's article.

Furthermore, you will need to add three values to your trackbar for example, minimum, maximum, and value. The minimum is the lowest amount the trackbar can have the maximum is the highest and the value is the current value of the trackbar. These changes can be made by the properties menu if you have visual C# this is what it will look like.

332564/article_trackbar1.png

For the code way it will be like this.

trackbar1.Minimum = 10;
trackbar1.Maximum = 100;
trackbar1.Value = 100;

I set the value to 100 so its opacity is 100% visible, another thing I put 10 as the minimum so the application wont be invisible (bad idea).

Lastly, before you are done with the trackbar you need to set the change rate, which depending on the values you choose changes how the trackbar fades and reappears in the application.

There are two change rates: the lowest is called a "SmallChange", values should be small, and "LargeChange" values should be larger than "SmallChange". Depending on what you are looking for you will have to play around these values. You can see these changes in the properties menu or for code users:

trackbar1.SmallChange = value;
trackbar1.LargeChange = value;

If you want to modify any other changes look in the properties menu, for code users look into Mahesh Chand's article:

332564/Window_Docker_Opacity_Meter_.png

Points of Interest

Well this is it! My first article ever, followed by my first C# project. I hope all of you enjoy my project and this article, both were fun to make. Please leave some feedback, if I left any details or did something wrong I want to know. I know I made a lot of mistakes!

Thank you.

License

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

Share

About the Author

MR. AngelMendez
Student
United States United States
No Biography provided

Comments and Discussions

 
GeneralMy vote of 1 PinprofessionalBrisingr Aerowing12-Sep-14 16:16 
GeneralMy vote of 4 Pinmemberwvd_vegt16-Aug-12 21:30 
QuestionNice idea Pinmemberwvd_vegt16-Aug-12 21:30 
AnswerRe: Nice idea PinmemberMR. AngelMendez6-Sep-12 23:43 
GeneralMy vote of 1 PinmemberBillWoodruff16-Aug-12 13:45 
QuestionMy vote of #1 PinmemberBillWoodruff16-Aug-12 13:45 
AnswerRe: My vote of #1 PinmemberMR. AngelMendez6-Sep-12 23:49 
GeneralRe: My vote of #1 PinmemberCarsten V2.06-Sep-14 2:07 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web04 | 2.8.140905.1 | Last Updated 16 Aug 2012
Article Copyright 2012 by MR. AngelMendez
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid