Sign in to follow this  
Followers 0
Mackus101

Apply Hex Color to Main GUI from Pop Up Menu

3 posts in this topic

Hello Everybody,

This is my first official post even though I have been scouring the forums for a couple weeks now. I am a new program Hobbyist...just began learning Autoit/any language no earlier than the beginning of June. I am currently trying to figure out how to use the find Color under mouse and apply it from a pop up screen to a main GUI. I did find the main part of this code on one of these pages but I can't find where I originally started from...So thank you to whomever that was!

Issues I am facing:

  • When it does work it only works once
  • Can't seem to get the value of the Hex properly (tried different variations and my brain hurts now)
  • The main GUI doesn't refresh properly
#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
Global $pos = MouseGetPos()
Global $pixel_hex = Hex(PixelGetColor($pos[0],$pos[1]), 6)
Global $pixel_last
Global $Popcolor, $ColorUpdate, $lblF8, $lblF9, $lblF10, $lblF11, $HexTopFirst, $HexTopSecond, $HexTopThird, $HexTopFourth, _
$HexBotFirst, $HexBotSecond, $HexBotThird, $HexBotFourth, $lblName1, $lblName2, $lblName3, $lblName4, $FirstColor, _
$SecondColor, $ThirdColor, $FourthColor
HotKeySet("{F8}","clip8")
HotKeySet("{f9}","clip9")
HotKeySet("{F10}","clip10")
HotKeySet("{f11}","clip11")
HotKeySet("{ESC}","endme")
;-----------------MAIN GUI---------------
$MainColor = GUICreate ("Main Color Find", 340,140)
$ColorUpdate = GUICtrlCreateButton("Find Colors",110,105,120,25)
;........NAME Labels............
$lblMainName1= GUICtrlCreateLabel("One", 30, 68, 50, 13)
$lblMainName2= GUICtrlCreateLabel("Two", 108, 68, 45, 13)
$lblMainName3= GUICtrlCreateLabel("Three", 195, 68, 100, 13)
$lblMainName4= GUICtrlCreateLabel("Four", 280, 68, 30, 13)
;........Graphics........
$FirstMain = GUICtrlCreateGraphic(35, 48, 18, 18, BitOR($GUI_SS_DEFAULT_GRAPHIC,$SS_BLACKFRAME,$SS_SUNKEN))
$SecondMain = GUICtrlCreateGraphic(112, 48, 18, 18, BitOR($GUI_SS_DEFAULT_GRAPHIC,$SS_BLACKFRAME,$SS_SUNKEN))
$ThirdMain = GUICtrlCreateGraphic(200, 48, 18, 18, BitOR($GUI_SS_DEFAULT_GRAPHIC,$SS_BLACKFRAME,$SS_SUNKEN))
$FourthMain = GUICtrlCreateGraphic(282, 48, 18, 18, BitOR($GUI_SS_DEFAULT_GRAPHIC,$SS_BLACKFRAME,$SS_SUNKEN))
GUISetState(@SW_SHOW)
;----------Main Loop---------------------  
While 1
   $nMsg = GUIGetMsg(1)
   Switch $nMsg[1]
   Case $MainColor
   Switch $nMsg[0]
     Case $GUI_EVENT_CLOSE
      Exit
     
     Case $ColorUpdate
      PopColor()
   
   EndSwitch
  
      Case $PopColor
      Sleep(100)
      Call("grab")
      Switch $nMsg[0]
      Case $GUI_EVENT_CLOSE
      GUIDelete($PopColor)
      Sleep(10)
      GUICtrlSetState($ColorUpdate, $GUI_Enable)       
      Case $ColorUpdate
      GUICtrlSetBkColor($FirstMain,$FirstColor)
      GUICtrlSetBKColor($SecondMain,$SecondColor)
      GUICtrlSetBKColor($ThirdMain,$ThirdColor)
      GUISetBkColor($FourthMain,$FourthColor)
      EndSwitch
   EndSwitch
