ShellExecute

Hi,

I use ShellExecute to open an application:

ShellExecuteW(hwndMain, L"open", L"C:\\ApplicationA.exe", L"C:\\MyFile.doc", NULL, SW_SHOW);

It opens the file and it seems to be activated. But it is still shown under my previous document. Let's say: I am using Internet Explorer and then my program launch the file (MyFile.doc) when I click on a button. MyFile.doc is opened and it is activated, but what is on the top is still the Internet Explorer window. What can I do so that when MyFile.doc is opened, it is always on the top of all other windows?

Thanks very much.
[610 byte] By [samallis] at [2007-11-20 1:11:27]
# 1 Re: ShellExecute
Not sure it will help (cause I never tested it), but try to change the last parameter from SW_SHOW to SW_SHOWNORMAL.
VictorN at 2007-11-10 23:19:18 >
# 2 Re: ShellExecute
Not sure it will help (cause I never tested it), but try to change the last parameter from SW_SHOW to SW_SHOWNORMAL.

I tried it already, it doesn't work :(
samallis at 2007-11-10 23:20:18 >
# 3 Re: ShellExecute
Is the ApplicationA.exe that you launch is your application? Do you have the source code? Or its a third party application?

Cheers
golanshahar at 2007-11-10 23:21:11 >
# 4 Re: ShellExecute
Is the ApplicationA.exe that you launch is your application? Do you have the source code? Or its a third party application?

Cheers

There are a few applications that I want to call. Some of them are my own application, but others are not.

In my own application (ApplicationA.exe), I have added SetForegroundWindow, but it doesn't appear on the top as well when the window is opened. But the difference is, when the application A is opened, it is activated and on the below of the screen (where we have the Start menu, quick launch icons, etc.), my application A is flashing until I click on its window.

In short, the window is still not on the top.
samallis at 2007-11-10 23:22:16 >
# 5 Re: ShellExecute
The following makes sure that while restoring the app correctly gains the focus and doesn't flash in taskbar...

//Attach foreground window thread
//to our thread
AttachThreadInput(
GetWindowThreadProcessId(
::GetForegroundWindow(), NULL),
GetCurrentThreadId(), TRUE);

SetForegroundWindow();

SetFocus();

//Detach the attached thread
AttachThreadInput(
GetWindowThreadProcessId (
::GetForegroundWindow(), NULL),
GetCurrentThreadId(), FALSE);

See if it solves your problem.
logan at 2007-11-10 23:23:21 >
# 6 Re: ShellExecute
There are a few applications that I want to call. Some of them are my own application, but others are not.

In my own application (ApplicationA.exe), I have added SetForegroundWindow, but it doesn't appear on the top as well when the window is opened. But the difference is, when the application A is opened, it is activated and on the below of the screen (where we have the Start menu, quick launch icons, etc.), my application A is flashing until I click on its window.

In short, the window is still not on the top.

If its your application you can try calling ::BringWindowToTop() (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/windowing/windows/windowreference/windowfunctions/bringwindowtotop.asp) from inside the ApplicationA.exe.

Cheers
golanshahar at 2007-11-10 23:24:15 >