473,666 Members | 2,382 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

unhide window

Hi all,

how can I set an app's main window to visible from an other application?
My problem is, that I know only the handle of the other app's main
process, because the application's main window is set to hidden, so it
doesn't have a mainwindowHandl e, so I can't send a message to it.

Any idea?

Thank's in advance,

Tamas Meszaros
Nov 17 '05 #1
8 11525
> because the application's main window is set to hidden, so it doesn't have a mainwindowHandl e

The main window of an application cannot be "hidden" if it doesn't exist. If the app has a main window, that is not visible, then
it still has a handle.

To set the visibility of a window in another process using the handle of the window:

/// <summary>Sets the visibility of a window. This method allows one process to set the visiblity of a window owned by another
process.</summary>
/// <param name="cmd">SW_S HOW = 5, SW_HIDE = 0</param>
[System.Runtime. InteropServices .DllImport("use r32.dll", SetLastError=tr ue)]
static extern bool ShowWindowAsync (IntPtr windowHandle, int cmd);
/// <summary>

/// Async version allows show window cross-process.

/// </summary>

[DllImport("user 32.dll", SetLastError = true)]

private static extern bool ShowWindowAsync (IntPtr window, int cmd);
--
Dave Sexton
dave@www..jwaon line..com
-----------------------------------------------------------------------
"Mészáros Tamás" <me*****@sch.bm e.hu> wrote in message news:eB******** ******@TK2MSFTN GP15.phx.gbl...
Hi all,

how can I set an app's main window to visible from an other application? My problem is, that I know only the handle of the other
app's main process, because the application's main window is set to hidden, so it doesn't have a mainwindowHandl e, so I can't send
a message to it.

Any idea?

Thank's in advance,

Tamas Meszaros

Nov 17 '05 #2
So, I try the following:

string proc=Process.Ge tCurrentProcess ().ProcessName;
Process[] processes=Proce ss.GetProcesses ByName(proc);
if (processes.Leng th > 1)
{
Process p=Process.GetCu rrentProcess();
int n=0;
if (processes[0].Id==p.Id)
{
n=1;
}
IntPtr hWnd=processes[n].MainWindowHand le;
...
}

But hWnd = 0, if the MainWindow is invisible, so I can't send a message
to it.

(My target is to show a previously launched instance of an application
if I try to start again. And this window can be hidden, not only minimized).

thanks

Tamas
Dave wrote:
because the application's main window is set to hidden, so it doesn't have a mainwindowHandl e

The main window of an application cannot be "hidden" if it doesn't exist. If the app has a main window, that is not visible, then
it still has a handle.

To set the visibility of a window in another process using the handle of the window:

/// <summary>Sets the visibility of a window. This method allows one process to set the visiblity of a window owned by another
process.</summary>
/// <param name="cmd">SW_S HOW = 5, SW_HIDE = 0</param>
[System.Runtime. InteropServices .DllImport("use r32.dll", SetLastError=tr ue)]
static extern bool ShowWindowAsync (IntPtr windowHandle, int cmd);
/// <summary>

/// Async version allows show window cross-process.

/// </summary>

[DllImport("user 32.dll", SetLastError = true)]

private static extern bool ShowWindowAsync (IntPtr window, int cmd);

Nov 17 '05 #3
> But hWnd = 0, if the MainWindow is invisible, so I can't send a message to it.

No, hWnd is 0 if the MainWindow doesn't exist. It has not been created, or it was destroyed instead of being hidden.

The only way to show the window again is to recreate it.

--
Dave Sexton
dave@www..jwaon line..com
-----------------------------------------------------------------------
"Mészáros Tamás" <me*****@sch.bm e.hu> wrote in message news:e2******** ******@TK2MSFTN GP09.phx.gbl...
So, I try the following:

string proc=Process.Ge tCurrentProcess ().ProcessName;
Process[] processes=Proce ss.GetProcesses ByName(proc);
if (processes.Leng th > 1)
{
Process p=Process.GetCu rrentProcess();
int n=0;
if (processes[0].Id==p.Id)
{
n=1;
}
IntPtr hWnd=processes[n].MainWindowHand le;
...
}

