Jump to content

changing graphic colors

Recommended Posts


Hi folks,

I would like to create a traffic light like gui object, where the user (me) can see if something went well or not.

For that I wrote this:

$Kontrolllampe1 = GUICtrlCreateGraphic(432, 20, 31, 32)
GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0x000000, 0xFFCC33) ;== yellow
GUICtrlSetGraphic(-1, $GUI_GR_ELLIPSE, 6, 8, 20, 19)

I got seven traffic lights.

When I would like to change the color, what did I need to do?

I tried this:

Case $ButtonErstellen
        $Kontrolllampe1 = GUICtrlCreateGraphic(432, 20, 31, 32)
        GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0x000000, 0x00FF00) ;== green
        GUICtrlSetGraphic(-1, $GUI_GR_ELLIPSE, 6, 8, 20, 19)

but I have to click the button twice to see a result

Is there a possibility that I use something like

Case $ButtonErstellen
        $Kontrolllampe1 = GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0x000000, 0x00FF00) ;== green

(I know this doesn't work)

Thank you in advance

Share this post

Link to post
Share on other sites


Stop posting support questions in the Examples section!


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:


ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area


Share this post

Link to post
Share on other sites

this works:

Opt("GuiOnEventMode", 1)

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>

$hWnd = GUICreate("", 700, 320)
$Kontrolllampe1 = GUICtrlCreateGraphic(5, 5, 30, 31)
GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0x000000, 0xFFCC33) ;== yellow
GUICtrlSetGraphic(-1, $GUI_GR_ELLIPSE, 6, 8, 20, 19)
GUICtrlSetGraphic(-1, $GUI_GR_CLOSE)
GUICtrlSetOnEvent(-1, "_Change")

GUISetOnEvent(-3, "_MyExit")

While 1

Func _MyExit()

Func _Change()
    $iColor = Execute("0x"&Hex(Random(0, 255, 1), 2)&Hex(Random(0, 255, 1), 2)&Hex(Random(0, 255, 1), 2))
    GUICtrlSetGraphic($Kontrolllampe1, $GUI_GR_COLOR, 0x000000, $iColor) ;== yellow
    GUICtrlSetGraphic($Kontrolllampe1, $GUI_GR_ELLIPSE, 6, 8, 20, 19)
    GUICtrlSetGraphic(-1, $GUI_GR_CLOSE)
    GUICtrlSetGraphic($Kontrolllampe1, $GUI_GR_REFRESH)

Click on the graphic to change the color

Share this post

Link to post
Share on other sites

and this...

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>

Local $gui010 = GUICreate('Stop Light')

Local $gr010 = GUICtrlCreateGraphic(50, 50, 130, 130)
GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0x00ff00, 0x00FF00)
GUICtrlSetGraphic(-1, $GUI_GR_ELLIPSE, 35, 50, 230, 230)


AdlibRegister('StopAndGo', 500)

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $gui_event_close

Func StopAndGo()

    Local Static $sw = True

    Local $color = ($sw = True) ? 0x00ff00 : 0xff0000

    GUICtrlSetGraphic($gr010, $GUI_GR_COLOR, $color, $color)
    GUICtrlSetGraphic($gr010, $GUI_GR_ELLIPSE, 35, 50, 230, 230)
    GUICtrlSetGraphic($gr010, $Gui_gr_refresh)

    $sw = Not $sw

EndFunc   ;==>StopAndGo


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post

Link to post
Share on other sites

and this...

Click the traffic light to change colour.
The traffic lights can be dragged.
Changing the value of  the variable, $iFactor, will change the size of the traffic lights.
Press Esc to exit.

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <SendMessage.au3>

; ============ Get focus on traffic lights then press Esc to Exit ===================
; ============ Traffic lights can be dragged                      ===================

Global $iFactor = 14 ; <<----- Bigger the number, the bigger the traffic lights size - say between 0.5 and 14+
Local $iLeft = 20, $iTop = 20
Global $aLights[3], $iFlag = 1
Global $hWnd = GUICreate("", 28 * $iFactor, 70 * $iFactor, $iLeft, $iTop, $WS_POPUP + $WS_BORDER, $WS_EX_TOPMOST)
GUISetBkColor(0x808080, $hWnd)

For $i = 0 To 2
    $aLights[$i] = GUICtrlCreateGraphic(2 * $iFactor, (2 + ($i * 20)) * $iFactor, 28 * $iFactor, 31 * $iFactor)
    GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0x000000, $i = 0 ? 0xFF0000 : 0x000000) ;== red
    GUICtrlSetGraphic(-1, $GUI_GR_ELLIPSE, 2 * $iFactor, 2 * $iFactor, 20 * $iFactor, 20 * $iFactor)


While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            _SendMessage($hWnd, $WM_SYSCOMMAND, 0xF012, 0)

