Formless application

  • Thread starter Thread starter Mike Ruane-Torr
  • Start date Start date
M

Mike Ruane-Torr

I want to write an application that has no form, but uses toolbox
components, i.e. notify icon, context menu, timer. I notice that I can
drop these items onto a component class, but is that how I should be
approaching this problem? I have ended up tying myself in knots trying to
get Application.Run() to accept a context class, and raising the
ThreadExit event to stop everything - it's a bit more complicated than I
expected.

Am I being foolish? Should I just use a dummy form and never actually
display it? I feel uncomfortable doing this, because I don't NEED a
form. I thought .Net was more logical than that. Surely it has a way of
using controls without having a form?
 
Mike Ruane-Torr said:
I want to write an application that has no form, but uses toolbox
components, i.e. notify icon, context menu, timer. I notice that I can
drop these items onto a component class, but is that how I should be
approaching this problem? I have ended up tying myself in knots trying to
get Application.Run() to accept a context class, and raising the
ThreadExit event to stop everything - it's a bit more complicated than I
expected.

Am I being foolish? Should I just use a dummy form and never actually
display it? I feel uncomfortable doing this, because I don't NEED a
form. I thought .Net was more logical than that. Surely it has a way of
using controls without having a form?

A form is really just a framed window - it doesn't need to have any
controls on it or anything.

Where would you display your context menu if you didn't have a window
to hang it off?
 
Apps that use a notify icon will often have a form that is located off the
screen and does nothing but run the message loop. I assume the context menu
is for when the user clicks the notify icon so the form can display that for
you even though it's hidden off the screen.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Check out February's edition of Well Formed.
Non-client drawing, Graphics Transform stack and Flood-Filling
http://www.bobpowell.net/currentissue.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm

Read my Blog at http://bobpowelldotnet.blogspot.com
 
Hi Mike,

I have a similar application, it nevers show a windows, just an icon in the
system tray.

This is the code I'm using. basically you create a regular windows app and
then you minimize the main form, and set it to not appear in the taskbar:

this.WindowState = System.Windows.Forms.FormWindowState.Minimized;
this.Visible = false;
this.ShowInTaskbar = false;
this.Text = ""; // I think this is needed to not show the application
using alt+tab ???

//Or maybe this is to not show it? I don't really remember right now,
too early and too little cafeine yet :)
int windowStyle = GetWindowLong(Handle, GWL_EXSTYLE);
SetWindowLong(Handle, GWL_EXSTYLE, windowStyle | WS_EX_TOOLWINDOW);


Abyway , these are the declaration for Set|GetWindowLong :

[DllImport("user32.dll")]
public static extern int SetWindowLong( IntPtr window, int index, int
value);
[DllImport("user32.dll")]
public static extern int GetWindowLong( IntPtr window, int index);


Hope this help,
 
A form is really just a framed window - it doesn't need to have any
controls on it or anything.

Where would you display your context menu if you didn't have a window
to hang it off?
I'd have a window (not a form, a Windows window), which was created on
demand to service the context menu display. This can be done without a
main form in the application - and I'm sure many C++ applications using
MFC do exactly this.

Thanks to everyone for your help - it appears that I must have a form. I
just think that Microsoft have done such a wonderful job with .Net, but
they still insist on making you use a form when you don't want one. There
must be a better approach.
 
Back
Top