2010-08-30 71 views
1

我試圖用這個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");        
} 

如何確定準確的className?我假設CaptionName是'屏幕鍵盤'。

回答

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

從下列來源得到這個Activate Any Window With APIMSDN GetClassName function