Sign in to follow this  
Followers 0
CharlesEly

Duplicate ControlID

7 posts in this topic

Hi All,

I'm new to forums so forgive if I say something stupid!!

I think controlID's are supposed to be unique, but I keep getting a duplicate in the following code ($TTransDec and $TTransInc are both 8), If I get rid of $icon all is well.

Presumably I am doing something stupid, any ideas?

CODE
#include <Misc.au3>

#include <GuiConstants.au3>

$TrayColour=TrayCreateItem("Colour")

$TrayTransInc = TrayCreateItem("Increase Transparency")

$TrayTransDec = TrayCreateItem("Decrease Transparency")

$TrayExit= TrayCreateItem("Exit")

$Overlay = GuiCreate("SLSBOVERLAY", 400, 200, -1, -1,$WS_POPUPWINDOW+$WS_THICKFRAME,$WS_EX_TOOLWINDOW+$WS_EX_TOPMOST )

$OverlayLabel=GUICtrlCreateLabel("",0,0,400, 200,-1,$GUI_WS_EX_PARENTDRAG )

;$icon = GUICtrlCreateIcon ("c:\programming\slsb.ico",-1, 5,5)

$TMenu = GUICtrlCreateContextMenu ($OverlayLabel)

$TChangeColour = GUICtrlCreateMenuitem ("Colour", $Tmenu)

$TTransInc = GUICtrlCreateMenuItem("Increase Transparency", $Tmenu)

$TTransDec = GUICtrlCreateMenuItem("Decrease Transparency", $Tmenu)

$TExit = GUICtrlCreateMenuitem ("Exit", $Tmenu)

MsgBox(1, "", $TTransInc&$TTransDec&$TrayTransInc&$TrayTransDec)

Share this post


Link to post
Share on other sites



That isn't the ID it is reporting. It is reporting the state of the control.

I'm now even more confused, according to help the return value of GUICtrlCreate??? is the controlID, you say it isn't, I don't understand.

Charles

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

$TTransInc and $TTransDec the way you have it set up are handles...I believe that is the term. You use the handles to control that function (pressing the menu button).

Ex.

while 1
$msg = GuiGetMsg()
    Select
         Case $msg = $TTransInc
             ;Do whatever you program
     endselect
wend

If you want to see the controlID use Autoit Windows Info and hover over the button.

Edited by Champak

Share this post


Link to post
Share on other sites

Thanks, that was what I was doing, but it didn't work because I was getting two identical values.

I moved the $icon..... line to after the menu item lines and everything works OK - all Handles ControlIds or whatever they are called are unique and the rest of the code functions just as I expected it to.

Thanks for your help

$TTransInc and $TTransDec the way you have it set up are handles...I believe that is the term. You use the handles to control that function (pressing the menu button).

Ex.

while 1
$msg = GuiGetMsg()
    Select
         Case $msg = $TTransInc
             ;Do whatever you program
     endselect
wend

If you want to see the controlID use Autoit Windows Info and hover over the button.

Share this post


Link to post
Share on other sites

Thanks, that was what I was doing, but it didn't work because I was getting two identical values.

I moved the $icon..... line to after the menu item lines and everything works OK - all Handles ControlIds or whatever they are called are unique and the rest of the code functions just as I expected it to.

Thanks for your help

There are no handles in the code you originally posted, they are all ControlIDs. What you are seeing is that ControlIDs are only unique within a particular GUI, not the entire script's activity. Remember a single script can have many GUIs. In this case, note the Tray Menu is a different GUI from the one you created in the script, and so they have their own sequence of ControlIDs. This will make it clearer:

#include <Misc.au3>
#include <GuiConstants.au3>

Global $icon = ""

$TrayColour = TrayCreateItem("Colour")

$TrayTransInc = TrayCreateItem("Increase Transparency")
$TrayTransDec = TrayCreateItem("Decrease Transparency")
$TrayExit = TrayCreateItem("Exit")


$Overlay = GUICreate("SLSBOVERLAY", 400, 200, 200, 200, $WS_POPUPWINDOW + $WS_THICKFRAME, $WS_EX_TOOLWINDOW + $WS_EX_TOPMOST)
$OverlayLabel = GUICtrlCreateLabel(".", 0, 0, 400, 200, -1, $GUI_WS_EX_PARENTDRAG)

