Application with optional GUI

B

Big Bob

I am trying to create a host application that will create a server, and then
optionally display a GUI element (controlled by a command line argument).
Here's what I've done so far:

1. Created a console application that creates the server (I started with a
windows application, but couldn't find any sort of "app" code where I could
add the conditional GUI code)
2. Switched the console application to be a "Windows Application" to remove
the console window
3. If the user has entered the /SHOWGUI command line prompt, popup a
modeless dialog
4. Show a system tray icon with a context menu, which contains a "Shutdown"
item
5. At the end of the Main() function, block until the user selects shutdown
on the context menu.

I'm having problems with the fifth item. I can't find a way to block that
doesn't also kill the GUI. Just waiting on a mutex makes the GUI
unresponsive. How do I block, but keep the message pump going? (Is there
still a message pump?)

In the olden MFC days, I'd just return TRUE from the InitiInstance override
and everything would run.

Thanks,

Aaron
 
P

Peter Huang [MSFT]

Hi Bob,
I'm having problems with the fifth item. I can't find a way to block that
doesn't also kill the GUI. Just waiting on a mutex makes the GUI
unresponsive. How do I block, but keep the message pump going? (Is there
still a message pump?)

I think if you run the GUI in the same thread as the Main function, then
when you block the Main function will also block the Message Pump.
That is to say, if you design your program as single thread one, when the
form is showed , your program will not exit.
static void Main(string[] args)
{
System.Windows.Forms.Application.Run(new Form1());
}

Did you do something like the code below?
If yes, then the application will run the From1, which will keep the
message pump going, and the Main function will run at the code line.
In this case, you do not need to block in the main function, because the
Main() will not exit until you close the Form1.

Did I misunderstand your meaning?
If you have any related question, please feel free to let me know.

I look forward to hearing from you.
Regards,
Peter Huang


Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
 
P

Peter Huang [MSFT]

Hi Bob,

In addition, I think you may run the Form1 but have it hidden, so that your
aim can be achieved.
You may hidden the Form by overridding following method of Form

protected override void OnActivated(System.EventArgs e)
{
Hide();
}


Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
X-Tomcat-ID: 86872967
References: <KjM6b.383591$o%2.172541@sccrnsc02>
MIME-Version: 1.0
Content-Type: text/plain
Content-Transfer-Encoding: 7bit
From: (e-mail address removed) (Peter Huang [MSFT])
Organization: Microsoft
Date: Tue, 09 Sep 2003 03:01:09 GMT
Subject: RE: Application with optional GUI
X-Tomcat-NG: microsoft.public.dotnet.framework
Message-ID: <[email protected]>
Newsgroups: microsoft.public.dotnet.framework
Lines: 86
Path: cpmsftngxa06.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework:53239
NNTP-Posting-Host: TOMCATIMPORT2 10.201.218.182

Hi Bob,
I'm having problems with the fifth item. I can't find a way to block that
doesn't also kill the GUI. Just waiting on a mutex makes the GUI
unresponsive. How do I block, but keep the message pump going? (Is there
still a message pump?)

I think if you run the GUI in the same thread as the Main function, then
when you block the Main function will also block the Message Pump.
That is to say, if you design your program as single thread one, when the
form is showed , your program will not exit.
static void Main(string[] args)
{
System.Windows.Forms.Application.Run(new Form1());
}

Did you do something like the code below?
If yes, then the application will run the From1, which will keep the
message pump going, and the Main function will run at the code line.
In this case, you do not need to block in the main function, because the
Main() will not exit until you close the Form1.

Did I misunderstand your meaning?
If you have any related question, please feel free to let me know.

I look forward to hearing from you.
Regards,
Peter Huang


Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
From: "Big Bob" <[email protected]>
Newsgroups: microsoft.public.dotnet.framework
Subject: Application with optional GUI
Lines: 30
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2600.0000
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000
Message-ID: <KjM6b.383591$o%2.172541@sccrnsc02>
NNTP-Posting-Host: 12.232.67.107
X-Complaints-To: (e-mail address removed)
X-Trace: sccrnsc02 1062965610 12.232.67.107 (Sun, 07 Sep 2003 20:13:30 GMT)
NNTP-Posting-Date: Sun, 07 Sep 2003 20:13:30 GMT
Organization: Comcast Online
Date: Sun, 07 Sep 2003 20:13:31 GMT
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!news-out.cwix.com!newsfeed.cwix.c
o
m!news.maxwell.syr.edu!wn14feed!wn13feed!wn11feed!worldnet.att.net!204.127.
1
98.203!attbi_feed3!attbi.com!sccrnsc02.POSTED!not-for-mail
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework:53159
X-Tomcat-NG: microsoft.public.dotnet.framework

I am trying to create a host application that will create a server, and then
optionally display a GUI element (controlled by a command line argument).
Here's what I've done so far:

1. Created a console application that creates the server (I started with a
windows application, but couldn't find any sort of "app" code where I could
add the conditional GUI code)
2. Switched the console application to be a "Windows Application" to remove
the console window
3. If the user has entered the /SHOWGUI command line prompt, popup a
modeless dialog
4. Show a system tray icon with a context menu, which contains a "Shutdown"
item
5. At the end of the Main() function, block until the user selects shutdown
on the context menu.

I'm having problems with the fifth item. I can't find a way to block that
doesn't also kill the GUI. Just waiting on a mutex makes the GUI
unresponsive. How do I block, but keep the message pump going? (Is there
still a message pump?)

In the olden MFC days, I'd just return TRUE from the InitiInstance override
and everything would run.

Thanks,

Aaron
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top