Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Integer) As IntPtr Private Declare Function SetFocus Lib "user32.dll" (ByVal hwnd As Int32) As Int32 Private Sub btnfind_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnfind.Click Dim calculatorHandle As IntPtr = FindWindow(Nothing, "Calculatrice") If calculatorHandle = IntPtr.Zero Then MsgBox("Calculator is not running.") Return End If SetForegroundWindow(calculatorHandle) SendKeys.SendWait("111") SendKeys.SendWait("*") SendKeys.SendWait("11") SendKeys.SendWait("=") End Sub
Modifié par rsx602 le 28/08/2014 à 17:44
Je ne fait que verifier le titre non? Sinon si j'ai le handle je dois faire quoi apres ? Car avec le
Je perd le focus du moment qui louvre.
28 août 2014 à 18:49
En VB.NET, on oublie cette instruction, on utilise Try/Catch.
De plus :
Microsoft.VisualBasic.Mid(phrase, 17)
phrase.SubString(17)
28 août 2014 à 18:53
28 août 2014 à 21:54
28 août 2014 à 21:58
Une fois que tu as le Handle d'une fenêtre tu peux lui faire faire un peu ce que tu veux
http://www.vbforums.com/showthread.php?671719-RESOLVED-SetForeGroundWindow