cardguy1000 Posted April 28, 2009 Posted April 28, 2009 I'm trying to make a textbox that is prefilled with instructional text in light gray font color, and then when the textbox gets focus the text will the disappear so the user can type in their text. I intended on using the GUICtrlCreateInput function, prefilling the textbox with the instructional text and then once the textbox gains focus to clear the contents of the textbox and to change the font color to black. However, I can not seem to find a value that GUIGetMsg() returns if a control gains focus. Does anyone have any ideas? Below is my idea, where the commented out portion is the part I don't know how to handle, I just made up the onfocus() function as an example of what I want. #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form= $frmExample = GUICreate("Example Form", 218, 135, 193, 125) $lblName = GUICtrlCreateLabel("Name:", 16, 40, 35, 17) $lblPhone = GUICtrlCreateLabel("Phone:", 16, 72, 38, 17) $txtName = GUICtrlCreateInput("", 64, 32, 121, 21) $txtPhone = GUICtrlCreateInput("555-555-5555", 64, 64, 121, 21) GUICtrlSetColor($txtPhone, 0xC0C0C0) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit ;~ Case onfocus($txtPhone) ;~ GUICtrlSetColor($txtPhone, 0x000000) ;~ ControlSetText('','',$txtPhone,'') EndSwitch WEnd
cardguy1000 Posted April 28, 2009 Author Posted April 28, 2009 (edited) Hopefully someone has a better way, but this is what I came up with: expandcollapse popup#include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <array.au3> $txtPhoneText = '555-555-5555' #Region ### START Koda GUI section ### Form= $frmExample = GUICreate("Example Form", 218, 135, 193, 125) $lblName = GUICtrlCreateLabel("Name:", 16, 40, 35, 17) $lblPhone = GUICtrlCreateLabel("Phone:", 16, 72, 38, 17) $txtName = GUICtrlCreateInput("", 64, 32, 121, 21) $txtPhone = GUICtrlCreateInput($txtPhoneText, 64, 64, 121, 21) GUICtrlSetColor($txtPhone, 0xC0C0C0) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch If _onchange($frmExample,$txtPhone, $txtPhoneText) Then GUICtrlSetColor($txtPhone, 0x000000) ControlSetText('','',$txtPhone,'') EndIf WEnd Func _onchange($form, $controlID, $originalText) If ControlGetHandle('','',ControlGetFocus($form) ) = GUICtrlGetHandle($controlID) AND ControlGetText('','', $controlID) = $originalText Then Return 1 Else Return 0 EndIf EndFunc Edited April 28, 2009 by cardguy1000
ResNullius Posted April 28, 2009 Posted April 28, 2009 Here's the approach I use, thanks to GaryFrost:http://www.autoitscript.com/forum/index.ph...st&p=391271PS: you'll have to fix the includes for constants declarations.
Valuater Posted April 28, 2009 Posted April 28, 2009 This was easy... #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form= $frmExample = GUICreate("Example Form", 218, 135, 193, 125) $lblName = GUICtrlCreateLabel("Name:", 16, 40, 35, 17) $lblPhone = GUICtrlCreateLabel("Phone:", 16, 72, 38, 17) $txtName = GUICtrlCreateInput("", 64, 32, 121, 21) $blank = GUICtrlCreateLabel("", 64, 64, 121, 21) $txtPhone = GUICtrlCreateInput("555-555-5555", 64, 64, 121, 21) GUICtrlSetColor($txtPhone, 0xC0C0C0) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $blank GUICtrlDelete($blank) GUICtrlSetData($txtPhone, "") EndSwitch WEnd 8)
BrettF Posted April 29, 2009 Posted April 29, 2009 Would $WM_SETFOCUS work as well? Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version!
WideBoyDixon Posted April 29, 2009 Posted April 29, 2009 expandcollapse popup#include <GUIConstantsEx.au3> #include <GuiEdit.au3> #include <WindowsConstants.au3> #include <Constants.au3> #include <GuiMenu.au3> #include <WinAPI.au3> Opt('MustDeclareVars', 1) Global $hGui, $cInput, $cInput2, $wProcOld _Main() Func _Main() Local $wProcNew, $DummyMenu $hGui = GUICreate("Focus!", 400, 200, -1, -1, $WS_THICKFRAME, -1) $cInput = GUICtrlCreateInput("Type something here", 20, 20, 360, 20) GUICtrlSetColor(-1, 0x808080) $cInput2 = GUICtrlCreateInput("Type something here", 20, 50, 360, 20) GUICtrlSetColor(-1, 0x808080) $wProcNew = DllCallbackRegister("_FocusWindowProc", "ptr", "hwnd;uint;long;ptr") $wProcOld = _WinAPI_SetWindowLong(GUICtrlGetHandle($cInput), $GWL_WNDPROC, DllCallbackGetPtr($wProcNew)) _WinAPI_SetWindowLong(GUICtrlGetHandle($cInput2), $GWL_WNDPROC, DllCallbackGetPtr($wProcNew)) GUISetState(@SW_SHOW) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd EndFunc ;==>_Main Func _FocusWindowProc($hWnd, $uiMsg, $wParam, $lParam) Switch $uiMsg Case $WM_SETFOCUS If _WinAPI_GetWindowText($hWnd) = "Type something here" Then _WinAPI_SetWindowText($hWnd, "") If $hWnd = GUICtrlGetHandle($cInput) Then GUICtrlSetColor($cInput, 0x000000) Else GUICtrlSetColor($cInput2, 0x000000) EndIf EndIf Case $WM_KILLFOCUS If _WinAPI_GetWindowText($hWnd) = "" Then _WinAPI_SetWindowText($hWnd, "Type something here") If $hWnd = GUICtrlGetHandle($cInput) Then GUICtrlSetColor($cInput, 0x808080) Else GUICtrlSetColor($cInput2, 0x808080) EndIf EndIf EndSwitch Return _WinAPI_CallWindowProc($wProcOld, $hWnd, $uiMsg, $wParam, $lParam) EndFunc ;==>_FocusWindowProc WBD [center]Wide by name, Wide by nature and Wide by girth[u]Scripts[/u]{Hot Folders} {Screen Calipers} {Screen Crosshairs} {Cross-Process Subclassing} {GDI+ Clock} {ASCII Art Signatures}{Another GDI+ Clock} {Desktop Goldfish} {Game of Life} {3D Pie Chart} {Stock Tracker}[u]UDFs[/u]{_FileReplaceText} {_ArrayCompare} {_ToBase}~ My Scripts On Google Code ~[/center]
Valuater Posted April 29, 2009 Posted April 29, 2009 @Firestorm... this does work!... or tell me why it doesn't! #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form= $frmExample = GUICreate("Example Form", 218, 135, 193, 125) $lblName = GUICtrlCreateLabel("Name:", 16, 40, 35, 17) $lblPhone = GUICtrlCreateLabel("Phone:", 16, 72, 38, 17) $blank1 = GUICtrlCreateLabel("", 64, 32, 121, 21) $txtName = GUICtrlCreateInput("Type some text here", 64, 32, 121, 21) GUICtrlSetColor($txtName, 0xC0C0C0) $blank2 = GUICtrlCreateLabel("", 64, 64, 121, 21) $txtPhone = GUICtrlCreateInput("555-555-5555", 64, 64, 121, 21) GUICtrlSetColor($txtPhone, 0xC0C0C0) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $blank1 GUICtrlDelete($blank1) GUICtrlSetData($txtName, "") GUICtrlSetColor($txtName, "") Case $blank2 GUICtrlDelete($blank2) GUICtrlSetData($txtPhone, "") GUICtrlSetColor($txtPhone, "") EndSwitch WEnd 8)
Skrip Posted April 29, 2009 Posted April 29, 2009 @Firestorm... this does work!... or tell me why it doesn't! #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form= $frmExample = GUICreate("Example Form", 218, 135, 193, 125) $lblName = GUICtrlCreateLabel("Name:", 16, 40, 35, 17) $lblPhone = GUICtrlCreateLabel("Phone:", 16, 72, 38, 17) $blank1 = GUICtrlCreateLabel("", 64, 32, 121, 21) $txtName = GUICtrlCreateInput("Type some text here", 64, 32, 121, 21) GUICtrlSetColor($txtName, 0xC0C0C0) $blank2 = GUICtrlCreateLabel("", 64, 64, 121, 21) $txtPhone = GUICtrlCreateInput("555-555-5555", 64, 64, 121, 21) GUICtrlSetColor($txtPhone, 0xC0C0C0) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $blank1 GUICtrlDelete($blank1) GUICtrlSetData($txtName, "") GUICtrlSetColor($txtName, "") Case $blank2 GUICtrlDelete($blank2) GUICtrlSetData($txtPhone, "") GUICtrlSetColor($txtPhone, "") EndSwitch WEnd 8) Sorry, I removed my post. I was the one who misunderstood. I was thinking focus of the GUI. [left][sub]We're trapped in the belly of this horrible machine.[/sub][sup]And the machine is bleeding to death...[/sup][sup][/sup][/left]
cardguy1000 Posted April 29, 2009 Author Posted April 29, 2009 @Firestorm... this does work!... or tell me why it doesn't! #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form= $frmExample = GUICreate("Example Form", 218, 135, 193, 125) $lblName = GUICtrlCreateLabel("Name:", 16, 40, 35, 17) $lblPhone = GUICtrlCreateLabel("Phone:", 16, 72, 38, 17) $blank1 = GUICtrlCreateLabel("", 64, 32, 121, 21) $txtName = GUICtrlCreateInput("Type some text here", 64, 32, 121, 21) GUICtrlSetColor($txtName, 0xC0C0C0) $blank2 = GUICtrlCreateLabel("", 64, 64, 121, 21) $txtPhone = GUICtrlCreateInput("555-555-5555", 64, 64, 121, 21) GUICtrlSetColor($txtPhone, 0xC0C0C0) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $blank1 GUICtrlDelete($blank1) GUICtrlSetData($txtName, "") GUICtrlSetColor($txtName, "") Case $blank2 GUICtrlDelete($blank2) GUICtrlSetData($txtPhone, "") GUICtrlSetColor($txtPhone, "") EndSwitch WEnd 8) Valuater, that only works if the user clicks the control. If they tab to it then it will not work.
cardguy1000 Posted April 29, 2009 Author Posted April 29, 2009 Here's the approach I use, thanks to GaryFrost:http://www.autoitscript.com/forum/index.ph...st&p=391271PS: you'll have to fix the includes for constants declarations.Thanks, this is just what I needed.
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