Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/299.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 获取可读格式的窗口类型_C#_.net_Wpf - Fatal编程技术网

C# 获取可读格式的窗口类型

C# 获取可读格式的窗口类型,c#,.net,wpf,C#,.net,Wpf,我刚开始学习C#和WPF。有没有办法得到窗户的类型?例如,我使用它来获取窗口上的文本: [DllImport("user32.dll")] static extern int GetWindowText(IntPtr hWnd, StringBuilder text, int count); 返回:“提问-堆栈溢出-谷歌浏览器” 我只想获得“谷歌浏览器”。我试过了 这将返回“Chrome\u WidgetWin\u 1”。有没有一个更好的方法是我没有的?没有一个像您描述的那样分配给窗口的“类型

我刚开始学习C#和WPF。有没有办法得到窗户的类型?例如,我使用它来获取窗口上的文本:

[DllImport("user32.dll")]
static extern int GetWindowText(IntPtr hWnd, StringBuilder text, int count);
返回:“提问-堆栈溢出-谷歌浏览器”

我只想获得“谷歌浏览器”。我试过了

这将返回“Chrome\u WidgetWin\u 1”。有没有一个更好的方法是我没有的?

没有一个像您描述的那样分配给窗口的“类型”。最接近的是您已经检索到的类名

如果所有窗口都遵循相同的标题文本模式“some text”-“whatever”-“Google Chrome”,则可以解析标题文本,只提取最后一个值。破折号的数量或者其他什么都不重要,只要在“谷歌浏览器”之前有破折号,你就可以将其提取出来

string windowTypeName = string.Split('-').LastOrDefault();
如果标题文本中没有标题文本或破折号,则返回“Google Chrome”或null

编辑


您还可以获得与窗口关联的进程名,如果它是chrome.exe,那么您可以假设窗口类型为“Google chrome”

是的,我想这是最好的方法
string windowTypeName = string.Split('-').LastOrDefault();