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. How can I get the CWnd pointer from HANDLE hProcess

How can I get the CWnd pointer from HANDLE hProcess

Scheduled Pinned Locked Moved C / C++ / MFC
question
6 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.
  • C Offline
    C Offline
    caykahve
    wrote on last edited by
    #1

    Hi, After using ShellExecuteEx and getting HANDLE hProcess of the SHELLEXECUTEINFO Structure, I need to get the CWnd pointer of the program window I opened. I want to use it in SetWindowPos to move and set its size. How can I get CWnd *? Thanks, caykahve

    J T 2 Replies Last reply
    0
    • C caykahve

      Hi, After using ShellExecuteEx and getting HANDLE hProcess of the SHELLEXECUTEINFO Structure, I need to get the CWnd pointer of the program window I opened. I want to use it in SetWindowPos to move and set its size. How can I get CWnd *? Thanks, caykahve

      J Offline
      J Offline
      Jose Lamas Rios
      wrote on last edited by
      #2

      You don't actually need a CWnd*. CWnd will just wrap the handle and convert the calls you make to CWnd methods in calls to the corresponding API function using the handle stored in its m_hWnd member. For example, here is the implementation for CWnd::MoveWindow()

      void CWnd::MoveWindow(int x, int y, int nWidth, int nHeight, BOOL bRepaint)
      {
        ASSERT(::IsWindow(m_hWnd));
        ::MoveWindow(m_hWnd, x, y, nWidth, nHeight, bRepaint);
      }

      So, you can always make the call to the API function yourself. That being said, you can obtain a CWnd* for a given handle, using CWnd::FromHandle() but take note that in your case it will be a pointer to a temporary object, so you can't store it for later use. Again, if all you want to do is to use some CWnd methods, you can use the corresponding API function directly on the window handle. For CWnd::SetWindowPos, the corresponding API is just ::SetWindowPos. Look in the documentation to see what parameters it expects. -- jlr http://jlamas.blogspot.com/[^]

      J 1 Reply Last reply
      0
      • C caykahve

        Hi, After using ShellExecuteEx and getting HANDLE hProcess of the SHELLEXECUTEINFO Structure, I need to get the CWnd pointer of the program window I opened. I want to use it in SetWindowPos to move and set its size. How can I get CWnd *? Thanks, caykahve

        T Offline
        T Offline
        ThatsAlok
        wrote on last edited by
        #3

        caykahve wrote: , I need to get the CWnd pointer of the program window I opened. There is no direct Method for getting Window Handle from the process ID, but this link may help:- Is it possible to get info between HWND and Process handle?[^]

        "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

        cheers, Alok Gupta VC Forum Q&A :- I/ IV

        E 1 Reply Last reply
        0
        • T ThatsAlok

          caykahve wrote: , I need to get the CWnd pointer of the program window I opened. There is no direct Method for getting Window Handle from the process ID, but this link may help:- Is it possible to get info between HWND and Process handle?[^]

          "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

          cheers, Alok Gupta VC Forum Q&A :- I/ IV

          E Offline
          E Offline
          Eytukan
          wrote on last edited by
          #4

          :cool:.. this is another way to say Hi!! to u . but this is the only way now ..he he V

          1 Reply Last reply
          0
          • J Jose Lamas Rios

            You don't actually need a CWnd*. CWnd will just wrap the handle and convert the calls you make to CWnd methods in calls to the corresponding API function using the handle stored in its m_hWnd member. For example, here is the implementation for CWnd::MoveWindow()

            void CWnd::MoveWindow(int x, int y, int nWidth, int nHeight, BOOL bRepaint)
            {
              ASSERT(::IsWindow(m_hWnd));
              ::MoveWindow(m_hWnd, x, y, nWidth, nHeight, bRepaint);
            }

            So, you can always make the call to the API function yourself. That being said, you can obtain a CWnd* for a given handle, using CWnd::FromHandle() but take note that in your case it will be a pointer to a temporary object, so you can't store it for later use. Again, if all you want to do is to use some CWnd methods, you can use the corresponding API function directly on the window handle. For CWnd::SetWindowPos, the corresponding API is just ::SetWindowPos. Look in the documentation to see what parameters it expects. -- jlr http://jlamas.blogspot.com/[^]

            J Offline
            J Offline
            Jose Lamas Rios
            wrote on last edited by
            #5

            Holy handles, Batman! After reading Alok's response I now realize that you were talking about a process handle and I took it as a window handle. It's embarrasing considering how clear it is in the thread title itself :) No cookies but more coffe for me. Sorry, -- jlr http://jlamas.blogspot.com/[^]

            T 1 Reply Last reply
            0
            • J Jose Lamas Rios

              Holy handles, Batman! After reading Alok's response I now realize that you were talking about a process handle and I took it as a window handle. It's embarrasing considering how clear it is in the thread title itself :) No cookies but more coffe for me. Sorry, -- jlr http://jlamas.blogspot.com/[^]

              T Offline
              T Offline
              ThatsAlok
              wrote on last edited by
              #6

              Jose Lamas Rios wrote: No cookies but more coffe for me. Sir, Then please pass that Cookie to me, I am Hungry at this moment :).

              "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

              cheers, Alok Gupta VC Forum Q&A :- I/ IV

              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