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

    • PINTO1927
      png with background transparent into gui without border
      By PINTO1927
      Hi guys, I would like to make a gui borderless viewing a png image with transparent background.
       
      pretty much has to be visible only the png image with no background..you have any simple example?
      Thank's
      GUICtrlCreatePic  
      still it provides the image with the background...
    • toasterking
      Parsing binary data frames from an asynchronous source
      By toasterking
      I was just working on a project that involved decoding a stream of binary data from a serial port in AutoIt.  It took me a few hours to figure out how to process the data efficiently in AutoIt and I did not find any helpful examples on how to do so, so I thought I would share my core example and maybe save someone else some time.  There may be a more efficient way to do this, but this works well for me.
       
      #cs Author: ToasterKing This is an example of a way to parse streaming binary data that follows a strict format with a header and footer. In this example, each frame is 5 bytes with a 2-byte header of 0xD5AA and a 1-byte footer of 0xAD. The _BinaryParse() function accumulates incoming data in a buffer. Once a footer is found, it searches backward for the header, and if it is in the right position, it extracts the remaining 2 bytes in the middle, then moves on to looking for the next frame. #ce ; The data source might be something asynchronous like serial or TCP, but since this is just an example, I'm just putting the data in a variable. Local $fSomeData $fSomeData = Binary("0xD5AA24B1") ; Binary data constituting almost a complete frame. _BinaryParse($fSomeData) ; Call the function with the received data. It isn't a complete frame, so it is just stored in the buffer until more data is received. $fSomeData = Binary("0xAD62D5AA92E7AD") ; Remainder of the previous frame, one garbage byte (0x62) which should be skipped, and a complete additional frame. _BinaryParse($fSomeData) ; The function should be able to parse both frames now. Func _BinaryParse($fNewData) Local Static $fBinaryReceived = Binary("") ; Buffer for received data ConsoleWrite("Hey, the function is called!" & @CRLF) ; Add new data to the buffer. ; This ridiculous monstrosity is the only way I could find to append binary data to binary data in AutoIt. It must be converted to strings first. ; Both, one, or no substrings will begin with "0x" depending on whether they contained binary data. To be converted back to binary properly, only one instance ; of "0x" must exist at the beginning of the string. $fBinaryReceived = Binary("0x" & StringReplace(String($fBinaryReceived) & String($fNewData),"0x","")) ConsoleWrite("Data in the buffer: " & String($fBinaryReceived) & @CRLF) Local $iLength = BinaryLen($fBinaryReceived) ; Count the bytes in the data If $iLength > 0 Then Local $fBinaryReceivedTemp = $fBinaryReceived ; Create temporary copy to work on Local $fByte1,$fByte2 For $i = 1 To $iLength If BinaryMid($fBinaryReceivedTemp,$i,1) = 0xAD Then ; If the 1-byte footer found ConsoleWrite("Footer found at end of " & $i & " of " & $iLength & " bytes!" & @CRLF) If BinaryMid($fBinaryReceivedTemp,$i - 4,1) = 0xD5 And BinaryMid($fBinaryReceivedTemp,$i - 3,1) = 0xAA Then ; and the 2-byte header is found 4 bytes before that ConsoleWrite("Header found before the footer!" & @CRLF) $fByte1 = BinaryMid($fBinaryReceivedTemp,$i - 2,1) ; Get 1st byte in the body (between header and footer) $fByte2 = BinaryMid($fBinaryReceivedTemp,$i - 1,1) ; Get 2nd byte in the body (between header and footer) ConsoleWrite("Here is the critical data: " & String($fByte1) & " " & String($fByte2) & @CRLF) ; Just display the 2 bytes for demonstration purposes. Normally, you'd do something more useful with it here. EndIf $fBinaryReceived = BinaryMid($fBinaryReceivedTemp,$i + 1) ; Truncate the original data to remove all of the bytes just processed, then continue processing $fBinaryReceivedTemp EndIf Next EndIf EndFunc  
    • OldGuyWalking
      Identifying Button in Toolbar When There is no ControID
      By OldGuyWalking
      I want to click on a button that is inside a custom ToolBar on a nonAutoIT created form.  I've been using MouseClick but that fails if the toolbar is detached or if the form is resized.
      There is no ID associated with the toolbar but there is a handle.  I'm thinking that to get the handle I need a ControlID but that only gets me to the toolbar and I'd then need to have a way to identify the position of a button in order to click on it.  
      I'd found a discussion about identifying the position of a noname button by, I believe, it's Tip text back in December but I can't find it now.  Memory is a bit fuzzy on how I even got to the topic because at the time I was searching for something else.   I'll continue to search but if anyone has seen the topic, or knows of another solution could you please point me in that direction. 
      Thank you.
    • litlmike
      Excel Make Row Some Color
      By litlmike
      Hey there, I am trying to figure out how to fill an Excel row with a color, if some condition.  For example:
       
      $sColor = #FFF000 For $iCC = 1 To Ubound($aArray)-1 $sRange = "A:" & $iCC If _Excel_RangeReady($oWorkbook, $sRange) = "Some String" Then _Excel_FillInRowWithColor($iRowToFillIn, $sColor) Next  
      Anyone know how to do that?  Thanks!
    • lbsl
      Popup context menu not broadcasting control with multiple widows
      By lbsl
      Greetings fellows,
       
      I have an issue that is bothering me for quite some time now (Since Autoit3 V3.3.8.0 and still not solved in 3.3.14.0) and i have not found any clue how to solve this particular problem regarding the control of popup-menus for specific controls. I have been searching using many keywords in the hope to find a similar posted issue either on the internet or here on this forum but did not yet stumbled upon it so i have no other option than to post the question (Sorry if there would exist an earlier topic).
      Below is an example that demonstrates the issue very clearly if you follow the steps to reproduce:
      #include <GuiMenu.au3> #include <GUIConstantsEx.au3> #include <ListViewConstants.au3> #include <WindowsConstants.au3> $TestWindow1 = GUICreate("TestWindow1", 353, 277, 100, 80) $ListView1 = GUICtrlCreateListView("", 8, 8, 338, 262) $ListView1_0 = GUICtrlCreateListViewItem("TestItem1", $ListView1) $ListView1_1 = GUICtrlCreateListViewItem("TestItem2", $ListView1) $ListView1_2 = GUICtrlCreateListViewItem("TestItem3", $ListView1) GUISetState(@SW_SHOW) $TestWindow2 = GUICreate("TestWindow2", 353, 277, 100 + 400, 80) $ListView2 = GUICtrlCreateListView("", 8, 8, 338, 262) $ListView2_0 = GUICtrlCreateListViewItem("TestItem1", $ListView2) $ListView2_1 = GUICtrlCreateListViewItem("TestItem2", $ListView2) $ListView2_2 = GUICtrlCreateListViewItem("TestItem3", $ListView2) GUISetState(@SW_SHOW) GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") Local $MenuContext, $MenuContext2 Local $ahLVMenu[3] Local $ahLVMenu2[3] For $i = 0 To 2 $ahLVMenu[$i] = GUICtrlCreateDummy() $ahLVMenu2[$i] = GUICtrlCreateDummy() Next While 1 Local $nMsg = GUIGetMsg(1) Switch $nMsg[0] Case $GUI_EVENT_CLOSE If $nMsg[1] == $TestWindow2 Then GUISetState(@SW_HIDE, $nMsg[1]) Else Exit EndIf Case $ahLVMenu[0] ConsoleWrite("Dialog 1, Item 1" & @CRLF) Case $ahLVMenu[1] ConsoleWrite("Dialog 1, Item 2" & @CRLF) Case $ahLVMenu[2] ConsoleWrite("Dialog 1, Item 3" & @CRLF) Case $ahLVMenu2[0] ConsoleWrite("Dialog 2, Item 1" & @CRLF) Case $ahLVMenu2[1] ConsoleWrite("Dialog 2, Item 2" & @CRLF) Case $ahLVMenu2[2] ConsoleWrite("Dialog 2, Item 3" & @CRLF) EndSwitch WEnd Func WM_NOTIFY($hWnd, $Msg, $wParam, $lParam) #forceref $hWnd, $Msg, $wParam Local $hWndFrom, $iIDFrom, $event, $tNMHDR, $hWndListView, $hWndListView2, $tInfo $hWndListView = $ListView1 $hWndListView2 = $ListView2 Local $tMsgFilter, $hMenu If Not IsHWnd($ListView1) Then $hWndListView = GUICtrlGetHandle($ListView1) If Not IsHWnd($ListView2) Then $hWndListView2 = GUICtrlGetHandle($ListView2) $tNMHDR = DllStructCreate($tagNMHDR, $lParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iIDFrom = DllStructGetData($tNMHDR, "IDFrom") $event = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hWndListView2 Switch $event Case $NM_RCLICK ; Sent by a list-view control when the user clicks an item with the right mouse button _LV_PopUpMenu2() ; Show popup context menu in Pharmacist article list EndSwitch Case $hWndListView Switch $event Case $NM_RCLICK ; Sent by a list-view control when the user clicks an item with the right mouse button _LV_PopUpMenu() ; Show popup context menu in Pharmacist article list EndSwitch EndSwitch $hWndFrom = 0 $iIDFrom = 0 $tNMHDR = 0 $hWndListView = 0 $hWndListView2 = 0 $tInfo = 0 $tMsgFilter = 0 $hMenu = 0 Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY Func _LV_PopUpMenu() $MenuContext = _GUICtrlMenu_CreatePopup(40) _GUICtrlMenu_InsertMenuItem($MenuContext, 0, "Dialog 1, item 1", $ahLVMenu[0]) _GUICtrlMenu_InsertMenuItem($MenuContext, 1, "Dialog 1, item 2", $ahLVMenu[1]) _GUICtrlMenu_InsertMenuItem($MenuContext, 2, "Dialog 1, item 3", $ahLVMenu[2]) _GUICtrlMenu_TrackPopupMenu($MenuContext, $TestWindow1) _GUICtrlMenu_DestroyMenu($MenuContext) Return $GUI_RUNDEFMSG EndFunc ;==>_LV_PopUpMenu Func _LV_PopUpMenu2() $MenuContext2 = _GUICtrlMenu_CreatePopup(40) _GUICtrlMenu_InsertMenuItem($MenuContext2, 0, "Dialog 2, item 1", $ahLVMenu2[0]) _GUICtrlMenu_InsertMenuItem($MenuContext2, 1, "Dialog 2, item 2", $ahLVMenu2[1]) _GUICtrlMenu_InsertMenuItem($MenuContext2, 2, "Dialog 2, item 3", $ahLVMenu2[2]) _GUICtrlMenu_TrackPopupMenu($MenuContext2, $TestWindow2) _GUICtrlMenu_DestroyMenu($MenuContext2) Return $GUI_RUNDEFMSG EndFunc ;==>_LV_PopUpMenu2
      I have two window dialogs and two listview controls defined.
      Each listview control has its own popup menu and menu items.
      The code above works fine as long as both window dialogs are visible.
      You can right-click on each listview control and you get the designated menu popped up and if you select an item, the message for the specific item is being written into the console frame for it.
      However, if you close window 2, and attempt to trigger the options in the popup menu for window 1, you will notice that the notification messages are no longer being triggered at all.
      The popup menu becomes visible if you right-click the area and disappears if you select an option, but the control item no longer sends a notification which means that the attached events for the trapping are no longer being executed.
      Now if you switch the code snippets of the window frames being generated, you will notice you can achieve the same issue the other way round, which means that context menu item notifications are being received and trigger an event routine as long as window 1 would then in that case remain open.
      So it seems that whichever window is generated the last, that window somehow seems to get attached to the notification messages that are being send by the dummy controls for the context menu items.
      Do i misinterpret something here, is there a fix for this issue or did i encountered some kind of bug inside Autoit3?