Page 1 sur 1

[..] ControlCommand FindString retourne 0

Posté : jeu. 01 févr. 2018 08:24
par A2Energie
Bonjour amis Autoitiens, :D

J'ai un problème qui me semble impossible à résoudre, c'est pourquoi je tente sur le forum afin d'essayer de le régler.

J'ai un programme tiers comportant une comboBox (je précise que la comboBox provient d'un programme tiers) donc je ne peux pas utiliser les Gui... ou _Gui...
Je passe par ControlCommand(...
Mon but est de repérer si un string existe dans cette comboBox, j'ai donc créé une fonction tt bête me retournant si oui ou non elle existe, et cela fonctionne très bien.
Le problème :
Lorsque le string se trouve en première position de la comboBox le : FindString me retourne 0
ET lorsque le string n'existe pas dans la comboBox le : FindString me retourne 0
Donc impossible de pouvoir discerner si le string existe pas ou si le string est en position 0 de la comboBox.

Voici le code :
Func FCombo_Exists($FCombo_Exists1, $ScriptLine = @ScriptLineNumber)
; -------------------------------------------
; - Description :
;     Permet de rechercher si un string existe
; - Variables :
;     $FCombo_Exists1 = Nom à rechercher
; - Retourne :
;     True / False
; -------------------------------------------
   $FCombo_Exists_Temp1 = False
   If ControlCommand("", "", "[CLASS:ComboBox; INSTANCE:1]", "FindString", $FCombo_Exists1) > 0 Then
     $FCombo_Exists_Temp1 = True
;~      Else ; Je préfère ne pas utiliser cette méthode alternative, car cela m'entraine d'autres problèmes (du faite de la selection : SetCurrentSelection)
;~        ControlCommand("", "", "[CLASS:ComboBox; INSTANCE:1]", "SetCurrentSelection", 0)
;~        If ControlCommand("", "", "[CLASS:ComboBox; INSTANCE:1]", "GetCurrentSelection", "") = $FCombo_Exists1 Then $FCombo_Exists_Temp1 = True
     EndIf
   Return $FCombo_Exists_Temp1
EndFunc
Je vous remercie de votre lecture, et de vos réponses.

Re: [..] ControlCommand FindString retourne 0

Posté : jeu. 01 févr. 2018 09:09
par mikell
ControlGetText + StringInStr ne marcherait pas ?

Re: [..] ControlCommand FindString retourne 0

Posté : jeu. 01 févr. 2018 11:38
par orax
Est-ce que @error est différent de "0" quand ControlCommand ne trouve pas la chaîne ?

Code : Tout sélectionner

ControlCommand("", "", "[CLASS:ComboBox; INSTANCE:1]", "FindString", $FCombo_Exists1)
ConsoleWrite(@error & @CRLF)

Re: [..] ControlCommand FindString retourne 0

Posté : jeu. 01 févr. 2018 11:43
par A2Energie
Bonjour Mikell,

Merci pour ta réponse.
Nan ControlGetText me retourne vide, j'ai également essayé sur son parent (Vide aussi)
Au passage la fonction Test() (ci dessous) est bien pratique,
Test(ControlGetText("", "", "[CLASS:ComboBox; INSTANCE:1]"), "test 1") ; Retourne VIDE
Test(ControlGetText("", "", "[CLASS:PageControl; INSTANCE:1]"), "test 2") ; Retourne VIDE


Func Test($Test1, $Test2 = "", $ScriptLine = @ScriptLineNumber)
   If IsArray($Test1) Then
     _ArrayDisplay($Test1, "(" & $ScriptLine & ") : " & $Test2)
   Else
     MsgBox(1, "(" & $ScriptLine & ") : " & $Test2, $Test1)
   EndIf
   Sleep(1000)
EndFunc

Re: [..] ControlCommand FindString retourne 0

Posté : jeu. 01 févr. 2018 11:45
par A2Energie
Merci Orax pour ta réponse, nos réponses ce sont croisées,

Oui j'ai essayé @Error et a chaque fois 0
Que le résultat soit introuvable ou que le résultat soit trouvable.

Ca serait trop facile :D

Re: [..] ControlCommand FindString retourne 0  

Posté : jeu. 01 févr. 2018 15:46
par mikell
A tout hasard .... :mrgreen:
#include <GuiComboBoxEx.au3>

$hWnd = ControlGetHandle("titre de la fenêtre", "", "[CLASS:ComboBox; INSTANCE:1]")
$list = _GUICtrlComboBoxEx_GetList($hWnd)
Msgbox(0,"", $list)

Re: [..] ControlCommand FindString retourne 0

Posté : ven. 02 févr. 2018 07:50
par A2Energie
OMG mikell !!! :shock:

Oui ca fonctionne.
Je peux donc utiliser des fonctions GUI, ce qui va me libérer d'un tel poids.

Ps: je sais pas si j'ai été assez stupide pour ne jamais y avoir pensé, ou si je m'y suis mal pris. L'important étant que je vais pouvoir avancer.

Merci :D :bisou:

Re: [..] ControlCommand FindString retourne 0

Posté : ven. 02 févr. 2018 08:57
par A2Energie
Pour ceux qui n'aiment pas les Udf voici la version sans Udf :

Le problème se situe sur la réponse du Dll :
Origine : DllCall("user32.dll", "lresult", "SendMessageW", "hwnd", $hWnd, "uint", 0x14C, "int", 0, "wstr", $FCombo_Exists1)
Solution : DllCall("user32.dll", "lresult", "SendMessageW", "hwnd", $hWnd, "uint", 0x14C, "int", -1, "wstr", $FCombo_Exists1)
Func FCombo_Exists($FCombo_Exists1, $ScriptLine = @ScriptLineNumber)
; -------------------------------------------
; - Description :
;               Permet de rechercher si un string existe
; - Variables :
;               $FCombo_Exists1 = Nom à rechercher
; - Retourne :
;               True / False
; -------------------------------------------
   Local $FCombo_Exists_Temp1 = False
   Local $FCombo_Exists_Temp2 = ""
   $hWnd = ControlGetHandle("", "", "[CLASS:ComboBox; INSTANCE:1]")
   If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
   $FCombo_Exists_Temp2 = DllCall("user32.dll", "lresult", "SendMessageW", "hwnd", $hWnd, "uint", 0x14C, "int", -1, "wstr", $FCombo_Exists1)
   If $FCombo_Exists_Temp2[0] >= 0 Then $FCombo_Exists_Temp1 = True
   Return $FCombo_Exists_Temp1
EndFunc