Alternative AppActivate

rsx602 Messages postés 140 Date d'inscription jeudi 24 août 2006 Statut Membre Dernière intervention 28 août 2014 - 28 août 2014 à 14:54
 Royalcraft - 25 mars 2021 à 07:33
Bonjour,

Comme a l'habitude =) , je suis sur un projet et je cherche a donner le focus sur une page deja ouverte avec son titre .. par compte quand j'utilise AppActivate la page s'ouvre mais ne garde pas le focus. J'aimerais savoir si quelqu'un a donc une alternative a AppActivate. Merci =)

2 réponses

Whismeril Messages postés 19027 Date d'inscription mardi 11 mars 2003 Statut Contributeur Dernière intervention 24 avril 2024 656
28 août 2014 à 17:33
Dans ton dernier message, le pivert t'a orienté sur les handle. As tu regardé?
0
rsx602 Messages postés 140 Date d'inscription jeudi 24 août 2006 Statut Membre Dernière intervention 28 août 2014
Modifié par rsx602 le 28/08/2014 à 17:44
On Error Resume Next

        For Each proc As Process In Process.GetProcesses()
            ' check process' main window title 
            If proc.MainWindowTitle.StartsWith("Appel entrant de") Then
                Dim p As Process = Process.GetProcessById(proc.Id)
                Dim phrase As String = p.MainWindowTitle.ToString
                phrase = Microsoft.VisualBasic.Mid(phrase, 17)
                My.Computer.Clipboard.SetText(phrase)

                Exit For
        Next


Je ne fait que verifier le titre non? Sinon si j'ai le handle je dois faire quoi apres ? Car avec le

AppActivate("nom de la fenetre")


Je perd le focus du moment qui louvre.
0
NHenry Messages postés 15113 Date d'inscription vendredi 14 mars 2003 Statut Modérateur Dernière intervention 22 avril 2024 159
28 août 2014 à 18:49
"On Error Resume Next"
En VB.NET, on oublie cette instruction, on utilise Try/Catch.

De plus :
Microsoft.VisualBasic.Mid(phrase, 17)
phrase.SubString(17)
0
rsx602 Messages postés 140 Date d'inscription jeudi 24 août 2006 Statut Membre Dernière intervention 28 août 2014
28 août 2014 à 18:53
Merci , je modifie ca a linstant =)
0
rsx602 Messages postés 140 Date d'inscription jeudi 24 août 2006 Statut Membre Dernière intervention 28 août 2014
28 août 2014 à 21:54
Sinon pour avoir et gardé le focus dune page... un idee =) ?
0
Whismeril Messages postés 19027 Date d'inscription mardi 11 mars 2003 Statut Contributeur Dernière intervention 24 avril 2024 656
28 août 2014 à 21:58
C'est pas ce qui Le Pivert t'as indiqué.
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
0
Bon je sais que l'on est en 2021 et que y a peux de chance que quelqu'un regarde mais bon voici la soluton au problème:

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


Il fallait changé le "ByVal hwnd As Long" en "ByVal hwnd As Integer"

Voici plus d'informations à propos de ce problème si vous parlez anglais : https://stackoverflow.com/questions/53075123/error-lib-kernel32-dll-pinvokestackimbalance-vb-net
0
Rejoignez-nous