Domanda

Sto tentando di utilizzare questo esempio di codice per controllare la tastiera di Windows XP (On-screen osk.exe) da un C # (.NET 3.5) WinForms applicazione:

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

Come faccio a determinare il className preciso? Suppongo che il CaptionName è 'Tastiera su schermo'.

È stato utile?

Soluzione

Sembra che il nome di classe è: "OSKMainClass"

Ecco il codice che ho usato per trovare questo. E 'solo un semplice 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());
    }

ottenuto questo dalle seguenti fonti Attiva qualsiasi finestra con API  e funzione MSDN GetClassName

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top