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

    Thanks Slavisa, I tried it. but it does nothing i donno why.. Could u please help me further with my code below: (I want to close the console that created within 3 seconds but it is not moving into that if part (bold)) CreateProcess(_T("\\windows\\iesample.exe"),imFullPath, NULL, NULL, FALSE, CREATE_NEW_CONSOLE, NULL, NULL, NULL, &processInfo1); Sleep(3000); EnumWindows(&EnumProc,processInfo1.dwProcessId); BOOL CALLBACK EnumProc(HWND hwnd, LPARAM param) { DWORD id = GetWindowThreadProcessId(hwnd, NULL); if (id == (DWORD)param) { DestroyWindow(hwnd); return false; } return true; }

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

    I think it is better to send WM_CLOSE to the window instead of calling DestroyWindow().

    Slavisa

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

      C Offline
      C 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]

      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
        • C 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 C 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

                C Offline
                C 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]

                V 1 Reply Last reply
                0
                • C 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..

                  C 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..

                    C Offline
                    C 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]

                    V 1 Reply Last reply
                    0
                    • C 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...

                      C 1 Reply Last reply
                      0
                      • V vijaywithu

                        I am in a serious deputation buddy...

                        C Offline
                        C 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]

                        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