2010-08-30 4 views
1

Je cherche à utiliser ce code sample pour contrôler Windows XP Clavier à l'écran (osk.exe) d'un C# (.NET 3.5) Application Winforms:Recherche du nom de classe du clavier visuel?

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

Comment puis-je déterminer la className précise? Je suppose que CaptionName est 'Clavier à l'écran'.

Répondre

3

On dirait que le nom de classe est: « OSKMainClass »

Voici le code que je trouvais cela. Il est juste un simple C# Forms App

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

obtenu ceci à partir des sources suivantes Activate Any Window With API et MSDN GetClassName function