Sign in to follow this  
Followers 0

Apply Hex Color to Main GUI from Pop Up Menu


3 posts in this topic

Posted

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



Posted

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.

Share this post


Link to post
Share on other sites

Posted

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