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. Passing window to a different process?

Passing window to a different process?

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
18 Posts 6 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
    IGx89
    wrote on last edited by
    #1

    I have two programs, and I need to have a special window open whenever one or both of them are loaded. It's working pretty well, but I've run across a problem: if I load program 1, then program 2, then close P2, then close P1, it works fine (the window isn't destroyed until the last program exits), but if I load P1, then P2, then close P1, the special window is destroyed (because P1 was the program that spawned it). Is there any way to pass the special window from P1 to P2, so closing P1 doesn't close the that window? I can't just recreate the special window, because then it loses its position on the taskbar (moves to the end of the list of open programs). Thanks!

    D P 2 Replies Last reply
    0
    • I IGx89

      I have two programs, and I need to have a special window open whenever one or both of them are loaded. It's working pretty well, but I've run across a problem: if I load program 1, then program 2, then close P2, then close P1, it works fine (the window isn't destroyed until the last program exits), but if I load P1, then P2, then close P1, the special window is destroyed (because P1 was the program that spawned it). Is there any way to pass the special window from P1 to P2, so closing P1 doesn't close the that window? I can't just recreate the special window, because then it loses its position on the taskbar (moves to the end of the list of open programs). Thanks!

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

      When P1 starts, check for the existance of the special window and create it if necessary. Save the window handle for later. When P2 starts, check for the existance of the special window and create it if necessary. Save the window handle for later. When P1 ends, if it has a valid window handle and P2 is not running, close the special window. When P2 ends, if it has a valid window handle and P1 is not running, close the special window. Will that work?


      "When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen

      I 1 Reply Last reply
      0
      • I IGx89

        I have two programs, and I need to have a special window open whenever one or both of them are loaded. It's working pretty well, but I've run across a problem: if I load program 1, then program 2, then close P2, then close P1, it works fine (the window isn't destroyed until the last program exits), but if I load P1, then P2, then close P1, the special window is destroyed (because P1 was the program that spawned it). Is there any way to pass the special window from P1 to P2, so closing P1 doesn't close the that window? I can't just recreate the special window, because then it loses its position on the taskbar (moves to the end of the list of open programs). Thanks!

        P Offline
        P Offline
        palbano
        wrote on last edited by
        #3

        I don't believe a window can survive it's parent process. If that is true then you need the "special window" to be a separate process. Then i believe you can just make the special process a "single instance" process by using a mutex.

        "No matter where you go, there your are." - Buckaroo Banzai

        -pete

        I 1 Reply Last reply
        0
        • P palbano

          I don't believe a window can survive it's parent process. If that is true then you need the "special window" to be a separate process. Then i believe you can just make the special process a "single instance" process by using a mutex.

          "No matter where you go, there your are." - Buckaroo Banzai

          -pete

          I Offline
          I Offline
          IGx89
          wrote on last edited by
          #4

          If I did that, would the new process be visible to the user (listed in Task Manager)?

          J A 2 Replies Last reply
          0
          • D David Crow

            When P1 starts, check for the existance of the special window and create it if necessary. Save the window handle for later. When P2 starts, check for the existance of the special window and create it if necessary. Save the window handle for later. When P1 ends, if it has a valid window handle and P2 is not running, close the special window. When P2 ends, if it has a valid window handle and P1 is not running, close the special window. Will that work?


            "When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen

            I Offline
            I Offline
            IGx89
            wrote on last edited by
            #5

            That's exactly what I'm doing already. The problem occurs when closing P1 but P2 is still running: the special window is closed anyway (which appears unavoidable unless a separate process is used for the special window).

            D 1 Reply Last reply
            0
            • I IGx89

              If I did that, would the new process be visible to the user (listed in Task Manager)?

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

              Yes Why dont you simply *hide* P1 as if it was closed? Another option is to inject the window into explorer.exe this way it wont die with P1. Check CreateRemoteThread Papa while (TRUE) Papa.WillLove ( Bebe ) ;

              I 1 Reply Last reply
              0
              • I IGx89

                That's exactly what I'm doing already. The problem occurs when closing P1 but P2 is still running: the special window is closed anyway (which appears unavoidable unless a separate process is used for the special window).

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

                So are you saying that P1 is closing the special window without first checking to see if P2 is still running?


                "When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen

                I 1 Reply Last reply
                0
                • J jmkhael

                  Yes Why dont you simply *hide* P1 as if it was closed? Another option is to inject the window into explorer.exe this way it wont die with P1. Check CreateRemoteThread Papa while (TRUE) Papa.WillLove ( Bebe ) ;

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

                  Well, P1 will be taking up at least 40mb, so that's not an option :) Thanks, I'll check out that function.

                  1 Reply Last reply
                  0
                  • I IGx89

                    If I did that, would the new process be visible to the user (listed in Task Manager)?

                    A Offline
                    A Offline
                    Anonymous
                    wrote on last edited by
                    #9

                    sure is that a problem?

                    I 1 Reply Last reply
                    0
                    • D David Crow

                      So are you saying that P1 is closing the special window without first checking to see if P2 is still running?


                      "When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen

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

                      No; let me show you some psuedo-code to illustrate: P1_OnExit() { if(!exists(P2)) close(specialwindow) //window is closed, like it should be } //P1 closes //The special window is closed, even if P2 still exists

                      D 1 Reply Last reply
                      0
                      • A Anonymous

                        sure is that a problem?

                        I Offline
                        I Offline
                        IGx89
                        wrote on last edited by
                        #11

                        We're trying to avoid that, making it as clean as possible. But, if there's no decent way around it, then we might end up doing that after all.

                        P 1 Reply Last reply
                        0
                        • I IGx89

                          We're trying to avoid that, making it as clean as possible. But, if there's no decent way around it, then we might end up doing that after all.

                          P Offline
                          P Offline
                          palbano
                          wrote on last edited by
                          #12

                          Sorry that Anonymous post was me... i timed out, had to actually do some work :laugh: "Clean" is in the eye of the beholder. My first thought is that a Single Instance process for the special window would produce the "Simplest" solution. I always like simple. Of course I don't have the complete context of your problem so...

                          "No matter where you go, there your are." - Buckaroo Banzai

                          -pete

                          I 1 Reply Last reply
                          0
                          • P palbano

                            Sorry that Anonymous post was me... i timed out, had to actually do some work :laugh: "Clean" is in the eye of the beholder. My first thought is that a Single Instance process for the special window would produce the "Simplest" solution. I always like simple. Of course I don't have the complete context of your problem so...

                            "No matter where you go, there your are." - Buckaroo Banzai

                            -pete

                            I Offline
                            I Offline
                            IGx89
                            wrote on last edited by
                            #13

                            Well, basically I'm trying to force two different programs to appear as one program on the taskbar, but two separate programs in the alt-tab window. I'm currently doing it by making the two programs not show up on the taskbar, and using a special window and the ITaskbarList interface to make an entry on the taskbar that doesn't show up in the alt-tab window.

                            P 1 Reply Last reply
                            0
                            • I IGx89

                              No; let me show you some psuedo-code to illustrate: P1_OnExit() { if(!exists(P2)) close(specialwindow) //window is closed, like it should be } //P1 closes //The special window is closed, even if P2 still exists

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

                              It looks as though the exists() function is not returning the correct status of P2. On the other hand, I may be making an incorrect assumption about the "special window." Reading through the other replies to this post, I was assuming it was a separate process (since the word spawn) was used. If it is indeed just a window that is "owned" by P1, my posts are wrong.


                              "When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen

                              1 Reply Last reply
                              0
                              • I IGx89

                                Well, basically I'm trying to force two different programs to appear as one program on the taskbar, but two separate programs in the alt-tab window. I'm currently doing it by making the two programs not show up on the taskbar, and using a special window and the ITaskbarList interface to make an entry on the taskbar that doesn't show up in the alt-tab window.

                                P Offline
                                P Offline
                                palbano
                                wrote on last edited by
                                #15

                                Probably a stupid question, but... Why not just One process that looks like One process because it is One process? :-D

                                "No matter where you go, there your are." - Buckaroo Banzai

                                -pete

                                I 1 Reply Last reply
                                0
                                • P palbano

                                  Probably a stupid question, but... Why not just One process that looks like One process because it is One process? :-D

                                  "No matter where you go, there your are." - Buckaroo Banzai

                                  -pete

                                  I Offline
                                  I Offline
                                  IGx89
                                  wrote on last edited by
                                  #16

                                  Both apps are way too big to combine them both, that's why :)

                                  J 1 Reply Last reply
                                  0
                                  • I IGx89

                                    Both apps are way too big to combine them both, that's why :)

                                    J Offline
                                    J Offline
                                    Joel Lucsy
                                    wrote on last edited by
                                    #17

                                    Is that "Too big" as in the projects are too big, or in the process memory is too big? If it's the later, then I wouldn't consider that an issue as both programs will have to be in memory regardless. In fact, it may be slightly less memory as there is no overhead for the second process (not mention code being used for communication). If it's the former, then you may want to break up the application into dlls that are more easily managed. -- Joel Lucsy

                                    I 1 Reply Last reply
                                    0
                                    • J Joel Lucsy

                                      Is that "Too big" as in the projects are too big, or in the process memory is too big? If it's the later, then I wouldn't consider that an issue as both programs will have to be in memory regardless. In fact, it may be slightly less memory as there is no overhead for the second process (not mention code being used for communication). If it's the former, then you may want to break up the application into dlls that are more easily managed. -- Joel Lucsy

                                      I Offline
                                      I Offline
                                      IGx89
                                      wrote on last edited by
                                      #18

                                      I mean the former; it would be a complete nightmare to combine them, and definitely not worth it.

                                      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