473,503 Members | 2,159 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Show a Hidden Form?

I have an application. When a user minimizes it it hides itselfs but stays activate in the system tray. Since it is hidden the user may think that they have exited the application and now may attempt to create a new instance by launching the program again. The problem that I am running into is being able to restore the previous application. I am able to end the multiple instance application but since the previous application is hidden I cannot find a way to 'show' previous application
Any suggestions? I need an answer fast.
Nov 16 '05 #1
5 13280
Maybe I am missing the point, however, in Properties you have the option
"showIn Taskbar". The user will be able to maximize the screen from there.
Second, you are worried that the form is still active, so why not close one
form when the other is opened. Then when the user needs it again he'll just
open it again.
Patrick.

*************************
"Susan" <an*******@discussions.microsoft.com> wrote in message
news:FB**********************************@microsof t.com...
I have an application. <skipped>

Nov 16 '05 #2
The form in the first instance of the application is hidden, and runs in the background. I do not want two instances running, so when a user tries to open a second instance, I want to bring up the hidden form from the first instance, and close the second. I just have no idea how to show that form from the code in the second instance (the application runs the mulitple instance code on startup). The other option that I have is to close the first instance, and bring up the second, but I don't know how to do that either. I am currently researching how to kill a process, hoping that will do the trick.
Nov 16 '05 #3
Hi Susan

There are two separated issues in your post, how to detect that a previous
instance is running and how to send a message to another windows to make it
the foremost window.

1- Detect a previous instance:
You can use several techniques, basically ALL of them involve the creation
of a unique object, you can use a Mutex for example, or search by process
name. if you do a search in the archives of this NG you will find several
suggestions as this is an issue that is constantly asked.

2- All you need is the handle of the main windows of the other isntance, you
get it using Process.MainWindowHandle

Here is some code I have used

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

//yyou need this namespace
using System.Runtime.InteropServices;
// P/invoke declarations
public class Form1 : System.Windows.Forms.Form
{
//I search by process name
static public Process FindParallelProcess()
{

string currentprocname = Process.GetCurrentProcess().ProcessName;
foreach( Process process in Process.GetProcessesByName(
currentprocname) )
{
if ( process.Id != Process.GetCurrentProcess().Id )
return process;
}
return null;

}
[DllImport("user32.dll",EntryPoint="SetForegroundWi ndow")]
public static extern bool SetForegroundWindow(IntPtr hWnd);

//Detection
static void Main()
{

Process previous = Form1.FindParallelProcess();
if ( previous == null )
Application.Run(new Form1());
else
{
//Give the focus to the other instance
SetForegroundWindow( previous.MainWindowHandle);
}
}

"Susan" <an*******@discussions.microsoft.com> wrote in message
news:FB**********************************@microsof t.com...
I have an application. When a user minimizes it it hides itselfs but stays activate in the system tray. Since it is hidden the user may think
that they have exited the application and now may attempt to create a new
instance by launching the program again. The problem that I am running into
is being able to restore the previous application. I am able to end the
multiple instance application but since the previous application is hidden I
cannot find a way to 'show' previous application. Any suggestions? I need an answer fast.

Nov 16 '05 #4
Thanks. But the SetForegroundWindow will not work, because the form is hidden. I can make it work all day long, if the UI is visible, but after it is hidden, SetForegroundWindow doesn't work. That is why I need to know first how to make that form visible again, before I call the SetForegroundWindow. I am so confused with this right now. Do you know anything about Killing a process? If I can't make the first instance visible, I can close it, and let the second instance come up. All the examples I find declare variables as process, and that will not compile for me. I am beginning to think that I am just an idiot, lol.
Nov 16 '05 #5
Hi Susan,
How are you hidding the form?

Now that I think about it I have never use SetForegroundWindow from another
application to show a form I had call hidden on.

Now , I do know that if you call Show from the same application it does
show again.

IF that is the case then what you can do is send a message to the hidden
application, the target application get the message and call the Show method
as needed.
Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Susan" <an*******@discussions.microsoft.com> wrote in message
news:88**********************************@microsof t.com...
Thanks. But the SetForegroundWindow will not work, because the form is

hidden. I can make it work all day long, if the UI is visible, but after it
is hidden, SetForegroundWindow doesn't work. That is why I need to know
first how to make that form visible again, before I call the
SetForegroundWindow. I am so confused with this right now. Do you know
anything about Killing a process? If I can't make the first instance
visible, I can close it, and let the second instance come up. All the
examples I find declare variables as process, and that will not compile for
me. I am beginning to think that I am just an idiot, lol.
Nov 16 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
2288
by: Jack | last post by:
I want to display a table on a page based on whether a button is pressed or not. I'm new at php so I'm sure I'm making a basic mistake. Here's what I am trying. My thought was that $show_summary...
13
73970
by: genetic.error | last post by:
I'm moving from Vb6 to VB.Net. I have a feeling this has come up before... The VS.Net MSDN file seems to state that the following should work: Form1.Show Form1.Visible = True Form1.Hide...
9
2737
by: sergio | last post by:
Hi all, I have created the following script that will show/hide a menu based on checkboxes. It works fine in Opera but not on IE6! Does anybody knows a workaround this problem? Thanks for your...
5
2160
by: Zambien | last post by:
Hi all, Here's my problem. I have tables that are using the menu/submenu idea for hiding rows. This works fine in IE (of course) and does show/hide correctly in netscape, but as soon as the...
3
10174
by: veganeater | last post by:
Hi, I'm wondering if there's a way that I can select which <div> to show based on the user's selection from a dropdown/listbox form. <form name="form1" method="post" action=""> <select...
4
7981
by: jerryyang_la1 | last post by:
I've found this script that allows be to hide/show form elements.. <script language="JavaScript"><!-- var toggle = true; function show(object) { if (document.layers && document.layers)...
1
1898
by: Richard | last post by:
Hello there, I have a form that is called from a Sub Main procedure using application.run(Form1). On my main form there is a button to open an instance of Form2 and then at the same time hide...
3
6369
by: Merlin | last post by:
Hi there, I am trying to create a form with an dynamic field that can be shown or hidden. As I saw for example on google it is possible with JS to show a layer and move the content underneath...
0
2058
by: BcNexus | last post by:
Hello all, The search function of this forum isn't working although I found a similar question on the forum using Google, but the replies don't help me. So, forgive me please if this has been...
0
7205
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7287
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7467
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5592
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5021
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3175
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3166
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1519
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
397
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.