Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Hiding the main app window created by ShellExecuteEx?

Hiding the main app window created by ShellExecuteEx?

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestiontutorial
9 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Kayembi
    wrote on last edited by
    #1

    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

    J I A 3 Replies Last reply
    0
    • K Kayembi

      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

      J Offline
      J Offline
      jmkhael
      wrote on last edited by
      #2

      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 ) ;

      K 1 Reply Last reply
      0
      • J jmkhael

        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 ) ;

        K Offline
        K Offline
        Kayembi
        wrote on last edited by
        #3

        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

        J 1 Reply Last reply
        0
        • K Kayembi

          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

          J Offline
          J Offline
          jmkhael
          wrote on last edited by
          #4

          i guess then u have to use CreateProcess and use the wShowWindow of the lpStartupInfo Papa while (TRUE) Papa.WillLove ( Bebe ) ;

          D 1 Reply Last reply
          0
          • J jmkhael

            i guess then u have to use CreateProcess and use the wShowWindow of the lpStartupInfo Papa while (TRUE) Papa.WillLove ( Bebe ) ;

            D Offline
            D Offline
            David Crow
            wrote on last edited by
            #5

            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?

            1 Reply Last reply
            0
            • K Kayembi

              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

              I Offline
              I Offline
              igor1960
              wrote on last edited by
              #6

              Install system wide hook before launching your missbehaving app. and intercept WM_SHOWWINDOW... "...Ability to type is not enough to become a Programmer. Unless you type in VB. But then again you have to type really fast..." Me

              1 Reply Last reply
              0
              • K Kayembi

                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

                A Offline
                A Offline
                Anthony_Yio
                wrote on last edited by
                #7

                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

                K D 2 Replies Last reply
                0
                • A 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

                  K Offline
                  K Offline
                  Kayembi
                  wrote on last edited by
                  #8

                  Thanks for the reply, but unfortunately that only works for console/DOS apps (though I tried it anyway) - the app I'm launching is a Win32 EXE... Thanks for all the suggestions so far, KB

                  1 Reply Last reply
                  0
                  • A 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

                    D Offline
                    D Offline
                    David Crow
                    wrote on last edited by
                    #9

                    Something 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?

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups