?
Solved

URGENT:  Creating a Tray Application in C#

Posted on 2003-12-11
8
Medium Priority
?
435 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses
Course of the Month8 days, 8 hours left to enroll

764 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