But hWnd = 0, if the MainWindow is invisible, so I can't send a message to it.

(My target is to show a previously launched instance of an application if I try to start again. And this window can be hidden, not
only minimized).

thanks

Tamas
Dave wrote:
because the application's main window is set to hidden, so it doesn't have a mainwindowHandl e

The main window of an application cannot be "hidden" if it doesn't exist. If the app has a main window, that is not visible,
then it still has a handle.

To set the visibility of a window in another process using the handle of the window:

/// <summary>Sets the visibility of a window. This method allows one process to set the visiblity of a window owned by another
process.</summary>
/// <param name="cmd">SW_S HOW = 5, SW_HIDE = 0</param>
[System.Runtime. InteropServices .DllImport("use r32.dll", SetLastError=tr ue)]
static extern bool ShowWindowAsync (IntPtr windowHandle, int cmd);
/// <summary>

/// Async version allows show window cross-process.

/// </summary>

[DllImport("user 32.dll", SetLastError = true)]

private static extern bool ShowWindowAsync (IntPtr window, int cmd);


Nov 17 '05 #4
It's sure, it exists, I've only called a Hide() method on it, and hWnd
is 0 (I've tried it).

Can I catch messages somehow, which are sent to the process handle?
(wndproc handles messages sent to the window handle only)

thanks

Tamas
Dave wrote:
But hWnd = 0, if the MainWindow is invisible, so I can't send a message to it.

No, hWnd is 0 if the MainWindow doesn't exist. It has not been created, or it was destroyed instead of being hidden.

The only way to show the window again is to recreate it.

Nov 17 '05 #5
I just looked at your code to access the process that you posted earlier. It seems your attempting to acquire the current process:
Process p=Process.GetCu rrentProcess();
Why not just use Process.GetCurr entProcess().Ma inWindowHandle?
I don't understand how that is useful. Isn't your code running in the main form?
It's sure, it exists, I've only called a Hide() method on it, and hWnd is 0 (I've tried it).
What did you try? A handle of 0 (zero) means that no window exists. (period).

Can I catch messages somehow, which are sent to the process handle?
(wndproc handles messages sent to the window handle only)
I believe you have to use Hooks for that... Check out MSDN for the Windows API functions pertaining to Messaging and Hooks. You'll
have to use interop.

You can use Spy++ to monitor messages sent to a window (tool that ships with C++).
--
Dave Sexton
dave@www..jwaon line..com
-----------------------------------------------------------------------
"Mészáros Tamás" <me*****@sch.bm e.hu> wrote in message news:Od******** *****@TK2MSFTNG P10.phx.gbl... It's sure, it exists, I've only called a Hide() method on it, and hWnd is 0 (I've tried it).

Can I catch messages somehow, which are sent to the process handle?
(wndproc handles messages sent to the window handle only)

thanks

Tamas
Dave wrote:
But hWnd = 0, if the MainWindow is invisible, so I can't send a message to it.

No, hWnd is 0 if the MainWindow doesn't exist. It has not been created, or it was destroyed instead of being hidden.

The only way to show the window again is to recreate it.

Nov 17 '05 #6
> I just looked at your code to access the process that you posted
earlier. It seems your attempting to acquire the current process:
Process p=Process.GetCu rrentProcess();

Why not just use Process.GetCurr entProcess().Ma inWindowHandle?
I don't understand how that is useful. Isn't your code running in

the main form?

I use GetCurrentProce ss( ).Processname to determine the name of the
process. Then I look for other running processes whit the same name. If
any other process exists whit the same name, then I would like to set
that other window visible, and close this one.

So I don't want to allow to run two instances from the same application.
When I try to execute the second one, I would like to set the first
one visible, and exit the second one.
It's sure, it exists, I've only called a Hide() method on it, and

hWnd is 0 (I've tried it).What did you try? A handle of 0 (zero) means that no window exists.

(period).

I started the application, then started an other instance of it, and the
second one could realize the windowhandle of the first one. Then I hid
the first app's main window (with Form.Hide( )), looked for the window
handle of it, but it was 0. I've tried "third party" applications as
well, and they found the handle to bo 0 as well. So if a window is
hidden, it seems not to have a windowhandle.

Tamas

Nov 17 '05 #7
If your want to ensure that only a single instance of your application may be executed at any given time, then use a Mutex object,
which can be shared across-process boundaries as a singleton:

private static Mutex SingleInstanceM utex;

/// <summary>Dispos es the mutex object that ensures only a single instance of this application will execute at any given
time.</summary>
private static void SingleInstanceP rocess_Exited(o bject sender, EventArgs e)
{
if (SingleInstance Mutex != null)
SingleInstanceM utex.Close();
}

public static void Main()
{
Process process = Process.GetCurr entProcess();
bool createdNew;
SingleInstanceM utex = new Mutex(true, process.Process Name, out createdNew);

if (createdNew)
process.Exited+ = new EventHandler(Si ngleInstancePro cess_Exited);
else
// Allow only a single instance of the app to execute
process.Kill();
}
So if a window is hidden, it seems not to have a windowhandle.


Incorrect. I attempted to reproduce the behavior your experiencing and I've done so with success. Take this code for example:

CheckHiddenHand leForm form = new CheckHiddenHand leForm();

Console.WriteLi ne("Show Form...");

form.Show();
System.Windows. Forms.Applicati on.DoEvents();

Console.WriteLi ne("\tMainWindo wHandle: {0}", Process.GetCurr entProcess().Ma inWindowHandle) ;
Console.WriteLi ne("\tForm.Hand le: {0}", form.Handle);

Console.WriteLi ne("Hide Form...");

form.Hide();
System.Windows. Forms.Applicati on.DoEvents();

Console.WriteLi ne("\tMainWindo wHandle: {0}", Process.GetCurr entProcess().Ma inWindowHandle) ;
Console.WriteLi ne("\tForm.Hand le: {0}", form.Handle);

Console.WriteLi ne("Close Form...");

form.Close();
System.Windows. Forms.Applicati on.DoEvents();

Console.WriteLi ne("\tMainWindo wHandle: {0}", Process.GetCurr entProcess().Ma inWindowHandle) ;
Outputs the following results to the Console window:
Show Form...
MainWindowHandl e: 5308896 -- MainWindowHandl e
Form.Handle: 5308896 -- Notice that the Form.Handle is the MainWindowHandl e
Hide Form...
MainWindowHandl e: 0 -- there is no longer a Main window for the process since the Form has been hidden
Form.Handle: 5308896 -- *** The window still has a handle ***
Close Form...
MainWindowHandl e: 0 -- The window is now disposed (Form.Handle is now inaccessible and assumed
IntPtr.Zero)
Press any key to continue
As you can see, the window still has a handle, however, once it is hidden it is no longer the "MainWindow " of the process. You may
have to use Windows API calls to obtain the handle to the window, or just ignore it because it's hidden. That's what you're
attempting to accomplish anyway, correct?

I suggest looping through all of the processes with the same name if you do not want to ensure a single instance of the app using
the Mutex in my code example above. If the process Id is not of the current process, AND the MainWindowHandl e is not IntPtr.Zero
then use my Interop code I supplied to you in a previous post to show the window.

GL

--
Dave Sexton
dave@www..jwaon line..com
-----------------------------------------------------------------------
"Mészáros Tamás" <me*****@sch.bm e.hu> wrote in message news:%2******** *******@TK2MSFT NGP10.phx.gbl.. .
I just looked at your code to access the process that you posted

earlier. It seems your attempting to acquire the current process:
Process p=Process.GetCu rrentProcess();

Why not just use Process.GetCurr entProcess().Ma inWindowHandle?
I don't understand how that is useful. Isn't your code running in

the main form?

I use GetCurrentProce ss( ).Processname to determine the name of the process. Then I look for other running processes whit the same
name. If any other process exists whit the same name, then I would like to set that other window visible, and close this one.

So I don't want to allow to run two instances from the same application. When I try to execute the second one, I would like to set
the first one visible, and exit the second one.
It's sure, it exists, I've only called a Hide() method on it, and

hWnd is 0 (I've tried it).
What did you try? A handle of 0 (zero) means that no window exists.

(period).

I started the application, then started an other instance of it, and the second one could realize the windowhandle of the first
one. Then I hid the first app's main window (with Form.Hide( )), looked for the window handle of it, but it was 0. I've tried
"third party" applications as well, and they found the handle to bo 0 as well. So if a window is hidden, it seems not to have a
windowhandle.

Tamas

Nov 17 '05 #8
As you can see, the window still has a handle, however, once it is hidden it is no longer the "MainWindow " of the process.


That's what I didn't know till now. But everything is clear now!

Thank's a lot for your help

Tamas
Nov 17 '05 #9

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

Similar topics

2
18368
by: Peter K | last post by:
How do I Hide/Unhide the Main Database Window in VB?
4
7074
by: caimito | last post by:
Hello to the group. I have been unsuccessful at unhiding the database window via code. The most I have gotten is to open the unhide dialogue from a command button on a form, but then I still have to select the datbase from the dialogue box and click unhide. Is there a more direct method via code? I use access 2000 but am transitioning to access 2003.
7
2004
by: MLH | last post by:
Is there any case you can imagine that A97 would NOT display the Unhide option under the Window menu after running this line... Me.Visible = False Yes, its happening to me. The Unhide choice is grayed out after running this line on a form that was opened with the acDialog parm. Guys, this wierd stuff I'm encountering, could some hardware issue be responsible or would a viral element be more likely at fault?
5
1819
by: MLH | last post by:
I used this line in A2.0 to unhide the database window: DoCmd.DoMenuItem A_FORMBAR, 4, 4, 0, A_MENU_VER20 Although it will work in A97, it will also unhide anything else that's hidden on each successive run. Is there a more specific command syntax to unhide a given form (or the database window)?
4
3663
by: g3000 | last post by:
I have seen examples of hiding and showing a div What I want to do is have a table with six columns. The sixth column is a check box to Unhide a div that is a form. I want it to show on top of the table to enter in comments. Then click submit in the div form and hide the div. Pop up window is not what I want. I dont want the window like border. Almost like a floating frame in the middle of the table.
5
1814
by: victorcamp | last post by:
Applications I work with routinely hide the database window on Startup, which, once open, return this value: CurrentDb.Properties! = False During maintenance, I use a special keystroke to close the main form and leave me in the DB Window, but I always have to then unhide it before I can work. I can use this to bring up the Unhide dialog box, but I still have to hit enter to OK the action: DoCmd.RunCommand acCmdWindowUnhide
3
2790
by: toodi4 | last post by:
I'm using a javascript that hides and unhides text based on a button click. It works great across static fields on a form. The problem I have is that I'm trying to hide and unhide various fields that are populated on the page by a database. In other words, sometimes there are 4 fields, sometimes 6. I've used various scripts for the hide/unhide function. This is one I'm using now that I've copied from another source: <script...
3
2433
by: =?Utf-8?B?aWxy?= | last post by:
Hi All I am developing an vb 2005 winforms application that connects to a database and displays a datagridview of the data. A user can select and then edit, or create a new entry by opening a modal form and editing the record. I would like the user to be able to hide either the parent form or the parent and modal form if they are currently editing in the modal form and unhide the parent or both forms from the notification icon. I seem...
1
5779
by: Simon | last post by:
Dear reader, In a datasheet form you have the possibility to hide or unhide columns. But in case the datasheet form is a sub-form this functionality is not longer available.
0
8352
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8863
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8780
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8549
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6189
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5661
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4192
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4358
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2005
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.