Sign in to follow this  
Followers 0
Tankbuster

[solved] Read GUICtrlSetTip from file - or how to access a control by it's name in variable

4 posts in this topic

#1 ·  Posted (edited)

Could someone please explain where my thoughts went wrong?

GUICtrlSetTip($arrTemp[$i][0],$arrTemp[$i][1])

I searched the forum and I found of course some posts, but I didn't found the right idea/hint.

I fear it's a face palm for me.....

I stripped down everything to this:

#include <Debug.au3>
#include <array.au3>

_DebugSetup(@ScriptName,False,2)

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 351, 270, 192, 124)
$Button1 = GUICtrlCreateButton("Button1", 64, 32, 217, 65)
$Button2 = GUICtrlCreateButton("Button2", 64, 112, 217, 65)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

local $MessageBundletextfile="MSGBUNDLE.INI"
local $arrTemp
$arrTemp=IniReadSection($MessageBundletextfile,"CONTROLTIP")
_ArrayDisplay($arrTemp)
for $i = 1 to $arrTemp[0][0]
_debugout($arrTemp[$i][0]&":"&$arrTemp[$i][1])
GUICtrlSetTip($arrTemp[$i][0],$arrTemp[$i][1])
Next

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit

EndSwitch
WEnd

File Conent of $MessageBundletextfile="MSGBUNDLE.INI"

[CONTROLTIP]
$hGui = "Hello"
$Button1 = "Tip on Button1"
$Button2 = "Tip on Button2"
Edited by Tankbuster

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Something like this?

#include <GUIConstantsEx.au3>
#Include <Array.au3>

GUICreate("PlayHD Example", 466, 190)
Local $bArray[1], $bTip[1]
For $i = 0 To 5
For $j = 0 To 5
_ArrayAdd($bArray,GUICtrlCreateButton("Button "&$i&" - "&$j, $i*75+8, $j*25+8, 75, 25))
_ArrayAdd($bTip,_GuiCtrlSetTip_($bArray[UBound($bArray)-1],"Tip Button "&$i&" - "&$j))
$bArray[0] += 1
$bTip[0] = $bArray[0]
Next
Next
$Label = GUICtrlCreateLabel("",8,165,460,17)
GUICtrlSetFont($Label,9,400,0,"Consolas")

GUISetState()

Local $Timer, $Debug = 1

While 1
$gMsg = GUIGetMsg()
Switch $gMsg
Case $GUI_EVENT_CLOSE
Exit GUIDelete()
Case $bArray[1] To $bArray[UBound($bArray)-1]
If $Debug Then $Timer = TimerInit()
For $i = 1 To UBound($bArray)-1
If $gMsg = $bArray[$i] Then
GUICtrlSetData($Label,"CtrlID : "&$bArray[$i]&"|CtrlText : "&GUICtrlRead($bArray[$i])&"|Tip : "&$bTip[$i])
ExitLoop
EndIf
Next
If $Debug Then ConsoleWrite("Time to Find Control : "&TimerDiff($Timer)&" ms."&@LF)
EndSwitch
WEnd

Func _GuiCtrlSetTip_($controlID, $tiptext , $title = "", $icon = 0, $options = 1)
GUICtrlSetTip($controlID, $tiptext , $title , $icon , $options)
Return $tiptext
EndFunc

It works fine until 300 Buttons

with more you need more time to wait.

300 button < 500 ms (~450 ms)

Or i dont understand your problem? (Sorry i'm not a good 'english-er')

Edited by PlayHD

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Use Eval and strip the $ from the key of your ini-section.

Eval=Return the value of the variable defined by an string.

GUICtrlSetTip(Eval($arrTemp[$i][0]),$arrTemp[$i][1])

And your script does not work since $Button1 is a variable and not a fixed string. Since you read out ini-sections as a sting, autoit cannot handle this. With eval, you translate that sting into the current value of the variable, which is the ControlID that is returned by GuiCtrlCreateXYZ here.

Edited by dabus

Share this post


Link to post
Share on other sites

dabus,

thank you, you solved it for me.

I was playing with eval before, but I missed my leading "$" in the INI file.

As always, reading the manual would have solved before asking.

I just added here the corrected code.

(and I fixed the OP because some includes are missing from copy and paste function)

#include <Debug.au3>
#include <array.au3>

_DebugSetup(@ScriptName,False,2)

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 351, 270, 192, 124)
$Button1 = GUICtrlCreateButton("Button1", 64, 32, 217, 65)
$Button2 = GUICtrlCreateButton("Button2", 64, 112, 217, 65)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

local $MessageBundletextfile="MSGBUNDLE.INI"
local $arrTemp
$arrTemp=IniReadSection($MessageBundletextfile,"CONTROLTIP")
_ArrayDisplay($arrTemp)
for $i = 1 to $arrTemp[0][0]
_debugout($arrTemp[$i][0]&":"&$arrTemp[$i][1])

;~ dabus fix ---------- START
GUICtrlSetTip(Eval($arrTemp[$i][0]),$arrTemp[$i][1])
;~ dabus fix ---------- END

Next

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit

EndSwitch
WEnd

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0

  • Similar Content

    • Skysnake
      By Skysnake
      Local $idRep = GUICtrlCreateMenuItem(">My First Report", $idReportmenu) GUICtrlSetTip($idRep, "Standard Report") Nothing appears obvious.  It may be impossible to set a tip to a menu Item... ?
      Any ideas please?
    • nitekram
      By nitekram
      I have tried _GUIToolTip_AddTool() & GUICtrlSetTip() & TrayItemGetHandle()  but have had no luck...is there a way that I have missed, or is it not possible to create a ToolTip for an individual item in the Tray?