1

このコードサンプルを使用して、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は「オンスクリーンキーボード」だと思います。

4

1 に答える 1

3

クラス名は「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());
    }

次のソースからこれを取得しましたAPIMSDNGetClassName関数を使用して任意のウィンドウをアクティブ化します

于 2010-08-30T21:36:32.117 に答える