none
Getting correct window title using Process object

    Question

  • My app is enumerating the processes returned from Process.GetProcesses(). In some cases, the caption on the main window does not match that returned from the Process.MainWindowTitle property. Nevertheless, TaskManger does manage to obtain the correct caption. Is there another way (from C#) to find window captions? Or to hunt through another process's windows to see where the elusive caption might be hiding?
    "I don't want to steal the show. I only want to borrow it for awhile."
    Tuesday, November 16, 2010 8:34 PM

Answers

  • Hi Chuck Puckett,

    Welcome to MSDN Forums!

     

    You can use GetWindowText Function to retrieve the window caption.

     

    GetWindowText Function

    If the target window is owned by another process and has a caption, GetWindowText retrieves the window caption text.

     

    And this thread had solved a question about how to retrieve the window caption, you can reference it.

    http://social.msdn.microsoft.com/forums/en-US/winforms/thread/d332a263-a11b-4638-b70a-468cfd195ced/

     

    If there’s anything unclear, please feel free to let me know.

    Best wishes,

    Mike

    -------------------------------------------------------------------

    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to the others community members reading the thread.

     

    *****************************************************

    [All-In-One Code Framework]

    Sample world! You will get more from this world!

    Welcome to the new world!

    Friday, November 19, 2010 11:23 AM

All replies

  • Hi Chuck Puckett,

    Welcome to MSDN Forums!

     

    You can use GetWindowText Function to retrieve the window caption.

     

    GetWindowText Function

    If the target window is owned by another process and has a caption, GetWindowText retrieves the window caption text.

     

    And this thread had solved a question about how to retrieve the window caption, you can reference it.

    http://social.msdn.microsoft.com/forums/en-US/winforms/thread/d332a263-a11b-4638-b70a-468cfd195ced/

     

    If there’s anything unclear, please feel free to let me know.

    Best wishes,

    Mike

    -------------------------------------------------------------------

    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to the others community members reading the thread.

     

    *****************************************************

    [All-In-One Code Framework]

    Sample world! You will get more from this world!

    Welcome to the new world!

    Friday, November 19, 2010 11:23 AM
  • There is no way to know what the "main window" of an application is. The Process.MainWindowTitle property attempts to guess by assuming that the first-created, top-level, visible window is the "main window". Because there is no way for a process to specify which is its "main window", this will always be a guess that ends up being correct most of the time.

    Task Manager's "Applications" tab does not enumerate processes, it enumerates windows that are: top-level, visible, and WS_EX_APPWINDOW. Given a window handle, you can get the thread, and subsequently the process that owns it.

    Friday, November 19, 2010 4:11 PM