lhw Posted November 12, 2011 Share Posted November 12, 2011 hello guys , i'm working on a program in autoit,this is my script goes so far,i just want ony a button highlighted in red when it pressed,the others still be in noraml, can anyone help on this, your help is greatly appreciated. #include <guiconstantsex.au3> #include <windowsconstants.au3> #include <buttonconstants.au3> GUICreate('My app', 200, 130) GUISetBkColor(0x000000) $btn1 = GUICtrlCreateButton('', 10, 5, 40, 20) $btn2 = GUICtrlCreateButton('', 10, 35, 40, 20) $btn3 = GUICtrlCreateButton('', 10, 65, 40, 20) $btn4 = GUICtrlCreateButton('', 10, 95, 40, 20) $lab = GUICtrlCreateLabel('', 90, 20, 100, 30) GUICtrlSetColor(-1, 0X07F823) GUISetState() While 1 $msg = GuiGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case $msg = $btn4 GUICtrlSetData($lab, 'You press button4') GUICtrlSetBkColor($btn4, 0XF80707) Case $msg = $btn3 GUICtrlSetData($lab, 'You press button3') GUICtrlSetBkColor($btn3, 0XF80707) Case $msg = $btn2 GUICtrlSetData($lab, 'You press button2') GUICtrlSetBkColor($btn2, 0XF80707) Case $msg = $btn1 GUICtrlSetData($lab, 'You press button1') GUICtrlSetBkColor($btn1, 0XF80707) EndSelect WEnd Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted November 12, 2011 Moderators Share Posted November 12, 2011 lhw, You could reset all of the buttons each time you press one - like this: expandcollapse popup#include <guiconstantsex.au3> #include <windowsconstants.au3> #include <buttonconstants.au3> GUICreate('My app', 200, 130) GUISetBkColor(0x000000) $btn1 = GUICtrlCreateButton('', 10, 5, 40, 20) $btn2 = GUICtrlCreateButton('', 10, 35, 40, 20) $btn3 = GUICtrlCreateButton('', 10, 65, 40, 20) $btn4 = GUICtrlCreateButton('', 10, 95, 40, 20) $lab = GUICtrlCreateLabel('', 90, 20, 100, 30) GUICtrlSetColor(-1, 0X07F823) GUISetState() While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case $msg = $btn4 GUICtrlSetData($lab, 'You press button4') _Clear_Buttons() GUICtrlSetBkColor($btn4, 0XF80707) Case $msg = $btn3 GUICtrlSetData($lab, 'You press button3') _Clear_Buttons() GUICtrlSetBkColor($btn3, 0XF80707) Case $msg = $btn2 GUICtrlSetData($lab, 'You press button2') _Clear_Buttons() GUICtrlSetBkColor($btn2, 0XF80707) Case $msg = $btn1 GUICtrlSetData($lab, 'You press button1') _Clear_Buttons() GUICtrlSetBkColor($btn1, 0XF80707) EndSelect WEnd Func _Clear_Buttons() For $i = $btn1 To $btn4 GUICtrlSetBkColor($i, 0XFEFEFE) Next EndFunc Or you could keep track of the last pressed button - like this: expandcollapse popup#include <guiconstantsex.au3> #include <windowsconstants.au3> #include <buttonconstants.au3> $iLast_Button = 0 GUICreate('My app', 200, 130) GUISetBkColor(0x000000) $btn1 = GUICtrlCreateButton('', 10, 5, 40, 20) $btn2 = GUICtrlCreateButton('', 10, 35, 40, 20) $btn3 = GUICtrlCreateButton('', 10, 65, 40, 20) $btn4 = GUICtrlCreateButton('', 10, 95, 40, 20) $lab = GUICtrlCreateLabel('', 90, 20, 100, 30) GUICtrlSetColor(-1, 0X07F823) GUISetState() While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case $msg = $btn4 GUICtrlSetData($lab, 'You press button4') GUICtrlSetBkColor($iLast_Button, 0XFEFEFE) $iLast_Button = $btn4 GUICtrlSetBkColor($btn4, 0XF80707) Case $msg = $btn3 GUICtrlSetData($lab, 'You press button3') GUICtrlSetBkColor($iLast_Button, 0XFEFEFE) $iLast_Button = $btn3 GUICtrlSetBkColor($btn3, 0XF80707) Case $msg = $btn2 GUICtrlSetData($lab, 'You press button2') GUICtrlSetBkColor($iLast_Button, 0XFEFEFE) $iLast_Button = $btn2 GUICtrlSetBkColor($btn2, 0XF80707) Case $msg = $btn1 GUICtrlSetData($lab, 'You press button1') GUICtrlSetBkColor($iLast_Button, 0XFEFEFE) $iLast_Button = $btn1 GUICtrlSetBkColor($btn1, 0XF80707) EndSelect WEnd All clear? M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
lhw Posted November 12, 2011 Author Share Posted November 12, 2011 Hi M23, Thanks for your solution, my problem gone:) Link to comment Share on other sites More sharing options...
dynamitemedia Posted January 19, 2016 Share Posted January 19, 2016 i have been working on this code trying to make it work with a set of images i get from a xml file... i haven't gotten that far yet i'm just setting the image count and later will get that here is the code i have so far.... expandcollapse popup#include <GUIConstantsEx.au3> #include <ButtonConstants.au3> #include <WinAPI.au3> #include <Skin.au3> #include <GDIPlus.au3> #include <Array.au3> #include <GuiButton.au3> #include <GuiListView.au3> #include "GUIScrollbars_Ex.au3" #include ".\Skins\Cosmo.au3" #include "_UskinLibrary.au3" _Uskin_LoadDLL() _USkin_Init(_Cosmo(True)) Global $X = 195, $Count = 0, $Width = 1250, $Height = 750 Global $sImagePath = @ScriptDir & "\Imgs\" ; Put your image paths in this array ;Global $aImage[8] = [$sImagePath & "League of Legends.bmp", $sImagePath & "Team Fortress 2.bmp", "Image_Path_3", "Image_Path_4", "Image_Path_5", "Image_Path_6", "Image_Path_7", "Image_Path_8"] Global $aImage[4000], $Button[4000] , $aLabel[4000], $aButton[4000], $aLabel[4000] Global $imgCount = 100 MainGui() Func MainGui() $MainGUI = GUICreate("", $Width, $Height) ; will create a dialog box that when displayed is centered] Opt("GUICoordMode", 20) For $i = 1 To $imgCount $X += 100 Next _GUIScrollbars_Generate($MainGUI, 0, $X) GUICtrlSetResizing(-1, $GUI_DOCKAUTO) ; Create labels For $i = 0 To $imgCount - 1 ; $Count += 1 For $j = 0 To 3 $iIndex = $j + ($i * 4) $aLabel[$iIndex] = GUICtrlCreateLabel("", 45 + (300 * $j), 25 + (300 * $i), 266, 266) GUICtrlSetBkColor($aLabel[$iIndex], 0xFFFFFF) GUICtrlSetState($aLabel[$iIndex], $GUI_DISABLE) Next Next ; Create buttons For $i = 0 To $imgCount - 1 ; $Count += 1 For $j = 0 To 3 $iIndex = $j + ($i * 4) $aButton[$iIndex] = GUICtrlCreateButton("Button " & ($iIndex + 1), 50 + (300 * $j), 30 + (300 * $i), 256, 256, $BS_BITMAP) GUICtrlSetImage($aButton[$iIndex], $aImage[$iIndex]) Next Next ; Set default button GUICtrlSetState($aButton[0], $GUI_FOCUS) GUICtrlSetBkColor($aLabel[0], 0x00FF00) $hActive = GUICtrlGetHandle($aButton[0]) ; Create dummy controls $cDummy_Up = GUICtrlCreateDummy() $cDummy_Dn = GUICtrlCreateDummy() GUISetState() ; Set the Up/Down keys as accelerators - they will only act like this when your GUI is active Local $aAccelKeys[2][2] = [["{UP}", $cDummy_Up], ["{DOWN}", $cDummy_Dn]] GUISetAccelerators($aAccelKeys) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $cDummy_Up, $cDummy_Dn _Vertical_TabStop() Case $aButton[$i] MsgBox($MB_SYSTEMMODAL, "Pressed", $aButton[$i]) EndSwitch ; Get focused control $hCurrFocus = _WinAPI_GetFocus() ; If it has changed If $hCurrFocus <> $hActive Then ; See if it is a button For $i = 0 To $imgCount If $hCurrFocus = GUICtrlGetHandle($aButton[$i]) Then ; Reset all the labels For $j = 0 To $imgCount GUICtrlSetBkColor($aLabel[$j], 0xFFFFFF) Next ; Highlight the correct label GUICtrlSetBkColor($aLabel[$i], 0x00FF00) ExitLoop EndIf Next $hActive = $hCurrFocus EndIf WEnd EndFunc ;==>Mainscript Func _Vertical_TabStop() ; Get active control $hActive = _WinAPI_GetFocus() For $i = 0 To 4 ; If it is a button If $hActive = GUICtrlGetHandle($aButton[$i]) Then ; Then determine index of the button above/below $iIndex = Mod($i + 4, $imgCount) ; And set focus GUICtrlSetState($aButton[$iIndex], $GUI_FOCUS) ; No point in looking further ExitLoop EndIf Next EndFunc Now a couple issues i am having and maybe you can see the simple mistak9s) 1.) when button is clicked it starts with saying button presses was the number 403 and stops at 504 2.) i cant go up and down , i can go down 3 and then it stops 3.) the highlighting only goes so far and just stops which is actually 503 4.) its showing more than 100 buttons 5.) the scroll bar should stop at the last row and i cant seem to get that to work either I feel i am so close but so far any help and explanation to what i am missing would be awesome Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now