[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

URGENT:  Creating a Tray Application in C#

Posted on 2003-12-11
8
Medium Priority
?
436 Views
Last Modified: 2010-04-16
I want to create a tray application in C#, which I have done.  However, to run the app, I am calling Sytem.Applicaton(run) which loads the window form of my class.  This in turn, loads a blank form, which is hidden and does not appear in the task bar.  The tray app runs find and all is well and good.  

However, a user can alt-tab to it, and sense the form is useless, I would like to avoid this.  Is there a way I can avoid this?

Also, I need to send windows messages to it.  Is this possible to do with no window?  
0
Comment
Question by:jjacksn
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
8 Comments
 
LVL 18

Expert Comment

by:testn
ID: 9930163
You might need to use an API called ShowWindow

ShowWindow(Handle, SW_HIDE);
0
 
LVL 5

Author Comment

by:jjacksn
ID: 9930178
testn,

this should hide thie window from the alt-tab?  
0
 
LVL 18

Accepted Solution

by:
testn earned 2000 total points
ID: 9930205
using System.Runtime.InteropServices;

        [DllImport("user32.dll")]
        private static extern uint ShowWindow( IntPtr hWnd, int nCmd );

......

where SW_HIDE = 0

in your form... this refer to System.Windows.Forms.Form instance
ShowWindow(this.Handle, SW_HIDE);
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 5

Author Comment

by:jjacksn
ID: 9930230
testn, thanks, worked perfectly.  

Now, I guessing this is not the proper way to be doing this.  Must one have an actual window open to receive messages?  If I implement IMessageFilter, can I just somehow enter the message pump in main and then receive the messages and mouse clicks properly vs. doing what I am doing now?
0
 
LVL 18

Expert Comment

by:testn
ID: 9931483
You're right.... there is no proper way to do that as far as I know... I am sure why tray application will not accept the windows message. *deeply exhale*
0
 
LVL 9

Expert Comment

by:malharone
ID: 9932111
an easier way ...
set
form.showintaskbar=false
0
 
LVL 9

Expert Comment

by:malharone
ID: 9932136
this is the actual form .. hides the current form with systray icon.

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;


namespace WindowsApplication3
{
      /// <summary>
      /// Summary description for Form1.
      /// </summary>
      public class Form1 : System.Windows.Forms.Form
      {
            private System.Windows.Forms.NotifyIcon notifyIcon1;
            private System.ComponentModel.IContainer components;

            public Form1()
            {
                  //
                  // Required for Windows Form Designer support
                  //
                  InitializeComponent();

                  //
                  // TODO: Add any constructor code after InitializeComponent call
                  //
            }

            /// <summary>
            /// Clean up any resources being used.
            /// </summary>
            protected override void Dispose( bool disposing )
            {
                  if( disposing )
                  {
                        if (components != null)
                        {
                              components.Dispose();
                        }
                  }
                  base.Dispose( disposing );
            }

            #region Windows Form Designer generated code
            /// <summary>
            /// Required method for Designer support - do not modify
            /// the contents of this method with the code editor.
            /// </summary>
            private void InitializeComponent()
            {
                  this.components = new System.ComponentModel.Container();
                  System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
                  this.notifyIcon1 = new System.Windows.Forms.NotifyIcon(this.components);
                  //
                  // notifyIcon1
                  //
                  this.notifyIcon1.Icon = ((System.Drawing.Icon)(resources.GetObject("notifyIcon1.Icon")));
                  this.notifyIcon1.Text = "notifyIcon1";
                  this.notifyIcon1.Visible = true;
                  //
                  // Form1
                  //
                  this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
                  this.ClientSize = new System.Drawing.Size(292, 273);
                  this.Name = "Form1";
                  this.ShowInTaskbar = false;
                  this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
                  this.Text = "Form1";
                  this.WindowState = System.Windows.Forms.FormWindowState.Minimized;
                  this.Load += new System.EventHandler(this.Form1_Load);

            }
            #endregion

            /// <summary>
            /// The main entry point for the application.
            /// </summary>
            [STAThread]
            static void Main()
            {
                  Application.Run(new Form1());
            }

            private void Form1_Load(object sender, System.EventArgs e)
            {
                  this.Visible=false;
            }
      }
}
0
 
LVL 5

Author Comment

by:jjacksn
ID: 10240067
testn, i lied.  that didn't really work.  It doesn' t show up in the taskbar or the task manager, but one can still alt-tab to it.
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Suggested Courses

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question