Func _Change()
    $iFlag = Mod($iFlag + 1, 3)

    GUICtrlSetGraphic($aLights[0], $GUI_GR_COLOR, 0x000000, $iFlag = 1 ? 0xFF0000 : 0x000000) ;== Red else Black
    GUICtrlSetGraphic($aLights[0], $GUI_GR_ELLIPSE, 2 * $iFactor, 2 * $iFactor, 20 * $iFactor, 20 * $iFactor)
    GUICtrlSetGraphic($aLights[0], $GUI_GR_REFRESH)

    GUICtrlSetGraphic($aLights[1], $GUI_GR_COLOR, 0x000000, ($iFlag = 0) ? 0xFFFF00 : 0x000000) ;== Yellow else Black
    GUICtrlSetGraphic($aLights[1], $GUI_GR_ELLIPSE, 2 * $iFactor, 2 * $iFactor, 20 * $iFactor, 20 * $iFactor)
    GUICtrlSetGraphic($aLights[1], $GUI_GR_REFRESH)

    GUICtrlSetGraphic($aLights[2], $GUI_GR_COLOR, 0x000000, $iFlag = 2 ? 0x00FF00 : 0x000000) ;== Green else Black
    GUICtrlSetGraphic($aLights[2], $GUI_GR_ELLIPSE, 2 * $iFactor, 2 * $iFactor, 20 * $iFactor, 20 * $iFactor)
    GUICtrlSetGraphic($aLights[2], $GUI_GR_REFRESH)
EndFunc   ;==>_Change


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

  • Similar Content

    • Xandy
      By Xandy
      Waxworks Code Wheel.
      Written in AutoIt with SDL.
    • binhn211
      By binhn211
      I need help with graphics
      I need to drawimage out the desktop continuous image is not removed, without the support of the "while"
      when I used while the image will blink

    • dreamzboy
      By dreamzboy

      I would like to know how to go about making the following item clear and transparent.   They're currently being highlight by a blue/black bar over the texts.  I've read through pages and pages of "transparent group, radios, and checkboxes" but none looks like a simple implemenation nor does it apply to my case.
      Groups Text Radio Text Also, I'm unable to see my tabs perhaps it's being hidden by the background picture? (see figure 2 for what it's supposed to look like).  Using the code from AdmiralClaws, it made the radio graphic or style a little plain and I would like to restore it.  I don't need the tab section transparent, just the dark grey area around it.
      $chk = GUICtrlCreateCheckbox("This is checkbox - Lorem ipsum dolor sit amet.", 20, 20) DllCall("UxTheme.dll", "int", "SetWindowTheme", "hwnd", GUICtrlGetHandle(-1), "wstr", 0, "wstr", 0) $lbl = GUICtrlCreateLabel("This is label - Lorem ipsum dolor sit amet", 20, 100) $rdo = GUICtrlCreateRadio("This is radio - Lorem ipsum dolor sit amet", 20, 180) DllCall("UxTheme.dll", "int", "SetWindowTheme", "hwnd", GUICtrlGetHandle(-1), "wstr", 0, "wstr", 0) Test Program
      #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Example() Func Example() ; Create a GUI with various controls. Local $hGUI = GUICreate("Example", 400, 300) ; GUICtrlCreatePic (".\background.bmp", 0, 0, 400, 300) GUICtrlCreateTab (20, 20, 360, 260) GUICtrlCreateTabItem ("Option 1") GUICtrlCreateGroup ("Radio", 40, 60, 320, 200) $radio1 = GUICtrlCreateRadio ("Radio 1", 60, 80) ;DllCall("UxTheme.dll", "int", "SetWindowTheme", "hwnd", GUICtrlGetHandle($radio1), "wstr", 0, "wstr", 0) $radio2 = GUICtrlCreateRadio ("Radio 2", 60, 110) ;DllCall("UxTheme.dll", "int", "SetWindowTheme", "hwnd", GUICtrlGetHandle($radio2), "wstr", 0, "wstr", 0) GUICtrlCreateTab (30, 30, 360, 260) GUICtrlCreateTabItem ("Option 2") GUICtrlCreateGroup ("Radio", 40, 60, 320, 200) $radio3 = GUICtrlCreateRadio ("Radio 3", 60, 80) ;DllCall("UxTheme.dll", "int", "SetWindowTheme", "hwnd", GUICtrlGetHandle(-1), "wstr", 0, "wstr", 0) $radio4 = GUICtrlCreateRadio ("Radio 4", 60, 110) ;DllCall("UxTheme.dll", "int", "SetWindowTheme", "hwnd", GUICtrlGetHandle(-1), "wstr", 0, "wstr", 0) ; Display the GUI. GUISetState(@SW_SHOW, $hGUI) ; Loop until the user exits. While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd ; Delete the previous GUIs and all controls. GUIDelete($hGUI) EndFunc ;==>Example
      (Figure 1)

      (Figure 2)
    • eukalyptus
      By eukalyptus
      Direct2D UDF
      Is Direct2D the new GDIPlus?
      Hmm - I think it is not! It is too complicated and Microsoft failed at the design
      But Direct2D is hardware accelerated and it has some features I always missed in GDIPlus, like loading/saving animated GIF´s, combining path´s or drawing bitmap´s in a perspective view...
      check out the examples to see, what can be done
      Download: https://autoit.de/index.php/Attachment/70-Direct2D-7z/
      Or visit the original topic at the german forum - link in my signature
    • prazetto
      By prazetto
      UDF provide graphical control based on static class.


      v1.01. Fix on Syntax Error Checking

      Choose server where you will download:
      fxControl.zip - code.google.com (renamed from zettoControl_v1.02.zip)
      fxControl.zip - autoitscript.com
      The next version of this UDF will named as fxControl (Control Framework).


      Application using zettoControl

      Z-Compressor [link fixed]
      Clean PC
      Clean PC Source available in spoiler below 'Codice Sorgente' text,
      in that page. but download link: dead. Its still useful because at
      least the source are here while you able replace image file with
      what you have.


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.