Sign in to follow this  
Followers 0
armoros

Color Select Example

1 post in this topic

These are 2 useful examples on how to change the color of a GUI background.

They are made by a user named ReaperX from another forum, not Autoit

and i didn't ask his permission. Can't tell the forum, maybe it breaks this forums rules.

1) A Sample GUI. It Just Uses 3 Radio Buttons and You Choose One to Change the GUI BG Color to.

include <GUIConstants.au3>
MainGUI()
Func MainGUI()
    GUICreate("ReaperX's Test GUI")
    $file = GUICtrlCreateMenu("File")
    $file_notepad = GUICtrlCreateMenuItem("Open Notepad", $file)
    $file_computer = GUICtrlCreateMenuItem("Open My Computer", $file)
    $file_exit = GUICtrlCreateMenuItem("Exit", $file)
    $actions = GUICtrlCreateMenu("Actions")
    $actions_txt_file = GUICtrlCreateMenuItem("Open Text File", $actions)
    $actions_calc = GUICtrlCreateMenuItem("Open Calculator", $actions)
    $help = GUICtrlCreateMenu("Help")
    $help_about = GUICtrlCreateMenuItem("About", $help)
    $tab_set = GUICtrlCreateTab(110, 100, 135, 150)
    $tab_1 = GUICtrlCreateTabItem("Change BG")
    $bg_red_radio = GUICtrlCreateRadio("Red", 115, 125)
    $bg_green_radio = GUICtrlCreateRadio("Green", 115, 145)
    $bg_yellow_radio = GUICtrlCreateRadio("Yellow", 115, 165)
    $tab_2 = GUICtrlCreateTabItem("AutoIt Info")
    GUISetState()
    While 1
        $msg = GUIGetMsg()
        If $msg = $GUI_EVENT_CLOSE Then ExitLoop
        If $msg = $file_notepad Then
             $file = Run("notepad.exe")
         EndIf
        if $msg = $file_computer Then
             $file = Run("explorer.exe")
         EndIf
        If $msg = $file_exit Then
             Exit
         EndIf
        If $msg = $actions_txt_file Then
            $txt_file_1 = FileOpenDialog("Choose a Text File to Open...", @DesktopDir, "Text Files(*.txt)")
            FileOpen($txt_file_1)
         EndIf
        If $msg = $actions_calc Then
            Run("calc.exe")
         EndIf
        If $msg = $help_about Then
            $help = MsgBox(0, "About", "This Test GUI Was Created by ReaperX")
        EndIf
        Select
        Case $msg = $bg_red_radio
            GUISetBkColor(0xED1C24)
        Case $msg = $bg_green_radio
            GUISetBkColor(0x22B14C)
        Case $msg = $bg_yellow_radio
            GUISetBkColor(0xFFF200)
            EndSelect
    WEnd
EndFunc

2) Brings up a Color Pallette in the GUI and You Use it To Select a Color to Change the BG of the GUI to.

#Include <GUIConstants.au3>
#Include <Misc.au3>
GUICreate("Choose Color")
$button = GUICtrlCreateButton("Choose Color", 150, 150)
$iReturnType = 2
GUISetState()
While 1
    $msg = GUIGetMsg()
    if $msg = $GUI_EVENT_CLOSE Then Exit
        Select
        Case $msg = $button
            $color = _ChooseColor($iReturnType)
            GUISetBkColor($color)
        EndSelect
        WEnd

[font="verdana, geneva, sans-serif"] [/font]

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

    • SaeidN
      By SaeidN
      Hi,
      I saw a couple topics about both mousedrag and imagesearch in background or minimized window, but none of them has the solution, and they were old topics.
      So I wanted to ask whether there is a way to mouse drag without the cursor to move, (I want to use mouse when mousedrag is working on a window). I don't know whether I can mix ControlMove with some other stuff or any other way?
      And also for the image search, is there any way to search for image (or pixel) in a background or minimized window? I thought maybe there is a au3 or dll or ... file for doing this.
      Another question I have: Any way to pinch zoom (two fingers) a window like "windows photo viewer" to zoom in or out? I saw something almost the same here, but not what I want.
      I appreciate it.
    • FMS
      By FMS
      Hello,
      I'm rather new at Autoit (picked it up again afther a couple of years) but i dont know what I'm doing wrong here.
      I hope somebody can help me making this script "better readeble" and explain what I'm doing wrong here.
      The thing that i want to do here is making a tool that helps me whit doing mine work.
      Also want to do the "ping" command in the background whit only a msgbox if ok or not.
      In the code I'm writing now I'm using Send commands but know that there is a better way for this.
      At this point there is a error also whish i do not udnerstand where it is comming from.
      the error i get is:
      MsgBox($MB_SYSTEMMODAL, "Error", " Error no IP or name is filled in")
      MsgBox(^ ERROR
      Could somebody help me whit looking at this code?
       
      #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> $Form1 = GUICreate("Form1", 385, 112, 192, 124) $iIP = GUICtrlCreateInput("", 80, 16, 209, 21) $btn_ping = GUICtrlCreateButton("Ping", 24, 56, 89, 25) $btn_vnc = GUICtrlCreateButton("VNC", 136, 56, 89, 25) $btn_evr = GUICtrlCreateButton("Eventvieuwer", 248, 56, 89, 25) GUISetState(@SW_SHOW) Func check_input() If GUICtrlRead($iIP) = "" Then Return False Else Return True Endif EndFunc While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $btn_ping $check = check_input() If ($check = False) Then Run ("cmd.exe") WinWaitActive("C:\WINDOWS\system32\cmd.exe") Send ("ping " & GUICtrlRead($iIP) & "{ENTER}") WinClose ("C:\WINDOWS\system32\cmd.exe") ;if ping OK then msgbox OK else NOK Else MsgBox($MB_SYSTEMMODAL, "Error", " Error no IP or name is filled in") EndIf Case $btn_vnc $check = check_input() If ($check = False) Then Run ("cmd.exe") WinWaitActive("C:\WINDOWS\system32\cmd.exe") Send ("eventvwr.exe " & GUICtrlRead($iIP) & "{ENTER}") WinClose ("C:\WINDOWS\system32\cmd.exe") Else MsgBox($MB_SYSTEMMODAL, "Error", " Error no IP or name is filled in") EndIf Case $btn_evr $check = check_input() If ($check = False) Then Run ("cmd.exe") WinWaitActive("C:\WINDOWS\system32\cmd.exe") Send ("vncviewer " & GUICtrlRead($iIP) & "{ENTER}") WinClose ("C:\WINDOWS\system32\cmd.exe") Else MsgBox($MB_SYSTEMMODAL, "Error", " Error no IP or name is filled in") EndIf EndSwitch WEnd  
    • shokwave8
      By shokwave8
      Hello there Com,
      The following is my problem. I try to create a window with Koda-Formdesigner and the background of the Form, Button and Edit shall be blue with white letters. Everytime i run the code the colour from button and edit background sets to default. 
      i tried to set the backgroundcolour manually to blue for the button and the editbox but then the GUI just does not appear while running the script. 
      I got you some screens of Koda (howitshould.jpg) and the actual running script (howitis.jpg). I hope you guys can help me  
      Thanks for reading and replying.
      (I'm german and i might did some mistakes in language )
       

       

    • KryTonX
      By KryTonX
      Hello there,
      as I used this function in a lot of projects, I might as well share it
      It gets a color value from a background (or foreground of course) window by using a combination of WinAPI.au3 and GDIPlus.au3 (might as well be replaced with https://msdn.microsoft.com/en-us/library/windows/desktop/dd144909(v=vs.85).aspx which should work too and is maybe a bit faster, as it wouldn't need to create an extra GDIPlus Bitmap).
       
      Long story short; here is the function:
       
      ;=================================================================================================================================== ; ; Description: Gets the Color Value from a Pixel (possible in background windows [not hidden!]) ; Syntax: GetColor() ; Parameter(s): ; $iX - X Coordinate (In the Window, not whole Screen), get it by using the Autoit Window Info tool! ; $iY - Y Coordinate (In the Window, not whole Screen), get it by using the Autoit Window Info tool! ; $WinHandle - Handle obtained by WinGetHandle ; $iWidth - Width of the Window to Capture ; $iHeight - Height of the Window to Capture ; ; Return Value(s): Hex of Color Value ; ; Requirements: ; #RequireAdmin Braucht Adminrechte falls ihr auf ein Programm mit Adminrechten zugreifen wollt! ;#include <WinAPI.au3> ;#include <WindowsConstants.au3> ;#include <GDIPlus.au3> ;#include <ScreenCapture.au3> ; #include <Array.au3> ; ; Note: Does NOT work on hidden or minimized windows as Windows stops rendering them. ; If you do not want to put in the $WinHandle all the time, replace the $WinHandle Parameter ; with $WinHandle = $hwnd (if $hwnd is your Handle obtained by WinGetHandle) ; ; Tested only on Windows 10 Professional 64 Bit ; ;=================================================================================================================================== Func GetColor($iX,$iY,$WinHandle) _GDIPlus_Startup() Local $aPos = WinGetPos($WinHandle) $iWidth = $aPos[2] $iHeight = $aPos[3] Local $hDDC = _WinAPI_GetDC($WinHandle) Local $hCDC = _WinAPI_CreateCompatibleDC($hDDC) $hBMP = _WinAPI_CreateCompatibleBitmap($hDDC, $iWidth, $iHeight) _WinAPI_SelectObject($hCDC, $hBMP) DllCall("User32.dll", "int", "PrintWindow", "hwnd", $WinHandle, "hwnd", $hCDC, "int", 0) _WinAPI_BitBlt($hCDC, 0, 0, $iWidth, $iHeight, $hDDC, 0, 0, $__SCREENCAPTURECONSTANT_SRCCOPY) $BMP = _GDIPlus_BitmapCreateFromHBITMAP($hBMP) Local $aPixelColor = _GDIPlus_BitmapGetPixel($BMP, $iX, $iY) _WinAPI_ReleaseDC($WinHandle, $hDDC) _WinAPI_DeleteDC($hCDC) _WinAPI_DeleteObject($hBMP) _GDIPlus_ImageDispose($BMP) _GDIPlus_Shutdown() Return Hex($aPixelColor, 6) EndFunc ;==>GetColor
      And when we are at it, here is a little program to get the right color values for your program, just press Shift + X after configuration it, by putting in the right Program Title and you will get the coordinates and the color value of your mouse position inside of the program you wanted ^^
       
      ; #RequireAdmin Braucht Adminrechte falls ihr auf ein Programm mit Adminrechten zugreifen wollt! #include <WinAPI.au3> #include <WindowsConstants.au3> #include <GDIPlus.au3> #include <ScreenCapture.au3> #include <Array.au3> HotKeySet("{ESC}","_exit") HotKeySet("X","Go") Global $x Global $y Global $hBMP ;~ MsgBox(0,"","OK!") $Title = "PUT THE TITLE OF YOUR WINDOW HERE!" $hwnd = WinGetHandle($Title) MsgBox (0,"",$hwnd) While 1 Sleep (100) WEnd Func Go() Local $MousePos = _WinAPI_GetMousePos(True, $hWnd) $x = DllStructGetData($MousePos, "X") $y = DllStructGetData($MousePos, "Y") ;~ $x = if you want to set them manual ;~ $y = use this and comment out both DLLStructGetData $Color = GetColor($x, $y, $hwnd) MsgBox(0,"","x: " &$x& " y: " &$y& " Color: " &$Color) EndFunc Func _Exit() Exit EndFunc Func GetColor($iX,$iY,$WinHandle) _GDIPlus_Startup() Local $aPos = WinGetPos($WinHandle) $iWidth = $aPos[2] $iHeight = $aPos[3] Local $hDDC = _WinAPI_GetDC($WinHandle) Local $hCDC = _WinAPI_CreateCompatibleDC($hDDC) $hBMP = _WinAPI_CreateCompatibleBitmap($hDDC, $iWidth, $iHeight) _WinAPI_SelectObject($hCDC, $hBMP) DllCall("User32.dll", "int", "PrintWindow", "hwnd", $WinHandle, "hwnd", $hCDC, "int", 0) _WinAPI_BitBlt($hCDC, 0, 0, $iWidth, $iHeight, $hDDC, 0, 0, $__SCREENCAPTURECONSTANT_SRCCOPY) $BMP = _GDIPlus_BitmapCreateFromHBITMAP($hBMP) Local $aPixelColor = _GDIPlus_BitmapGetPixel($BMP, $iX, $iY) _WinAPI_ReleaseDC($WinHandle, $hDDC) _WinAPI_DeleteDC($hCDC) _WinAPI_DeleteObject($hBMP) _GDIPlus_ImageDispose($BMP) _GDIPlus_Shutdown() Return Hex($aPixelColor, 6) EndFunc ;==>GetColor


      I hope  I was able to help somebody on the long run
      If you have any improvements or found any mistake, please let me know and I will try to improve the function as soon as possible.
      Also please excuse my "not so clean" coding, I am still learning

      Have fun,
      KryTonX
       
      EDIT: Thanks at JohnOne for his improvements on the Script, I have added WinGetPos...I wonder why I never got that Idea
    • aNewLyfe
      By aNewLyfe
      I'm trying to make a desktop wallpaper application with video support.
      But stuck at z-order.
      Any suggestions? How to put autoit window before desktop listview?
      I'm currently attaching window to the WorkerW. also tried the $HWND_BOTTOM const of _WinAPI_SetWindowPos but when i apply this, win goes invisible.
      no luck yet any help will be appreciated