代码之家  ›  专栏  ›  技术社区  ›  John M

找到屏幕键盘的类名?

  •  1
  • John M  · 技术社区  · 14 年前

    我想用这个 code sample 要从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");                            
    }
    

    如何确定准确的类名?我假设标题名称是“屏幕键盘”。

    1 回复  |  直到 14 年前
        1
  •  3
  •   Chmod    14 年前

    看起来类名是:“oskmainclass”

    这是我用来找到这个的代码。这只是一个简单的C表单应用程序

        [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());
        }
    

    从以下来源得到这个 Activate Any Window With API MSDN GetClassName function

    推荐文章