running an application in foreground?

  • Thread starter Thread starter one2001boy
  • Start date Start date
O

one2001boy

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.
 
William said:
Check the docs for SwitchToThisWindow()

http://msdn.microsoft.com/library/d...erence/windowfunctions/switchtothiswindow.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.
 
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
 
Fredrik said:
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.
 
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
 
William said:
You are welcome.




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




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.
 
Back
Top