Hiding the main app window created by ShellExecuteEx?
-
Hi, I have launched an executable from my program using ShellExecuteEx(). However, I want this program initially to run in the background in a hidden state. Setting the nShow property of the SHELLEXECUTEINFO structure to SW_HIDE in this instance doesn't work - presumably because the launched program won't allow it (in accordance with what it says on MSDN, ie. that this info is passed to the program but it's up to the program how to use it). Thus, I guess I need to explicitly call ShowWindow with SW_HIDE set to hide the window created. The problem is, how do I do this effectively, so that the main window of the program launched is hidden from the very start? At the moment I am using FindWindow(), like this:
ShellExecuteEx(&app); HWND app_hWnd; while(app_hWnd == 0) //loop until app window is found { //if there is an error and the app closes, leave loop: if(WaitForSingleObject(app.hProcess,0)==WAIT_TIMEOUT) { ShowWindow((app_hWnd = FindWindow("app_mainwin",NULL)),SW_HIDE); //Ensure loading window is updated if anything happens in the meantime: if(PeekMessage(&msg,NULL,0,0,PM_REMOVE)) { TranslateMessage(&msg); DispatchMessage(&msg); } } else {break;} //if app has quit (eg. error), exit loop so we can end the program normally }
This isn't a great solution, though, as the launched program window is shown for a couple of seconds before FindWindow() and ShowWindow() catch it and hide it. Does anybody know of a better way of doing this, so that the launched application window is not shown at all until I call ShowWindow again with SW_SHOW? ...Talking of which, I have a secondary problem relating to this. When I do call ShowWindow(app_hWnd,SW_SHOW) to restore the window, even after the window is shown again, it does not appear in the taskbar until I alt-tab out of it and back in again. How do I ensure that a program's window is restored to the taskbar on re-showing it? (I have tried SW_RESTORE, SW_SHOWNORMAL etc...) Any suggestions or help much appreciated, as always. Many thanks, KB -
Hi, I have launched an executable from my program using ShellExecuteEx(). However, I want this program initially to run in the background in a hidden state. Setting the nShow property of the SHELLEXECUTEINFO structure to SW_HIDE in this instance doesn't work - presumably because the launched program won't allow it (in accordance with what it says on MSDN, ie. that this info is passed to the program but it's up to the program how to use it). Thus, I guess I need to explicitly call ShowWindow with SW_HIDE set to hide the window created. The problem is, how do I do this effectively, so that the main window of the program launched is hidden from the very start? At the moment I am using FindWindow(), like this:
ShellExecuteEx(&app); HWND app_hWnd; while(app_hWnd == 0) //loop until app window is found { //if there is an error and the app closes, leave loop: if(WaitForSingleObject(app.hProcess,0)==WAIT_TIMEOUT) { ShowWindow((app_hWnd = FindWindow("app_mainwin",NULL)),SW_HIDE); //Ensure loading window is updated if anything happens in the meantime: if(PeekMessage(&msg,NULL,0,0,PM_REMOVE)) { TranslateMessage(&msg); DispatchMessage(&msg); } } else {break;} //if app has quit (eg. error), exit loop so we can end the program normally }
This isn't a great solution, though, as the launched program window is shown for a couple of seconds before FindWindow() and ShowWindow() catch it and hide it. Does anybody know of a better way of doing this, so that the launched application window is not shown at all until I call ShowWindow again with SW_SHOW? ...Talking of which, I have a secondary problem relating to this. When I do call ShowWindow(app_hWnd,SW_SHOW) to restore the window, even after the window is shown again, it does not appear in the taskbar until I alt-tab out of it and back in again. How do I ensure that a program's window is restored to the taskbar on re-showing it? (I have tried SW_RESTORE, SW_SHOWNORMAL etc...) Any suggestions or help much appreciated, as always. Many thanks, KBthe struct _SHELLEXECUTEINFO has int nShow; nShow Show flags. Can be one of the SW_ values described for theShowWindow function. If the lpFile specifies an executable file, this member specifies how the application is to be shown when it is opened. Papa while (TRUE) Papa.WillLove ( Bebe ) ;
-
the struct _SHELLEXECUTEINFO has int nShow; nShow Show flags. Can be one of the SW_ values described for theShowWindow function. If the lpFile specifies an executable file, this member specifies how the application is to be shown when it is opened. Papa while (TRUE) Papa.WillLove ( Bebe ) ;
Thank you for your reply but if you read my post you will see that I have already explained that this is not working, and why it's not working (because it's up to the application how it handles these flags, see MSDN). Any help much appreciated, Thanks, KB
-
Thank you for your reply but if you read my post you will see that I have already explained that this is not working, and why it's not working (because it's up to the application how it handles these flags, see MSDN). Any help much appreciated, Thanks, KB
-
i guess then u have to use CreateProcess and use the wShowWindow of the lpStartupInfo Papa while (TRUE) Papa.WillLove ( Bebe ) ;
That has already been tried, too. The "show" parameters are ignored if document-type files are specified.
Five birds are sitting on a fence. Three of them decide to fly off. How many are left?
-
Hi, I have launched an executable from my program using ShellExecuteEx(). However, I want this program initially to run in the background in a hidden state. Setting the nShow property of the SHELLEXECUTEINFO structure to SW_HIDE in this instance doesn't work - presumably because the launched program won't allow it (in accordance with what it says on MSDN, ie. that this info is passed to the program but it's up to the program how to use it). Thus, I guess I need to explicitly call ShowWindow with SW_HIDE set to hide the window created. The problem is, how do I do this effectively, so that the main window of the program launched is hidden from the very start? At the moment I am using FindWindow(), like this:
ShellExecuteEx(&app); HWND app_hWnd; while(app_hWnd == 0) //loop until app window is found { //if there is an error and the app closes, leave loop: if(WaitForSingleObject(app.hProcess,0)==WAIT_TIMEOUT) { ShowWindow((app_hWnd = FindWindow("app_mainwin",NULL)),SW_HIDE); //Ensure loading window is updated if anything happens in the meantime: if(PeekMessage(&msg,NULL,0,0,PM_REMOVE)) { TranslateMessage(&msg); DispatchMessage(&msg); } } else {break;} //if app has quit (eg. error), exit loop so we can end the program normally }
This isn't a great solution, though, as the launched program window is shown for a couple of seconds before FindWindow() and ShowWindow() catch it and hide it. Does anybody know of a better way of doing this, so that the launched application window is not shown at all until I call ShowWindow again with SW_SHOW? ...Talking of which, I have a secondary problem relating to this. When I do call ShowWindow(app_hWnd,SW_SHOW) to restore the window, even after the window is shown again, it does not appear in the taskbar until I alt-tab out of it and back in again. How do I ensure that a program's window is restored to the taskbar on re-showing it? (I have tried SW_RESTORE, SW_SHOWNORMAL etc...) Any suggestions or help much appreciated, as always. Many thanks, KB -
Hi, I have launched an executable from my program using ShellExecuteEx(). However, I want this program initially to run in the background in a hidden state. Setting the nShow property of the SHELLEXECUTEINFO structure to SW_HIDE in this instance doesn't work - presumably because the launched program won't allow it (in accordance with what it says on MSDN, ie. that this info is passed to the program but it's up to the program how to use it). Thus, I guess I need to explicitly call ShowWindow with SW_HIDE set to hide the window created. The problem is, how do I do this effectively, so that the main window of the program launched is hidden from the very start? At the moment I am using FindWindow(), like this:
ShellExecuteEx(&app); HWND app_hWnd; while(app_hWnd == 0) //loop until app window is found { //if there is an error and the app closes, leave loop: if(WaitForSingleObject(app.hProcess,0)==WAIT_TIMEOUT) { ShowWindow((app_hWnd = FindWindow("app_mainwin",NULL)),SW_HIDE); //Ensure loading window is updated if anything happens in the meantime: if(PeekMessage(&msg,NULL,0,0,PM_REMOVE)) { TranslateMessage(&msg); DispatchMessage(&msg); } } else {break;} //if app has quit (eg. error), exit loop so we can end the program normally }
This isn't a great solution, though, as the launched program window is shown for a couple of seconds before FindWindow() and ShowWindow() catch it and hide it. Does anybody know of a better way of doing this, so that the launched application window is not shown at all until I call ShowWindow again with SW_SHOW? ...Talking of which, I have a secondary problem relating to this. When I do call ShowWindow(app_hWnd,SW_SHOW) to restore the window, even after the window is shown again, it does not appear in the taskbar until I alt-tab out of it and back in again. How do I ensure that a program's window is restored to the taskbar on re-showing it? (I have tried SW_RESTORE, SW_SHOWNORMAL etc...) Any suggestions or help much appreciated, as always. Many thanks, KBTry createprocess instead. A good example by Neville Frank. [http://www.codeproject.com/script/comments/forums.asp? forumid=1647&select=626712&df=100#xx626506xx](
http://www.codeproject.com/script/comments/forums.asp?
forumid=1647&select=626712&df=100#xx626506xx)[[^](
http://www.codeproject.com/script/comments/forums.asp?
forumid=1647&select=626712&df=100#xx626506xx "New Window")] Sonork 100.41263:Anthony_Yio -
Try createprocess instead. A good example by Neville Frank. [http://www.codeproject.com/script/comments/forums.asp? forumid=1647&select=626712&df=100#xx626506xx](
http://www.codeproject.com/script/comments/forums.asp?
forumid=1647&select=626712&df=100#xx626506xx)[[^](
http://www.codeproject.com/script/comments/forums.asp?
forumid=1647&select=626712&df=100#xx626506xx "New Window")] Sonork 100.41263:Anthony_Yio -
Try createprocess instead. A good example by Neville Frank. [http://www.codeproject.com/script/comments/forums.asp? forumid=1647&select=626712&df=100#xx626506xx](
http://www.codeproject.com/script/comments/forums.asp?
forumid=1647&select=626712&df=100#xx626506xx)[[^](
http://www.codeproject.com/script/comments/forums.asp?
forumid=1647&select=626712&df=100#xx626506xx "New Window")] Sonork 100.41263:Anthony_YioSomething is amuck with your link. It has embedded
tags in it. Try http://www.codeproject.com/script/comments/forums.asp?msg=626506&forumid=1647#xx626506xx[^] instead.
Five birds are sitting on a fence. Three of them decide to fly off. How many are left?