How to get a process window class name from c#?

前端 未结 2 468
余生分开走
余生分开走 2021-01-14 12:22

How can I get the window class name of a certain process? I want to achieve this in c#.

I\'ve tried the process class in c# but I can only get the window name of the

2条回答
  •  无人及你
    2021-01-14 12:59

    I assume you mean you want to get the class name of the main window of a process.

    To do this, you will need to get the handle to the main window using the MainWindowHandle of your Process object, and then use the following interop method to obtain the class name:

    [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
    static extern int GetClassName(IntPtr hWnd, StringBuilder lpClassName, int nMaxCount);
    

    see pinvoke.net for sample code and MSDN for details on the function.

提交回复
热议问题