HurleyShanabarger Posted February 25, 2022 Posted February 25, 2022 Hi there, the GUI I am create has an input control, which show the paths to a selected folder. Depending on a setting on the GUI text should be appended to the folder - but in a different color. Basically it should be the combination of the user input/selection and the style that _GUICtrlEdit_SetCueBanner provides. Is there anything built in or do I need to create my on style for that?
Nine Posted February 25, 2022 Posted February 25, 2022 As per MSDN, you cannot : Quote An edit control that is used to begin a search may display "Enter search here" in gray text as a textual cue. When the user clicks the text, the text goes away and the user can type. You cannot set a cue banner on a multiline edit control or on a rich edit control. But you could simulate a cue in conjunction with EN_SETFOCUS notification. When the edit box receive the focus, you can erase the content, if it is the default value that is currently displayed... “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
HurleyShanabarger Posted February 25, 2022 Author Posted February 25, 2022 (edited) Got it working: expandcollapse popup#NoTrayIcon #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_UseX64=n #Tidy_Parameters=/reel /sf /ri #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #Region Description #EndRegion Description #Region Includes #include <GuiRichEdit.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #EndRegion Includes #Region Variables/Opt Opt("MustDeclareVars", 1) Global $g_boFocusKill = False, $g_hFocusKill = 0 Global $g_boFocusSet = False, $g_hFocusSet = 0 #EndRegion Variables/Opt #Region Main _Main() Func _Main() Local $hGUI = GUICreate('RichEdit with Input and Cue', 410, 83) Local $hRichEdit = _GUICtrlRichEdit_Create($hGUI, ">> This is the original text<<", 5, 5, 400, 21, $ES_LEFT) GUICtrlCreateButton("Button for loosing focus from RichEdit", 5, 31, 400, 21) Local $hEdit = GUICtrlCreateEdit("Edit for loosing focus from RichEdit", 5, 57, 400, 21, $ES_LEFT) GUISetState(@SW_SHOW, $hGUI) GUIRegisterMsg($WM_COMMAND, '_GUI_WM_FocusState') While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop EndSwitch If $g_boFocusSet Then If $g_hFocusSet = $hRichEdit Then _GUICtrlRichEdit_CueRemove($hRichEdit, "This is my cue text") $g_boFocusSet = False $g_hFocusSet = 0 EndIf If $g_boFocusKill Then If $g_hFocusKill = $hRichEdit Then _GUICtrlRichEdit_CueAppend($hRichEdit, "This is my cue text") $g_boFocusKill = False $g_hFocusKill = 0 EndIf WEnd EndFunc ;==>_Main #EndRegion Main #Region Functions GUI Func _GUICtrlRichEdit_CueAppend($p_hCtrl, $p_sgText) ; Get text, replace cue and set text Local $sgText = _GUICtrlRichEdit_GetText($p_hCtrl) $sgText = StringRegExpReplace($sgText, "\Q" & $p_sgText & "\E$", "") _GUICtrlRichEdit_SetText($p_hCtrl, $sgText) _SendMessage($p_hCtrl, $EM_SETSEL, -1, -1) _GUICtrlRichEdit_SetCharColor($p_hCtrl, Dec('C0C0C0')) _GUICtrlRichEdit_AppendTextWithoutFocus($p_hCtrl, $p_sgText) _SendMessage($p_hCtrl, $EM_SETSEL, -1, -1) EndFunc ;==>_GUICtrlRichEdit_CueAppend Func _GUICtrlRichEdit_CueRemove($p_hCtrl, $p_sgText) ; Get text and replace cue Local $sgText = _GUICtrlRichEdit_GetText($p_hCtrl) $sgText = StringRegExpReplace($sgText, "\Q" & $p_sgText & "\E$", "") ; Set text and restore selection _GUICtrlRichEdit_SetText($p_hCtrl, $sgText) _SendMessage($p_hCtrl, $EM_SETSEL, -1, -1) EndFunc ;==>_GUICtrlRichEdit_CueRemove #EndRegion Functions GUI #Region Functions Func _GUI_WM_FocusState($p_hWnd, $p_iMsg, $p_wParam, $p_lParam) Local $iCode = _WinAPI_HiWord($p_wParam) Switch $iCode Case $EN_SETFOCUS $g_boFocusSet = True $g_hFocusSet = $p_lParam Case $EN_KILLFOCUS $g_boFocusKill = True $g_hFocusKill = $p_lParam EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>_GUI_WM_FocusState Func _GUICtrlRichEdit_AppendTextWithoutFocus($hWnd, $sText) If Not _WinAPI_IsClassName($hWnd, $__g_sRTFClassName) Then Return SetError(101, 0, False) Local $iLength = _GUICtrlRichEdit_GetTextLength($hWnd) ; UDF _GUICtrlRichEdit_AppendText would call _GUICtrlRichEdit_SetSel, which calls _WinAPI_SetFocus ; Call of _WinAPI_SetFocus creates issue with focus detection _SendMessage($hWnd, $EM_SETSEL, $iLength, $iLength) Local $tSetText = DllStructCreate($tagSETTEXTEX) DllStructSetData($tSetText, 1, $ST_SELECTION) Local $iRet If StringLeft($sText, 5) <> "{\rtf" And StringLeft($sText, 5) <> "{urtf" Then DllStructSetData($tSetText, 2, $CP_UNICODE) $iRet = _SendMessage($hWnd, $EM_SETTEXTEX, $tSetText, $sText, 0, "struct*", "wstr") Else DllStructSetData($tSetText, 2, $CP_ACP) $iRet = _SendMessage($hWnd, $EM_SETTEXTEX, $tSetText, $sText, 0, "struct*", "STR") EndIf If Not $iRet Then Return SetError(700, 0, False) Return True EndFunc ;==>_GUICtrlRichEdit_AppendTextWithoutFocus #EndRegion Functions Edited February 25, 2022 by HurleyShanabarger
ad777 Posted February 25, 2022 Posted February 25, 2022 @HurleyShanabarger 2 hours ago, HurleyShanabarger said: do I need to create my on style for that? Yeah you create your own style like this: expandcollapse popup#include <GUIConstantsEx.au3> #include <GuiEdit.au3> #include <MsgBoxConstants.au3> Example() Func Example() Global $SET = "ON" Local $hGUI = GUICreate('Example', 300, 150) GUISetFont(10, 400, 0, 'Segoe UI') Local $idUsername = GUICtrlCreateInput('', 10, 10, 125, 25) _GUICtrlEdit_SetCueBanner($idUsername, "Search folder") Local $idPassword = GUICtrlCreateInput('Search..', 10, 40, 125, 25) Local $idButton_Close = GUICtrlCreateButton("Close", 210, 120, 85, 25) ControlFocus($hGUI, "", $idButton_Close) GUISetState(@SW_SHOW, $hGUI) MsgBox($MB_SYSTEMMODAL, "", _GUICtrlEdit_GetCueBanner($idPassword)) While 1 _SetCueBannerCF("Search..", $hGUI, $idPassword, 0x008000, "Segoe UI", 8, 400) Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $idButton_Close ExitLoop EndSwitch WEnd GUIDelete($hGUI) EndFunc ;==>Example Func _SetCueBannerCF($Text, $GUI, $Control, $color, $font, $size, $width) If $SET = "ON" Then GUICtrlSetColor($Control, $color) GUICtrlSetFont($Control, $size, $width, 0, $font) $SET = "OF" EndIf $CurInfo = GUIGetCursorInfo($GUI) If $CurInfo[4] = $Control And $CurInfo[2] = 1 Then If GUICtrlRead($Control) = $Text Then GUICtrlSetData($Control, "") EndIf ElseIf $CurInfo[4] <> $Control And $CurInfo[2] = 1 And GUICtrlRead($Control) = "" Then GUICtrlSetData($Control, $Text) EndIf EndFunc ;==>_SetCueBannerCF none
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