How to find hWnd handle from enumerated process?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Gary

    How to find hWnd handle from enumerated process?

    Hi i need to work with windows of processes that are running on my pc
    from a certain programme. I've figured out how to build an array of
    processes that contain just the processes i'm interested in by checking
    what the process name starts with.

    How do i find out the hWnd for the processes i've returned, because the
    function i need to run wants me to pass it the hWnd of the processes.

    Here's what I have so far, using notepad as my example : -

    static void EnumerateWindow s()
    {
    System.Diagnost ics.Process[] processes;
    processes =
    System.Diagnost ics.Process.Get ProcessesByName ("notepad");

    foreach (System.Diagnos tics.Process instance in processes)
    {
    MessageBox.Show (instance.Handl e.ToString());

    }

    }
    }

    Thankyou experts,

    Gary.

  • Barry Kelly

    #2
    Re: How to find hWnd handle from enumerated process?

    Gary wrote:
    How do i find out the hWnd for the processes i've returned, because the
    function i need to run wants me to pass it the hWnd of the processes.
    static void EnumerateWindow s()
    MessageBox.Show (instance.Handl e.ToString());
    What you've got there is a HINSTANCE, not a HWND.

    One way of doing it:
    - use P/Invoke and call EnumWindows, passing in a callback.
    - then use P/Invoke and call GetWindowThread ProcessId to get the PID
    - you can then use the PID with Process.GetProc essById to do your
    filtering.

    http://pinvoke.net has some info on prototypes to use for EnumWindows()
    and friends.

    -- Barry

    --

    Comment

    • Barry Kelly

      #3
      Re: How to find hWnd handle from enumerated process?

      Barry Kelly wrote:
      What you've got there is a HINSTANCE, not a HWND.
      Whups - I mis-remembered. It's a handle to the process, but that doesn't
      materially change my suggestion.

      -- Barry

      --

      Comment

      Working...