Jump to content

Duplicate ControlID


Recommended Posts

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)

Link to comment
Share on other sites

$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
Link to comment
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.

Link to comment
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
Link to comment
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)

:)

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...