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. transferring control between 2 programs?

transferring control between 2 programs?

Scheduled Pinned Locked Moved C / C++ / MFC
helptutorialquestion
10 Posts 4 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.
  • I Offline
    I Offline
    IlanTal
    wrote on last edited by
    #1

    In my application I have a button to start another application (a different program altogether). I use the old WinExec which works fine. The problem is that I don't want multiple instances of the other application. (For example the user clicks on the first application and again it gets control and then he clicks on the button again.) What I would like to do is transfer control to that program if it is running and not start and new instance of it. (This would be the equivalent of clicking on its icon on the bar on the bottom of the screen.) Is there a way to do such a thing? Thanks, Ilan

    L D D 3 Replies Last reply
    0
    • I IlanTal

      In my application I have a button to start another application (a different program altogether). I use the old WinExec which works fine. The problem is that I don't want multiple instances of the other application. (For example the user clicks on the first application and again it gets control and then he clicks on the button again.) What I would like to do is transfer control to that program if it is running and not start and new instance of it. (This would be the equivalent of clicking on its icon on the bar on the bottom of the screen.) Is there a way to do such a thing? Thanks, Ilan

      L Offline
      L Offline
      led mike
      wrote on last edited by
      #2

      IlanTal wrote:

      Is there a way to do such a thing?

      There are many ways. See Inter-process communication[^]

      I 1 Reply Last reply
      0
      • I IlanTal

        In my application I have a button to start another application (a different program altogether). I use the old WinExec which works fine. The problem is that I don't want multiple instances of the other application. (For example the user clicks on the first application and again it gets control and then he clicks on the button again.) What I would like to do is transfer control to that program if it is running and not start and new instance of it. (This would be the equivalent of clicking on its icon on the bar on the bottom of the screen.) Is there a way to do such a thing? Thanks, Ilan

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

        If you have access to the other application's source code, see here.


        "A good athlete is the result of a good and worthy opponent." - David Crow

        "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

        I 1 Reply Last reply
        0
        • I IlanTal

          In my application I have a button to start another application (a different program altogether). I use the old WinExec which works fine. The problem is that I don't want multiple instances of the other application. (For example the user clicks on the first application and again it gets control and then he clicks on the button again.) What I would like to do is transfer control to that program if it is running and not start and new instance of it. (This would be the equivalent of clicking on its icon on the bar on the bottom of the screen.) Is there a way to do such a thing? Thanks, Ilan

          D Offline
          D Offline
          DjinnKahn
          wrote on last edited by
          #4

          maybe: Use ::FindWindow() to check if the other program is running, and get the window handle if it is. Use something like ::SetFocus() or ::SetForegroundWindow() to give the other program control (now that you have its window handle).

          D 1 Reply Last reply
          0
          • D DjinnKahn

            maybe: Use ::FindWindow() to check if the other program is running, and get the window handle if it is. Use something like ::SetFocus() or ::SetForegroundWindow() to give the other program control (now that you have its window handle).

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

            DjinnKahn wrote:

            Use ::FindWindow()...

            ...to cause a potential deadlock situation.


            "A good athlete is the result of a good and worthy opponent." - David Crow

            "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

            I 1 Reply Last reply
            0
            • L led mike

              IlanTal wrote:

              Is there a way to do such a thing?

              There are many ways. See Inter-process communication[^]

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

              I don't want to send any information between the programs, just give the second program control - like you do when you click on the task bar.

              1 Reply Last reply
              0
              • D David Crow

                If you have access to the other application's source code, see here.


                "A good athlete is the result of a good and worthy opponent." - David Crow

                "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                I Offline
                I Offline
                IlanTal
                wrote on last edited by
                #7

                Today in the second program I use a mutex to detect the second instance and kill it. The reply below this one is correct in the sense that I want to give it focus. However I don't know what it means to give focus to a totally different process.

                D 1 Reply Last reply
                0
                • D David Crow

                  DjinnKahn wrote:

                  Use ::FindWindow()...

                  ...to cause a potential deadlock situation.


                  "A good athlete is the result of a good and worthy opponent." - David Crow

                  "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                  I Offline
                  I Offline
                  IlanTal
                  wrote on last edited by
                  #8

                  So I don't use FindWindow(). If I would use something better, how could I give focus?

                  1 Reply Last reply
                  0
                  • I IlanTal

                    Today in the second program I use a mutex to detect the second instance and kill it. The reply below this one is correct in the sense that I want to give it focus. However I don't know what it means to give focus to a totally different process.

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

                    IlanTal wrote:

                    However I don't know what it means to give focus to a totally different process.

                    The one and only instance of your "second program" does this with a call to SetForegroundWindow().


                    "A good athlete is the result of a good and worthy opponent." - David Crow

                    "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                    I 1 Reply Last reply
                    0
                    • D David Crow

                      IlanTal wrote:

                      However I don't know what it means to give focus to a totally different process.

                      The one and only instance of your "second program" does this with a call to SetForegroundWindow().


                      "A good athlete is the result of a good and worthy opponent." - David Crow

                      "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                      I Offline
                      I Offline
                      IlanTal
                      wrote on last edited by
                      #10

                      Thank you very much. That is my missing link.

                      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