WEnd
Func PopColor()
   $PopColor = GUICreate("Color Find Pop", 340,140)
   $ColorUpdate = GUICtrlCreateButton("Update Main",110,105,120,25)
   ;........F9 - F12 Labels.......
   $lblF8= GUICtrlCreateLabel("F8", 35, 7, 30, 20)
   $lblF9= GUICtrlCreateLabel("F9", 112, 7, 45, 20)
   $lblF10 = GUICtrlCreateLabel("F10", 200, 7, 50, 20)
   $lblF11 = GUICtrlCreateLabel("F11", 282, 7, 42, 20)
   ;........Top HEX Labels.......
   $HexTopFirst= GUICtrlCreateLabel("", 22, 32, 60, 13)
   $HexTopSecond= GUICtrlCreateLabel("", 102, 32, 60, 13)
   $HexTopThird = GUICtrlCreateLabel("", 188, 32, 60, 13)
   $HexTopFourth = GUICtrlCreateLabel("", 271, 32, 60, 13)
   ;........BOTTOM HEX Labels.......
   $HexBotFirst= GUICtrlCreateLabel("", 22, 85, 60, 13)
   $HexBoTSecond= GUICtrlCreateLabel("", 102, 85, 60, 13)
   $HexBoTThird = GUICtrlCreateLabel("", 188, 85, 60, 13)
   $HexBoTFourth = GUICtrlCreateLabel("", 271, 85, 60, 13)
   ;........NAME Labels............
   $lblName1= GUICtrlCreateLabel("One", 30, 68, 50, 13)
   $lblName2= GUICtrlCreateLabel("Two", 108, 68, 45, 13)
   $lblName3= GUICtrlCreateLabel("Three", 195, 68, 100, 13)
   $lblName4= GUICtrlCreateLabel("Four", 280, 68, 30, 13)
   ;........Graphics........
   $FirstColor = GUICtrlCreateGraphic(35, 48, 18, 18, BitOR($GUI_SS_DEFAULT_GRAPHIC,$SS_BLACKFRAME,$SS_SUNKEN))
   $SecondColor = GUICtrlCreateGraphic(112, 48, 18, 18, BitOR($GUI_SS_DEFAULT_GRAPHIC,$SS_BLACKFRAME,$SS_SUNKEN))
   $ThirdColor = GUICtrlCreateGraphic(200, 48, 18, 18, BitOR($GUI_SS_DEFAULT_GRAPHIC,$SS_BLACKFRAME,$SS_SUNKEN))
   $FourthColor = GUICtrlCreateGraphic(282, 48, 18, 18, BitOR($GUI_SS_DEFAULT_GRAPHIC,$SS_BLACKFRAME,$SS_SUNKEN))
   GUISetState(@SW_Show)
EndFunc
func grab()
    $pos = MouseGetPos()
    $pixel_hex = Hex(PixelGetColor($pos[0],$pos[1]), 6)
    
        If $pixel_last <> $pixel_hex Then
        GUICtrlSetData($HexTopFirst, $pixel_hex)
  GUICtrlSetData($HexTopSecond, $pixel_hex)
  GUICtrlSetData($HexTopThird, $pixel_hex)
  GUICtrlSetData($HexTopFourth, $pixel_hex)
    EndIf
    $pixel_last = $pixel_hex
EndFunc

Func clip8()
    Local $color = "0x" & $pixel_last
   GUICtrlSetBkColor($FirstColor, $color)
   GUICtrlSetColor($HexBotFirst,"0x"&$Pixel_Last)
   GUICtrlSetData($HexBotFirst, $Pixel_Last)
   EndFunc
  
   Func clip9()
    Local $color = "0x" & $pixel_last
   GUICtrlSetBkColor($SecondColor, $color)
   GUICtrlSetColor($HexBotSecond,"0x"&$Pixel_Last)
   GUICtrlSetData($HexBotSecond, $Pixel_Last)
   EndFunc
  
   Func clip10()
    Local $color = "0x" & $pixel_last
   GUICtrlSetBkColor($ThirdColor, $color)
   GUICtrlSetColor($HexBotThird,"0x"&$Pixel_Last)
   GUICtrlSetData($HexBotThird, $Pixel_Last)
   EndFunc
  
   Func clip11()
    Local $color = "0x" & $pixel_last
   GUICtrlSetBkColor($FourthColor, $color)
   GUICtrlSetColor($HexBotFourth,"0x"&$Pixel_Last)
   GUICtrlSetData($HexBotFourth, $Pixel_Last)
