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. using ShellExecute to close...

using ShellExecute to close...

Scheduled Pinned Locked Moved C / C++ / MFC
helpdesignquestion
12 Posts 3 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.
  • R Offline
    R Offline
    randomrockers
    wrote on last edited by
    #1

    Hi, i am using ShellExecute to open an image. The image is opened using Windows Picture and Fax Viewer. Now, I have a button, in my dialog(the UI). I want to close the Windows Picture and Fax Viewer, got any idea? here's my code... please help. its kinda urgent... been stuck on this for 3 days... googled it, but nopthing relevant came out. void CDesignDlg::OnImage() { // TODO: Add your control notification handler code here CFileDialog m_ldFile(TRUE); { if ( ! onStart ) { m_button.SetWindowText("Start Image"); } else { m_button.SetWindowText("Stop Image"); } onStart ^= 1; // make onStart 0, or 1 respectively } if (onStart==0){ if (m_ldFile.DoModal() ==IDOK) { CString abc= m_ldFile.GetPathName(); SHELLEXECUTEINFO tiff; tiff.cbSize = sizeof(SHELLEXECUTEINFO); tiff.fMask = NULL; tiff.hwnd = NULL; tiff.lpVerb = "open"; tiff.lpFile = abc; tiff.lpParameters= NULL; tiff.nShow = SW_SHOWNORMAL; tiff.hInstApp = NULL; tiff.lpIDList = NULL; tiff.lpClass = NULL; tiff.hkeyClass = NULL; tiff.dwHotKey = NULL; tiff.hIcon = NULL; tiff.hProcess = NULL; tiff.lpDirectory = NULL; int ReturnCode = ::ShellExecuteEx(&tiff); UpdateData(TRUE); }} else { //what should be put here??? } }

    T C 2 Replies Last reply
    0
    • R randomrockers

      Hi, i am using ShellExecute to open an image. The image is opened using Windows Picture and Fax Viewer. Now, I have a button, in my dialog(the UI). I want to close the Windows Picture and Fax Viewer, got any idea? here's my code... please help. its kinda urgent... been stuck on this for 3 days... googled it, but nopthing relevant came out. void CDesignDlg::OnImage() { // TODO: Add your control notification handler code here CFileDialog m_ldFile(TRUE); { if ( ! onStart ) { m_button.SetWindowText("Start Image"); } else { m_button.SetWindowText("Stop Image"); } onStart ^= 1; // make onStart 0, or 1 respectively } if (onStart==0){ if (m_ldFile.DoModal() ==IDOK) { CString abc= m_ldFile.GetPathName(); SHELLEXECUTEINFO tiff; tiff.cbSize = sizeof(SHELLEXECUTEINFO); tiff.fMask = NULL; tiff.hwnd = NULL; tiff.lpVerb = "open"; tiff.lpFile = abc; tiff.lpParameters= NULL; tiff.nShow = SW_SHOWNORMAL; tiff.hInstApp = NULL; tiff.lpIDList = NULL; tiff.lpClass = NULL; tiff.hkeyClass = NULL; tiff.dwHotKey = NULL; tiff.hIcon = NULL; tiff.hProcess = NULL; tiff.lpDirectory = NULL; int ReturnCode = ::ShellExecuteEx(&tiff); UpdateData(TRUE); }} else { //what should be put here??? } }

      T Offline
      T Offline
      tolw
      wrote on last edited by
      #2

      I think killing the process might do the trick. To do this you need the process ID. One of the ways to obtain it is:

      int ReturnCode = ::ShellExecuteEx(&tiff);
      // Get the pid
      DWORD pid = GetProcessID(tiff.hProcess);

      ....

      To kill the process call:

      KillProcess( pid );

      Let me know if this did the trick :)

      R 1 Reply Last reply
      0
      • R randomrockers

        Hi, i am using ShellExecute to open an image. The image is opened using Windows Picture and Fax Viewer. Now, I have a button, in my dialog(the UI). I want to close the Windows Picture and Fax Viewer, got any idea? here's my code... please help. its kinda urgent... been stuck on this for 3 days... googled it, but nopthing relevant came out. void CDesignDlg::OnImage() { // TODO: Add your control notification handler code here CFileDialog m_ldFile(TRUE); { if ( ! onStart ) { m_button.SetWindowText("Start Image"); } else { m_button.SetWindowText("Stop Image"); } onStart ^= 1; // make onStart 0, or 1 respectively } if (onStart==0){ if (m_ldFile.DoModal() ==IDOK) { CString abc= m_ldFile.GetPathName(); SHELLEXECUTEINFO tiff; tiff.cbSize = sizeof(SHELLEXECUTEINFO); tiff.fMask = NULL; tiff.hwnd = NULL; tiff.lpVerb = "open"; tiff.lpFile = abc; tiff.lpParameters= NULL; tiff.nShow = SW_SHOWNORMAL; tiff.hInstApp = NULL; tiff.lpIDList = NULL; tiff.lpClass = NULL; tiff.hkeyClass = NULL; tiff.dwHotKey = NULL; tiff.hIcon = NULL; tiff.hProcess = NULL; tiff.lpDirectory = NULL; int ReturnCode = ::ShellExecuteEx(&tiff); UpdateData(TRUE); }} else { //what should be put here??? } }

        C Offline
        C Offline
        CPallini
        wrote on last edited by
        #3

        You should send the WM_CLOSE message to the Windows Picture and Fax Viewer main window. :)

        If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
        This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
        [My articles]

        1 Reply Last reply
        0
        • T tolw

          I think killing the process might do the trick. To do this you need the process ID. One of the ways to obtain it is:

          int ReturnCode = ::ShellExecuteEx(&tiff);
          // Get the pid
          DWORD pid = GetProcessID(tiff.hProcess);

          ....

          To kill the process call:

          KillProcess( pid );

          Let me know if this did the trick :)

          R Offline
          R Offline
          randomrockers
          wrote on last edited by
          #4

          NOPE... IT DOESNT... i get the following errors c:\documents and settings\user\my documents\visual studio 2005\projects\design\designdlg.cpp(242) : error C2065: 'GetProcessID' : undeclared identifier c:\documents and settings\user\my documents\visual studio 2005\projects\design\designdlg.cpp(245) : error C2065: 'KillProcess' : undeclared identifier maybe you like to see the results... http://yfrog.com/11picture2mzjpx[^] stop does go back to start when i click it, but picture doesnt close

          T 1 Reply Last reply
          0
          • R randomrockers

            NOPE... IT DOESNT... i get the following errors c:\documents and settings\user\my documents\visual studio 2005\projects\design\designdlg.cpp(242) : error C2065: 'GetProcessID' : undeclared identifier c:\documents and settings\user\my documents\visual studio 2005\projects\design\designdlg.cpp(245) : error C2065: 'KillProcess' : undeclared identifier maybe you like to see the results... http://yfrog.com/11picture2mzjpx[^] stop does go back to start when i click it, but picture doesnt close

            T Offline
            T Offline
            tolw
            wrote on last edited by
            #5

            Do you have the proper include's? Try:

            #include Windows.h

            or

            #include Winbase.h

            Also as CPallini suggests below, you can try sending a WM_CLOSE to the window... Yo get the handle from the ShellExecuteEx method (in tiff.hwnd)

            R 1 Reply Last reply
            0
            • T tolw

              Do you have the proper include's? Try:

              #include Windows.h

              or

              #include Winbase.h

              Also as CPallini suggests below, you can try sending a WM_CLOSE to the window... Yo get the handle from the ShellExecuteEx method (in tiff.hwnd)

              R Offline
              R Offline
              randomrockers
              wrote on last edited by
              #6

              WM_CLOSE to window.. for example? I tried, but keep getting different error, went to the library of SHELLEXECUTE, all said is optional for hwnd... so i cannot get any example... yup. i do have the proper includes...

              T 1 Reply Last reply
              0
              • R randomrockers

                WM_CLOSE to window.. for example? I tried, but keep getting different error, went to the library of SHELLEXECUTE, all said is optional for hwnd... so i cannot get any example... yup. i do have the proper includes...

                T Offline
                T Offline
                tolw
                wrote on last edited by
                #7

                Foret the hwnd - I was wrong anyway :D Getting back to GetProcessID: Try reading about the function in MSDN - all the info is there. If your includes are ok maybe you're missing a lib? Did you link to Kernel32.dll? Select your project propertied, go to Linker -> Input -> Additional Dependencies And type in Kernel32.dll.

                R C 2 Replies Last reply
                0
                • T tolw

                  Foret the hwnd - I was wrong anyway :D Getting back to GetProcessID: Try reading about the function in MSDN - all the info is there. If your includes are ok maybe you're missing a lib? Did you link to Kernel32.dll? Select your project propertied, go to Linker -> Input -> Additional Dependencies And type in Kernel32.dll.

                  R Offline
                  R Offline
                  randomrockers
                  wrote on last edited by
                  #8

                  yup i know about the site... I am using Visual C++6 there is no additional dependencies there... :( i try puting it in object modules, but an error came out saying cannot open Kernel32.dll

                  1 Reply Last reply
                  0
                  • T tolw

                    Foret the hwnd - I was wrong anyway :D Getting back to GetProcessID: Try reading about the function in MSDN - all the info is there. If your includes are ok maybe you're missing a lib? Did you link to Kernel32.dll? Select your project propertied, go to Linker -> Input -> Additional Dependencies And type in Kernel32.dll.

                    C Offline
                    C Offline
                    CPallini
                    wrote on last edited by
                    #9

                    tolw wrote:

                    If your includes are ok maybe you're missing a lib?

                    Are you kidding? AFAIK "undeclared identifier" error has nothing to do with the linker. :)

                    If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                    This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
                    [My articles]

                    R T 2 Replies Last reply
                    0
                    • C CPallini

                      tolw wrote:

                      If your includes are ok maybe you're missing a lib?

                      Are you kidding? AFAIK "undeclared identifier" error has nothing to do with the linker. :)

                      If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                      This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
                      [My articles]

                      R Offline
                      R Offline
                      randomrockers
                      wrote on last edited by
                      #10

                      hmm... alright... i trying to call hWnd as a handle... and trying other methods... so once i get something, i let u guys know... but, if you guys got any idea, let me know too.. thanks...

                      T 1 Reply Last reply
                      0
                      • C CPallini

                        tolw wrote:

                        If your includes are ok maybe you're missing a lib?

                        Are you kidding? AFAIK "undeclared identifier" error has nothing to do with the linker. :)

                        If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                        This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
                        [My articles]

                        T Offline
                        T Offline
                        tolw
                        wrote on last edited by
                        #11

                        whoops - right you are - sorry about that - juggling between CP and my own projects can do that to you :-O

                        1 Reply Last reply
                        0
                        • R randomrockers

                          hmm... alright... i trying to call hWnd as a handle... and trying other methods... so once i get something, i let u guys know... but, if you guys got any idea, let me know too.. thanks...

                          T Offline
                          T Offline
                          tolw
                          wrote on last edited by
                          #12

                          Check out this thread also: http://www.codeproject.com/Forums/1647/C-Cplusplus-MFC.aspx?fid=1647&select=2972272&fr=7846#xx2972272xx[^] Apperantly people have had problems getting it to work before...

                          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