473,387 Members | 1,673 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

running an application in foreground?

Hello,

I have an executable file lanuched from another application.
is there a way to make thie executable file foreground if it is launched
from other application? Thanks.

Nov 17 '05 #1
7 2579
<on********@yahoo.com> wrote in message
news:u8**************@tk2msftngp13.phx.gbl...
I have an executable file lanuched from another application.
is there a way to make thie executable file foreground if it is launched
from other application? Thanks.


Check the docs for SwitchToThisWindow()

http://msdn.microsoft.com/library/de...thiswindow.asp

and read the remarks section for the caveats.

Regards,
Will
Nov 17 '05 #2
William DePalo [MVP VC++] wrote:
<on********@yahoo.com> wrote in message
news:u8**************@tk2msftngp13.phx.gbl...
I have an executable file lanuched from another application.
is there a way to make thie executable file foreground if it is launched
from other application? Thanks.

Check the docs for SwitchToThisWindow()

http://msdn.microsoft.com/library/de...thiswindow.asp

and read the remarks section for the caveats.


Will,

Thanks for the help.

I also find the function SetForegroundWindow().

My problem is that a1.exe launches a2.exe, and then a2.exe
launches a3.exe.

However, a3.exe cannot be displayed immediately.
Only after a2.exe is terminated, then a3.exe then can be displayed.
I think SetForegroundWindow() or SwitchToThisWindow() might be helpful,
but I am not sure if I should put this function in a3.exe or a2.exe?

Thanks.

Regards,
Will

Nov 17 '05 #3

<on********@yahoo.com> wrote in message
news:u8**************@tk2msftngp13.phx.gbl...
Hello,

I have an executable file lanuched from another application.
is there a way to make thie executable file foreground if it is launched
from other application? Thanks.


http://216.239.59.104/search?q=cache...rocessId&hl=sv

The trick is to use GetWindowThreadProcessId and AttachThreadInput

/Fredrik

Nov 17 '05 #4

<on********@yahoo.com> wrote in message
news:u8**************@tk2msftngp13.phx.gbl...
Hello,

I have an executable file lanuched from another application.
is there a way to make thie executable file foreground if it is launched
from other application? Thanks.

+void ReallySetForegroundWindow( HWND ahWnd )
+{
+ DWORD foregroundThreadID; // foreground window thread
+ DWORD ourThreadID; // our active thread
+ static char foo[1024];
+ HWND h = GetForegroundWindow();
+
+ // If the window is in a minimized state, maximize now
+ if (GetWindowLong(ahWnd, GWL_STYLE) & WS_MINIMIZE)
+ {
+ ShowWindow(ahWnd, SW_MAXIMIZE);
+ UpdateWindow(ahWnd);
+ }
+
+ // Check to see if we are the foreground thread
+ foregroundThreadID = GetWindowThreadProcessId(GetForegroundWindow(),
NULL);
+ ourThreadID = GetCurrentThreadId();
+
+ // If not, attach our thread's 'input' to the foreground thread's
+ if (foregroundThreadID != ourThreadID)
+ AttachThreadInput(foregroundThreadID, ourThreadID, TRUE);
+
+ // Bring our window to the foreground
+ SetForegroundWindow(ahWnd);
+
+ // Set focus.
+ SetFocus( ahWnd );
+
+ // If we attached our thread, detach it now
+ if (foregroundThreadID != ourThreadID)
+ AttachThreadInput(foregroundThreadID, ourThreadID, FALSE);
+
+ // Force our window to redraw
+ InvalidateRect(ahWnd, NULL, TRUE);
+}/Fredrik

Nov 17 '05 #5
Fredrik Wahlgren wrote:
<on********@yahoo.com> wrote in message
news:u8**************@tk2msftngp13.phx.gbl...
Hello,

I have an executable file lanuched from another application.
is there a way to make thie executable file foreground if it is launched
from other application? Thanks.


+void ReallySetForegroundWindow( HWND ahWnd )
+{
+ DWORD foregroundThreadID; // foreground window thread
+ DWORD ourThreadID; // our active thread
+ static char foo[1024];
+ HWND h = GetForegroundWindow();
+
+ // If the window is in a minimized state, maximize now
+ if (GetWindowLong(ahWnd, GWL_STYLE) & WS_MINIMIZE)
+ {
+ ShowWindow(ahWnd, SW_MAXIMIZE);
+ UpdateWindow(ahWnd);
+ }
+
+ // Check to see if we are the foreground thread
+ foregroundThreadID = GetWindowThreadProcessId(GetForegroundWindow(),
NULL);
+ ourThreadID = GetCurrentThreadId();
+
+ // If not, attach our thread's 'input' to the foreground thread's
+ if (foregroundThreadID != ourThreadID)
+ AttachThreadInput(foregroundThreadID, ourThreadID, TRUE);
+
+ // Bring our window to the foreground
+ SetForegroundWindow(ahWnd);
+
+ // Set focus.
+ SetFocus( ahWnd );
+
+ // If we attached our thread, detach it now
+ if (foregroundThreadID != ourThreadID)
+ AttachThreadInput(foregroundThreadID, ourThreadID, FALSE);
+
+ // Force our window to redraw
+ InvalidateRect(ahWnd, NULL, TRUE);
+}/Fredrik

I tried the above code, and the function SwitchToThisWindow(). It
doesn't help. My problem is that I have a1.exe calls a2.exe, and a2.exe
calls a3.exe. a3.exe is a GUI application, it is not started untill I
kills a1.exe. I am not sure if there is a way to bring a3.exe to the
foreground and make it run without killing a1.exe?

Thanks.

Nov 17 '05 #6
<on********@yahoo.com> wrote in message
news:Os**************@TK2MSFTNGP14.phx.gbl...
Thanks for the help.
You are welcome.
I also find the function SetForegroundWindow().
It works on '95 and NT4. It has been intentionally crippled on 98/Me/2K/XP
and 2K+3.
My problem is that a1.exe launches a2.exe, and then a2.exe
launches a3.exe.
However, a3.exe cannot be displayed immediately.
Only after a2.exe is terminated, then a3.exe then can be displayed.
I think SetForegroundWindow() or SwitchToThisWindow() might be helpful,
but I am not sure if I should put this function in a3.exe or a2.exe?


If you must, try calling SwitchToThisWindow() in a3 passing the handle of
its main window.

Note that many people, including me, will immediately uninstall an
application which "steals" the forreground. The bad behavior of so many
applications that did this is the reason why SetForegroundWindow() has been
crippled and why SwitchToThisWindow() is on its way out.

Regards,
Will
Nov 17 '05 #7
William DePalo [MVP VC++] wrote:
<on********@yahoo.com> wrote in message
news:Os**************@TK2MSFTNGP14.phx.gbl...
Thanks for the help.

You are welcome.

I also find the function SetForegroundWindow().

It works on '95 and NT4. It has been intentionally crippled on 98/Me/2K/XP
and 2K+3.

My problem is that a1.exe launches a2.exe, and then a2.exe
launches a3.exe.
However, a3.exe cannot be displayed immediately.
Only after a2.exe is terminated, then a3.exe then can be displayed.
I think SetForegroundWindow() or SwitchToThisWindow() might be helpful,
but I am not sure if I should put this function in a3.exe or a2.exe?

If you must, try calling SwitchToThisWindow() in a3 passing the handle of
its main window.

Note that many people, including me, will immediately uninstall an
application which "steals" the forreground. The bad behavior of so many
applications that did this is the reason why SetForegroundWindow() has been
crippled and why SwitchToThisWindow() is on its way out.


I have an applicaiton a1.exe calls a2.exe, a2.exe calls a3.exe.
I have to kill a1.exe and then a3.exe will run.
I added SwitchToThisWindow() on a3.exe, I still need to kill a1.exe to
get a3.exe to run. Not sure how to fix this problem.

If used notepad.exe to
replace a3.exe, I find that I can run a3.exe without the need to kill
a1.exe.

Not sure if there are some tricks over there?

Thanks.



Regards,
Will

Nov 17 '05 #8

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

Similar topics

1
by: wesley | last post by:
Hello, How do I pass object to the current running process? For example my assembly is called program.exe. Once program.exe is running sometime I want to call it again ie: program.exe /m...
5
by: oran johnson | last post by:
If Form.TopMost = true, will the form appear even if the associated application is not the active or foreground application? Thanks.
5
by: Publicjoe | last post by:
I am working on a little app which uses colour in the console window. I have created a class to extend the console functionality but the ClearScreen method does not work correctly. I am enclosing a...
3
by: kill.segfault | last post by:
hi, I am working with a ICA32 citrix client from windows xp, where I am trying to use some automation through citrix client so that I can unmann a tedious file-copy through one of the published...
1
by: daniel_xi | last post by:
Hi all, I am running a VS 2003 .NET project on my client machine (Win 2000 SP4, ..NET framework 1.1), running an ASP.NET application on a remote web server (Win 2000 Server, IIS 6.0, .NET...
6
by: Jen | last post by:
I've implemented single-instance functionality in my .exe by using the mutex method. Works great. But when the .exe detects that it is not the first instance I want to bring the main window of...
17
by: Bodyboarder20 | last post by:
Hello! So im working on an applicaiton that all pretty much sits on a single form. When the application completes a task, I'd like it to use FlashWindow() to notify the user that it has...
0
by: monty0018 | last post by:
Hi, I'm writing a custom clipboard application in VB .NET 2008 similar to Ditto (http://ditto-cp.sourceforge.net/). I have tried targeting .NET Frameworks 2.0, 3.0, and 3.5 with the same...
5
by: aagarwal8 | last post by:
Hi, I have a windows form application, where the requirement is as follows... If the application is already running, and the user tries to open another instance of the application, the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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,...

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.