EndFunc

Func endme()
   Exit
EndFunc

Questions:

  • Can my purpose be served better by applying read and write ini file?

    • Would it be possible to have the main GUI already have a saved HEX color if using ini that can be overwritting from pop up menu?
  • Would OnEvent be better?
Any help would be appreciated...been stressing out over this coding for the last few days!

Share this post


Link to post
Share on other sites



You're reusing the variable name for the buttons on both GUIs, so when you call PopColor, the variable that holds the value from the first GUI gets overwritten by the handle to the button on the second GUI. Once you do that, the button on GUI 1 will never work again.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

Thanks for the reply BrewMan!

oh that was a mistake from seperating this code from a much bigger project...accidental copy paste and no double checking the variables. Lets say we Change the FIrst button to just $Find and then we change the second button to $update. Now what would be the best way to get those colors from the 2nd GUI onto the 1st GUI after pressing $update?

Is there any way to read the Hex value of a font? A way to read the Hex value of a Graphic Background? Since the GUICtrlRead, GetData, Etc. does not return a Hex value and as soon as the mouse is moved the pixel_last is now different. So how do I capture that state in which when the button is pressed records the value but then communicates that value when and only when $update is pressed.

My previous attempt I tried to write an INI file for every F8-11 it would iniwrite "0x"&Pixel_Last into the INI and then referenced a variable to be read in the script and then refreshed on button press such as $update but it didn't work the way I thought it would...seemed as though it lagged in recording/missed a button/didn't copy correctly.

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

    • FrankSchneidewind
      [GUI] Drag&Drop files -> Get filename
      By FrankSchneidewind
      Hi all,
      I got a quick question regarding Drag&Drop with GUIs. I made a little script that does something with files and I need a way to get the name/path of the file when I drag&drop it into the GUI. Is there a quick way to do this?

      Tyvm in advance!
      Neo
    • Wingens
      Metro style combo
      By Wingens
      Hi all,
      I created a little script we use at work for inputing date and time stamps into our ticket system.
      Now I thought it would look nice in a Metro style GUI, I found an UDF on the forum what does almost everything I want.
      I have but one thing I can't seem to find and don't have the skills to create.
      The gui uses one pulldown menu (GUICtrlCreateCombo) it stays in the older looking style.
      I attached the script and files I have, also in the zip you find an example of what I am looking for.
       
      Hope you guys can help me 
      Hotkey.zip
    • jaberwacky
      GuiBuilderNxt - Reboot [08/18/2016]
      By jaberwacky
      This is an update to GuiBuilder (CyberSlug, Roy, TheSaint, and many others) to run on the latest AutoIt Beta release.
       
      For a chronological history of GuiBuilder and other GUI designers see: >AutoIt GUI Creators (Designers).
      The seed of this effort is >here.
      Note: This is early stage software.  Please help by reporting issues.
      -----------------------------------------------------
      Now for the latest exciting installment!  Tabs are now available!  One tab can be added to the GUI.  Move it, resize it, and right click to add a new tab item!  More context menu items on the way.  Also upcoming is the ability to be able to add controls to each tab item.
      ---------------------------------------------------------
      GUIBuilderNxt - Reboot.zip - Exe included.
      dl: 4286
      Changelog:
      New Features and fixes:
      1) Show or hide control while moving or resizing control. *Currently bugged out*
      2) Option to show controls which have had their state set to hidden.
      3) Properties window for each control as they are selected.  This makes fine tuning a control easier.
      4) A button which will resize a control's width to fit the text.  Uses Melba23's _StringSize library.
      5) Remembers settings from the last session.
      6) GuiOnEvent mode.  CyberSlug made mention of wanting to do this in the early days of GuiBuilder.
      7) Maps rather than multidimensional arrays.
      8) Consistent control naming, (i.e., instead of Group1, Button2, Button3, Radio4 it would now be Group1, Button1, Button2, Radio1).
      9) Restructured the menubar layout per GuiBuilder Resurrected.
      10) Hotkeys switched to accelerators.
      11) Option to wipe the gui clear to the Edit menu.
      12) Select and move multiple controls at once by holding down Ctrl or using a selection rectangle.
      13) Copy, Paste and Delete multiple controls at once.
      14) Solid grid background that now resizes to fit the GUI.
       
      Roadmap:
      1) Get the Tab control to work correctly. *Still in progress*
      2) Finish adding properties settings to the control properties window.
      3) Make the code generation produce code with a better layout.
      4) Common GUI templates.  Ability to make your own templates too.
      5) Select multiple controls and use arrow keys (or other method?) to snap the selected controls to align to the chosen edge.
      6) Visual hints to tell you when you're within so many pixels from the edge of the window or control.  Mimics the gui designer of Visual Basic.
      7) Double click a control to edit the text.
      8) Visual hints to indicate selected controls, etc.
      9) Ability to create and store custom controls.
       
      Known issues:
      1)Many!
    • FMS
      Winmove GUI moves buttons
      By FMS
      Hello,
      Below is a code whish i made for this problem i've. (code 1)
      The problem is that iff i try Winmove to to show the hidden button it's not working as i tought.
      What i try to do is just simple expand the GUI to make the hidden button visible. (code 2)
      I've already looked into GUICoordMode but don't think that's the problem.(or I don't understand it properly)
      Also tried to look into the forum but din't find anything around this subject but could't find anything around this subject.
      Does somebody knows what I'm doing wrong?
       
      Code 1 (winmove prblem) :
      #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> $Form1 = GUICreate("Form1", 134, 103, 192, 124) $Button1 = GUICtrlCreateButton("1", 8, 8, 75, 25) $Button2 = GUICtrlCreateButton("2", 8, 40, 75, 25) $Button3 = GUICtrlCreateButton("3", 8, 72, 75, 25) $expand_button = GUICtrlCreateButton("EXP", 96, 40, 27, 25) $hidden_button = GUICtrlCreateButton("Hidden", 160, 40, 75, 25) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $expand_button WinMove($Form1, "From1", 192, 124, 300, 103) EndSwitch WEnd  
      Code 2 What I'm trying to expand to :
      #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> $Form1 = GUICreate("Form1", 265, 114, 192, 124) $Button1 = GUICtrlCreateButton("1", 8, 8, 75, 25) $Button2 = GUICtrlCreateButton("2", 8, 40, 75, 25) $Button3 = GUICtrlCreateButton("3", 8, 72, 75, 25) $expand_button = GUICtrlCreateButton("EXP", 96, 40, 27, 25) $hidden_button = GUICtrlCreateButton("Hidden", 160, 40, 75, 25) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd  
    • rm4453
      Moving Combo To Next Option Automatically In AutoIt Gui
      By rm4453
      I need to find a way to after x amount of seconds set the Autoit gui's ComboBox to next option available, and if it reaches the end of the list start back at beginning. This way I can cycle through checking if users are connected to a network. The combo is populated via a recursive file search that contains folders with each connected user's username. The ComboBox will contain something like " username\config " for every connected user. So I need to make so it cycles through constantly every X seconds I have the gui functioning, and all that I just can't get this one part to work.

      TL:DR - How do I make so an AutoIt GUI ComboBox will cycle through all of its options every X seconds, and when it reaches bottom of options cycle back to top and continue the process again.

      Thanks! I can't post any code due to NDA sorry...