$icon = GUICtrlCreateIcon ("C:\Program Files\AutoIt3\Icons\FileType1.ico",-1, 5,5)

$TMenu = GUICtrlCreateContextMenu($OverlayLabel)
$TChangeColour = GUICtrlCreateMenuItem("Colour", $TMenu)
$TTransInc = GUICtrlCreateMenuItem("Increase Transparency", $TMenu)
$TTransDec = GUICtrlCreateMenuItem("Decrease Transparency", $TMenu)
$TExit = GUICtrlCreateMenuItem("Exit", $TMenu)
GUISetState()


MsgBox(1, "", "$TrayColour = " & $TrayColour & @CRLF & _
        "$TrayTransInc = " & $TrayTransInc & @CRLF & _
        "$TrayTransDec = " & $TrayTransDec & @CRLF & _
        "$TrayExit = " & $TrayExit & @CRLF & @CRLF & _
        "$OverlayLabel = " & $OverlayLabel & @CRLF & @CRLF & _
        "$icon = " & $icon & @CRLF & @CRLF & _
        "$TMenu = " & $TMenu & @CRLF & _
        "$TChangeColour = " & $TChangeColour & @CRLF & _
        "$TTransInc = " & $TTransInc & @CRLF & _
        "$TTransDec = " & $TTransDec & @CRLF & _
        "$TExit = " & $TExit)

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

Thank you! I thought that they were controlIDs but began to doubt myself when I read the other replies. It's all a bit clearer now. I thought I read somewhere in help that controlIDs were unique throughout a script even in different windows, I obviously misread something.

There are no handles in the code you originally posted, they are all ControlIDs. What you are seeing is that ControlIDs are only unique within a particular GUI, not the entire script's activity. Remember a single script can have many GUIs. In this case, note the Tray Menu is a different GUI from the one you created in the script, and so they have their own sequence of ControlIDs. This will make it clearer:

#include <Misc.au3>
#include <GuiConstants.au3>

Global $icon = ""

$TrayColour = TrayCreateItem("Colour")

$TrayTransInc = TrayCreateItem("Increase Transparency")
$TrayTransDec = TrayCreateItem("Decrease Transparency")
$TrayExit = TrayCreateItem("Exit")


$Overlay = GUICreate("SLSBOVERLAY", 400, 200, 200, 200, $WS_POPUPWINDOW + $WS_THICKFRAME, $WS_EX_TOOLWINDOW + $WS_EX_TOPMOST)
$OverlayLabel = GUICtrlCreateLabel(".", 0, 0, 400, 200, -1, $GUI_WS_EX_PARENTDRAG)

$icon = GUICtrlCreateIcon ("C:\Program Files\AutoIt3\Icons\FileType1.ico",-1, 5,5)

$TMenu = GUICtrlCreateContextMenu($OverlayLabel)
$TChangeColour = GUICtrlCreateMenuItem("Colour", $TMenu)
$TTransInc = GUICtrlCreateMenuItem("Increase Transparency", $TMenu)
$TTransDec = GUICtrlCreateMenuItem("Decrease Transparency", $TMenu)
$TExit = GUICtrlCreateMenuItem("Exit", $TMenu)
GUISetState()


MsgBox(1, "", "$TrayColour = " & $TrayColour & @CRLF & _
        "$TrayTransInc = " & $TrayTransInc & @CRLF & _
        "$TrayTransDec = " & $TrayTransDec & @CRLF & _
        "$TrayExit = " & $TrayExit & @CRLF & @CRLF & _
        "$OverlayLabel = " & $OverlayLabel & @CRLF & @CRLF & _
        "$icon = " & $icon & @CRLF & @CRLF & _
        "$TMenu = " & $TMenu & @CRLF & _
        "$TChangeColour = " & $TChangeColour & @CRLF & _
        "$TTransInc = " & $TTransInc & @CRLF & _
        "$TTransDec = " & $TTransDec & @CRLF & _
        "$TExit = " & $TExit)

:)

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