查找屏幕键盘的类名?
我试图使用此代码示例从C#(。NET 3.5)Winforms应用程序控制Windows XP屏幕键盘(OSK.exe):
[DllImport("User32.dll")]public static extern Int32 SetForegroundWindow(int hWnd); [DllImport("user32.dll")]public static extern int FindWindow(string lpClassName, string lpWindowName); private void BringToFront(string className,string CaptionName) { SetForegroundWindow(FindWindow(className,CaptionName)); } private void Form1_Load(object sender, EventArgs e) { BringToFront("Notepad", "Untitled - Notepad"); }
如何确定准确的className? 我假设CaptionName是’屏幕键盘’。
看起来类名是:“OSKMainClass”
这是我用来找到这个的代码。 它只是一个简单的C#Forms应用程序
[DllImport("User32.dll")] public static extern Int32 SetForegroundWindow(int hWnd); [DllImport("user32.dll")] public static extern int FindWindow(string lpClassName, string lpWindowName); [DllImport("user32.dll")] public static extern int GetClassName(int hWnd, StringBuilder lpClassName, int nMaxCount); public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { int hWnd = FindWindow(null, "On-Screen Keyboard"); StringBuilder buffer = new StringBuilder(128); GetClassName(hWnd, buffer, buffer.Capacity); MessageBox.Show(buffer.ToString()); }
从以下来源获得此function 使用API和MSDN GetClassName函数 激活任何窗口
上述就是C#学习教程:查找屏幕键盘的类名?分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)
本文来自网络收集,不代表计算机技术网立场,如涉及侵权请点击右边联系管理员删除。
如若转载,请注明出处:https://www.ctvol.com/cdevelopment/1012718.html