joe_pool_is Posted April 16, 2008 Posted April 16, 2008 We've got an old application that has been modified quite a bit. Originally, it was just a single form application that hid in the TaskBar Tray using a Notify Icon. Later, we had to add a Custom Dialog Box to the project. Now, it has been determined that the project would be best served by the Dialog Box only, and eliminate the main form. So, the project is now a Console-like Application that starts with a Main Module. The Notify Icon had to be included with the Dialog Box, otherwise we weren't able to make it work. The NotifyIcon has a Context Menu Strip and events for Click and Double Click. When the Main Module starts, it creates a new instance of the Dialog Box, but does not show it. When the Dialog Box is created, it creates and shows the Notify Icon. If you are still reading this, here is the problem: Unless the Dialog Box is being displayed (dialog1.ShowModal), all the Notify Icon will do is show its Balloon Message. The Click, Double Click, and Context Menu Strip does not react at all. Any idea why? How would I get this to work? Quote Avoid Sears Home Improvement
Leaders snarfblam Posted April 16, 2008 Leaders Posted April 16, 2008 It sounds like you are no longer running your application like a Windows Forms application. One of the biggest differences between a console application and a Windows Forms application (other than the latter having windows) is that a console application doesn't have a "message pump," the program's main loop that processes events and messages from Windows. Without this message pump, your application may not be able to properly interact with Windows or the user (hence the problems you've been having with the NotifyIcon). Since you are loading a Form right off the bat, why not just run your application like a normal Windows Forms application (except don't show the window until it's needed). If you don't want to or can't do that, your best bet would be to create a message pump using a variant of that of a Windows Forms app, something like so: C# Code[HorizontalRule]magic hidden text[/HorizontalRule]// Manages our program for us static class Program { ····static ApplicationContext appContext; ····[STAThread] ····static void Main() { ········// Set us up the program ········appContext = new ApplicationContext(); ········Application.EnableVisualStyles(); ········// Start the message pump ········Application.Run(appContext); ····} ····// Call this method to close the application ····public static void EndApplication() { ········// It might be a good idea to store a reference to your ········// dialog and notify icon in the program class and make ········// sure that they are disposed here. ········appContext.ExitThread(); ····} }[HorizontalRule]Why are you quoting me?[/HorizontalRule] Quote [sIGPIC]e[/sIGPIC]
joe_pool_is Posted April 16, 2008 Author Posted April 16, 2008 You are a coding fool, Marble Eater. Are you really only 23? Anyway, thanks for the tip! I was trying to get out of duplicating my Dialog Box onto a new form, but will probably solve my problem (and others that might creep in) easiest. Quote Avoid Sears Home Improvement
Leaders snarfblam Posted April 17, 2008 Leaders Posted April 17, 2008 I am 23. It's not a lie. And while I try to figure out whether I was just insulted or complimented, hopefully you will get your program up and running. Quote [sIGPIC]e[/sIGPIC]
joe_pool_is Posted April 18, 2008 Author Posted April 18, 2008 No insults. Just commenting on how obviously you love your work. It's a good thing! Quote Avoid Sears Home Improvement
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.