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. handle to a window created by createprocess

handle to a window created by createprocess

Scheduled Pinned Locked Moved C / C++ / MFC
help
15 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.
  • V vijaywithu

    I have used createProcess to run a process in a new window using CREATE_NEW_CONSOLE flag, Can any one help to get the handle to the console that i have created so as to close that window. code: CreateProcess(_T("\\windows\\ceplayer.exe"),_T("c:\\folder\\new.wmv"), NULL, NULL, FALSE, CREATE_NEW_CONSOLE, NULL, NULL, NULL, &processInfo); Thanks in Advance

    CPalliniC Offline
    CPalliniC Offline
    CPallini
    wrote on last edited by
    #6

    I suspect you've to use EnumThreadWindows [^], passing, as dwThreadId argument, the dwThreadId member of the PROCESS_INFORMATION struct filled by CreateProcess function. It's just a guess: the test is up to you. :)

    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]

    In testa che avete, signor di Ceprano?

    V 1 Reply Last reply
    0
    • _ _Superman_

      The return value of GetWindowThreadProcessId is the thread Id and not the process Id. If you want the process Id, use the second parameter like so.

      DWORD dwProcessId = 0;
      GetWindowThreadProcessId(hwnd, &dwProcessId);
      if (dwProcessId == (DWORD)param)

      «_Superman_» I love work. It gives me something to do between weekends.

      V Offline
      V Offline
      vijaywithu
      wrote on last edited by
      #7

      Friens i used GetWindowThreadProcessId(hwnd, &dwProcessId); and also PostMessage(hwnd,WM_CLOSE,0); but it is not moving into that if loop still if(dwprocessid == DWORD(param)) i could not figure it out what i need to do now or IS there any other way to get the handle of the window seeking ur help....

      1 Reply Last reply
      0
      • CPalliniC CPallini

        I suspect you've to use EnumThreadWindows [^], passing, as dwThreadId argument, the dwThreadId member of the PROCESS_INFORMATION struct filled by CreateProcess function. It's just a guess: the test is up to you. :)

        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]

        V Offline
        V Offline
        vijaywithu
        wrote on last edited by
        #8

        Friens i used GetWindowThreadProcessId(hwnd, &dwProcessId); and also PostMessage(hwnd,WM_CLOSE,0); but it is not moving into that if loop still if(dwprocessid == DWORD(param)) i could not figure it out what i need to do now or IS there any other way to get the handle of the window seeking ur help....

        S 1 Reply Last reply
        0
        • V vijaywithu

          Friens i used GetWindowThreadProcessId(hwnd, &dwProcessId); and also PostMessage(hwnd,WM_CLOSE,0); but it is not moving into that if loop still if(dwprocessid == DWORD(param)) i could not figure it out what i need to do now or IS there any other way to get the handle of the window seeking ur help....

          S Offline
          S Offline
          Slavisa Dojcinovic
          wrote on last edited by
          #9

          Well, since you just want to close the program you could use TerminateProcess(hProcess, 0);

          Slavisa

          V CPalliniC 2 Replies Last reply
          0
          • S Slavisa Dojcinovic

            Well, since you just want to close the program you could use TerminateProcess(hProcess, 0);

            Slavisa

            V Offline
            V Offline
            vijaywithu
            wrote on last edited by
            #10

            I am sorry not exactly i want to close the process slavisa i need to close that window alone and should open the next command line say next.wmv in that place

            1 Reply Last reply
            0
            • S Slavisa Dojcinovic

              Well, since you just want to close the program you could use TerminateProcess(hProcess, 0);

              Slavisa

              CPalliniC Offline
              CPalliniC Offline
              CPallini
              wrote on last edited by
              #11

              A hammer is another option. :)

              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]

              In testa che avete, signor di Ceprano?

              V 1 Reply Last reply
              0
              • CPalliniC CPallini

                A hammer is another option. :)

                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]

                V Offline
                V Offline
                vijaywithu
                wrote on last edited by
                #12

                I am sorry i could get what does A hammer is.. could you please throw some light on this area..

                CPalliniC 1 Reply Last reply
                0
                • V vijaywithu

                  I am sorry i could get what does A hammer is.. could you please throw some light on this area..

                  CPalliniC Offline
                  CPalliniC Offline
                  CPallini
                  wrote on last edited by
                  #13

                  Hammer [^]. :)

                  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]

                  In testa che avete, signor di Ceprano?

                  V 1 Reply Last reply
                  0
                  • CPalliniC CPallini

                    Hammer [^]. :)

                    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]

                    V Offline
                    V Offline
                    vijaywithu
                    wrote on last edited by
                    #14

                    I am in a serious deputation buddy...

                    CPalliniC 1 Reply Last reply
                    0
                    • V vijaywithu

                      I am in a serious deputation buddy...

                      CPalliniC Offline
                      CPalliniC Offline
                      CPallini
                      wrote on last edited by
                      #15

                      vijaywithu wrote:

                      I am in a serious deputation buddy...

                      You are a Member of Parliament? :rolleyes:

                      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]

                      In testa che avete, signor di Ceprano?

                      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