maba Posted February 4, 2012 Share Posted February 4, 2012 Hi, is there a simple way to change background or border color, or at least add a sign near the input, when user edit a input, date or other control? Thanks Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 4, 2012 Moderators Share Posted February 4, 2012 maba, Be careful about colouring active AutoIt controls - it can lead to unexpected behaviour because of the way this was implemented in the core code many years ago. As to checking to see if the user has changed anything in a control, you can either monitor the content of the control in your idle loop (simple) or look for a suitable Windows message (more elegant). This script shows how to do both: expandcollapse popup#include <GUIConstants.au3> #include <WindowsConstants.au3> #include <EditConstants.au3> #include <WinAPI.au3> ; Create a GUI $hGUI = GUICreate("Test", 500, 500) $hLabel_1 = GUICtrlCreateLabel("Input 1", 10, 10, 200, 20) $hInput_1 = GUICtrlCreateInput("", 10, 30, 200, 20) $hLabel_2 = GUICtrlCreateLabel("Input 2", 10, 110, 200, 20) $hInput_2 = GUICtrlCreateInput("", 10, 130, 200, 20) GUISetState() ; Look for the WM_COMMAND messages GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND") $sInput_1_Content = "" While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch ; Get the content of the input and compare the the last version $sInput_1_Text = GUICtrlRead($hInput_1) If $sInput_1_Text <> $sInput_1_Content Then ; It has changed so save it $sInput_1_Content = $sInput_1_Text ; Colour the label to red GUICtrlSetBkColor($hLabel_1, 0xFFCCCC) ; And after 1 sec set it back to white AdlibRegister("_Reset", 1000) EndIf WEnd Func _WM_COMMAND($hWHnd, $iMsg, $wParam, $lParam) ; If it was an update message from the correct input If _WinAPI_HiWord($wParam) = $EN_CHANGE And _WinAPI_LoWord($wParam) = $hInput_2 Then ; Chenge label to green GUICtrlSetBkColor($hLabel_2, 0xCCFFCC) ; And after 1 sec set it back to white AdlibRegister("_Reset", 1000) EndIf EndFunc ;==>_WM_COMMAND Func _Reset() ; Stop the function from being called again AdlibUnRegister("_Reset") ; Set the labels to white GUICtrlSetBkColor($hLabel_1, 0xFEFEFE) GUICtrlSetBkColor($hLabel_2, 0xFEFEFE) EndFunc Please ask if you have any questions. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
maba Posted February 4, 2012 Author Share Posted February 4, 2012 (edited) [dangerous mode on]Ooops.. [dangerous mode off]Thanks for your answer!This is an example of my target, I don't like so much because there are the green border even when user don't made changes.Your solution can solve the problem and I prefer change label background color (when possible), but.. when the focus change colors are reset to white, is it possible to "fix" the color? If user does a change color is set to red, if user reset to default.. windows color are applied. Edited February 4, 2012 by maba Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 4, 2012 Moderators Share Posted February 4, 2012 maba, Just check the content like this: expandcollapse popup#include <GUIConstants.au3> #include <WindowsConstants.au3> #include <EditConstants.au3> #include <WinAPI.au3> ; Create a GUI $hGUI = GUICreate("Test", 500, 500) $hLabel_1 = GUICtrlCreateLabel("Input 1", 10, 10, 200, 20) $hInput_1 = GUICtrlCreateInput("", 10, 30, 200, 20) $hLabel_2 = GUICtrlCreateLabel("Input 2", 10, 110, 200, 20) $hInput_2 = GUICtrlCreateInput("", 10, 130, 200, 20) GUISetState() ; Look for the WM_COMMAND messages GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND") $sInput_1_Content = "" While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch ; Get the content of the input and compare the the last version $sInput_1_Text = GUICtrlRead($hInput_1) If $sInput_1_Text <> $sInput_1_Content Then ; It has changed so save it $sInput_1_Content = $sInput_1_Text If $sInput_1_Content <> "" Then ; Colour the label to red GUICtrlSetBkColor($hLabel_1, 0xFFCCCC) Else ; Set it back to white GUICtrlSetBkColor($hLabel_1, 0xFEFEFE) EndIf EndIf WEnd Func _WM_COMMAND($hWHnd, $iMsg, $wParam, $lParam) ; If it was an update message from the correct input If _WinAPI_HiWord($wParam) = $EN_CHANGE And _WinAPI_LoWord($wParam) = $hInput_2 Then If GUICtrlRead($hInput_2) <> "" Then ; Chenge label to green GUICtrlSetBkColor($hLabel_2, 0xCCFFCC) Else ; Set it back to white GUICtrlSetBkColor($hLabel_2, 0xFEFEFE) EndIf EndIf EndFunc ;==>_WM_COMMAND All clear? M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
maba Posted February 4, 2012 Author Share Posted February 4, 2012 Ok, thanks. But if I want to check about 20 fields in a form and theirs default value (like and edit form for a sqlite record) I've to save this value in a second variable in the form creation? I cannot use GUICtrlRead to retrieve the "default" value. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 4, 2012 Moderators Share Posted February 4, 2012 maba, So we compare the content to the pre-set default value: expandcollapse popup#include <GUIConstants.au3> #include <WindowsConstants.au3> #include <EditConstants.au3> #include <WinAPI.au3> ; Set default values Global $sDef_1 = "Default value 1" Global $sDef_2 = "Default value 2" ; Create a GUI $hGUI = GUICreate("Test", 500, 500) $hLabel_1 = GUICtrlCreateLabel("Input 1", 10, 10, 200, 20) $hInput_1 = GUICtrlCreateInput($sDef_1, 10, 30, 200, 20) $hLabel_2 = GUICtrlCreateLabel("Input 2", 10, 110, 200, 20) $hInput_2 = GUICtrlCreateInput($sDef_2, 10, 130, 200, 20) GUISetState() ; Look for the WM_COMMAND messages GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND") ; Set current value $sInput_1_Content = $sDef_1 While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch ; Get the content of the input and compare the the last version $sInput_1_Text = GUICtrlRead($hInput_1) If $sInput_1_Text <> $sInput_1_Content Then ; It has changed so save it $sInput_1_Content = $sInput_1_Text If $sInput_1_Content <> $sDef_1 Then ; Colour the label to red GUICtrlSetBkColor($hLabel_1, 0xFFCCCC) Else ; Set it back to white GUICtrlSetBkColor($hLabel_1, 0xFEFEFE) EndIf EndIf WEnd Func _WM_COMMAND($hWHnd, $iMsg, $wParam, $lParam) ; If it was an update message from the correct input If _WinAPI_HiWord($wParam) = $EN_CHANGE And _WinAPI_LoWord($wParam) = $hInput_2 Then If GUICtrlRead($hInput_2) <> $sDef_2 Then ; Chenge label to green GUICtrlSetBkColor($hLabel_2, 0xCCFFCC) Else ; Set it back to white GUICtrlSetBkColor($hLabel_2, 0xFEFEFE) EndIf EndIf EndFunc ;==>_WM_COMMAND M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
maba Posted February 4, 2012 Author Share Posted February 4, 2012 Yep, perfect! Thanks I change only the default color: Func _WM_COMMAND($hWHnd, $iMsg, $wParam, $lParam) ; If it was an update message from the correct input If _WinAPI_HiWord($wParam) = $EN_CHANGE And _WinAPI_LoWord($wParam) = $hInput_2 Then If GUICtrlRead($hInput_2) <> $sDef_2 Then ; Chenge label to green GUICtrlSetBkColor($hLabel_2, 0xCCFFCC) Else ; Set it back to default GUICtrlSetBkColor($hLabel_2, _WinAPI_GetSysColor($COLOR_MENU)) EndIf EndIf EndFunc ;==>_WM_COMMAND In any case I must declare vars/consts for any fields that I want control. In your opinion is this a good choice for a form with 20/30 fields? Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 4, 2012 Moderators Share Posted February 4, 2012 maba,You would probably want to use a Switch structure to check whether the control was one you wished to check. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
maba Posted February 4, 2012 Author Share Posted February 4, 2012 Ok, I've readed about $WM_COMMAND here http://www.autoitscript.com/wiki/GUIRegisterMsgThanks! Link to comment Share on other sites More sharing options...
maba Posted February 22, 2012 Author Share Posted February 22, 2012 (edited) Is it possible manange icons also?Show an icon only if input is modified..Bad question above..How to hide icon when input is set back to default?expandcollapse popup#include <GUIConstants.au3> #include <WindowsConstants.au3> #include <EditConstants.au3> #include <WinAPI.au3> ; Set default values Global $sDef_1 = "Default value 1" Global $sDef_2 = "Default value 2" ; Create a GUI $hGUI = GUICreate("Test", 500, 500) $hLabel_1 = GUICtrlCreateLabel("Input 1", 10, 10, 200, 20) $hInput_1 = GUICtrlCreateInput($sDef_1, 10, 30, 200, 20) $hIcon_1 = GUICtrlCreateIcon(@AutoItExe, -1, 220, 30, 16, 16) $hLabel_2 = GUICtrlCreateLabel("Input 2", 10, 110, 200, 20) $hInput_2 = GUICtrlCreateInput($sDef_2, 10, 130, 200, 20) GUISetState() ; Look for the WM_COMMAND messages GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND") ; Set current value $sInput_1_Content = $sDef_1 While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch ; Get the content of the input and compare the the last version $sInput_1_Text = GUICtrlRead($hInput_1) If $sInput_1_Text <> $sInput_1_Content Then ; It has changed so save it $sInput_1_Content = $sInput_1_Text If $sInput_1_Content <> $sDef_1 Then ; Colour the label to red GUICtrlSetBkColor($hLabel_1, 0xFFCCCC) Else ; Set it back to white GUICtrlSetBkColor($hLabel_1, 0xFEFEFE) EndIf EndIf WEnd Func _WM_COMMAND($hWHnd, $iMsg, $wParam, $lParam) ; If it was an update message from the correct input If _WinAPI_HiWord($wParam) = $EN_CHANGE And _WinAPI_LoWord($wParam) = $hInput_2 Then If GUICtrlRead($hInput_2) <> $sDef_2 Then ; Chenge label to green GUICtrlSetBkColor($hLabel_2, 0xCCFFCC) GUICtrlCreateIcon(@AutoItExe, -1, 220, 130, 16, 16) Else ; Set it back to default GUICtrlSetBkColor($hLabel_2, _WinAPI_GetSysColor($COLOR_MENU)) ; HOW TO REMOVE ICON? EndIf EndIf EndFunc ;==>_WM_COMMANDThanks Edited February 22, 2012 by maba Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 22, 2012 Moderators Share Posted February 22, 2012 maba,Two ways to do this:- 1. Delete and create the icon each time - this is what I have done with Icon_1.- 2. Create the icon once and then hide/show it as necessary - and this is what happens with Icon_2.expandcollapse popup#include <GUIConstants.au3> #include <WindowsConstants.au3> #include <EditConstants.au3> #include <WinAPI.au3> ; Set default values Global $sDef_1 = "Default value 1", $hIcon_1 Global $sDef_2 = "Default value 2", $hIcon_2 ; Create a GUI $hGUI = GUICreate("Test", 500, 500) $hLabel_1 = GUICtrlCreateLabel("Input 1", 10, 10, 200, 20) $hInput_1 = GUICtrlCreateInput($sDef_1, 10, 30, 200, 20) $hLabel_2 = GUICtrlCreateLabel("Input 2", 10, 110, 200, 20) $hInput_2 = GUICtrlCreateInput($sDef_2, 10, 130, 200, 20) $hIcon_2 = GUICtrlCreateIcon(@AutoItExe, -1, 220, 130, 16, 16) GUICtrlSetState(-1, $GUI_HIDE) GUISetState() ; Look for the WM_COMMAND messages GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND") ; Set current value $sInput_1_Content = $sDef_1 While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch ; Get the content of the input and compare the the last version $sInput_1_Text = GUICtrlRead($hInput_1) If $sInput_1_Text <> $sInput_1_Content Then ; It has changed so save it $sInput_1_Content = $sInput_1_Text If $sInput_1_Content <> $sDef_1 Then ; Colour the label to red GUICtrlSetBkColor($hLabel_1, 0xFFCCCC) $hIcon_1 = GUICtrlCreateIcon(@AutoItExe, -1, 220, 30, 16, 16) Else ; Set it back to white GUICtrlSetBkColor($hLabel_1, 0xFEFEFE) GUICtrlDelete($hIcon_1) EndIf EndIf WEnd Func _WM_COMMAND($hWHnd, $iMsg, $wParam, $lParam) ; If it was an update message from the correct input If _WinAPI_HiWord($wParam) = $EN_CHANGE And _WinAPI_LoWord($wParam) = $hInput_2 Then If GUICtrlRead($hInput_2) <> $sDef_2 Then ; Chenge label to green GUICtrlSetBkColor($hLabel_2, 0xCCFFCC) GUICtrlSetState($hIcon_2, $GUI_SHOW) Else ; Set it back to default GUICtrlSetBkColor($hLabel_2, _WinAPI_GetSysColor($COLOR_MENU)) GUICtrlSetState($hIcon_2, $GUI_HIDE) EndIf EndIf EndFunc ;==>_WM_COMMANDAll clear? M23 footswitch 1 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
maba Posted February 23, 2012 Author Share Posted February 23, 2012 Melba23,yes, it works. I prefer 2nd solution again Thanks!Now.. I would add some input validation functions at this point but.. is it the right place?"Warning: blocking of running user functions which executes window messages with commands such as "Msgbox()" can lead to unexpected behavior, the return to the system should be as fast as possible !!!"Is it referred to a "waiting user input function" only or for all "complex" funtions? Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 23, 2012 Moderators Share Posted February 23, 2012 maba,When it says "as fast as possible", it means as fast as possible!!! I try to spend as little time as possible in the handler itself. If you need to run a longish function, and certainly anything that involves a loop, then you should use the handler to set a flag and then check for it in your idle loop. Search for "+m23 +guiregistermsg" and you will find plenty of examples of how this can be done. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
maba Posted February 24, 2012 Author Share Posted February 24, 2012 Yes, I have founded some docs. Suggestion: flags or the dummy controls? Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 24, 2012 Moderators Share Posted February 24, 2012 maba, Just a question of personal taste in my opinion. I use both - but usually not in the same script (unless it is deliberate for an example). M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now