Mat Posted December 13, 2009 Share Posted December 13, 2009 (edited) One of the many things on my (long) to do list that i have not been able to do recently due to a rather pleasant surprise, it was very quick and easy though.Everyone has seen those forms that already have text in the inputs such as "Search for..." that then disappears when the edit gains focus. Thats what this does, all you need to do is add one line after the edit/input, and thats it!the code:expandcollapse popupGlobal $EDIT_DEF_ITEMS[1][2] = [[0, 0]] Func _GUIEditSetDefault ($hEdit, $sDef) If $hEdit = 0 Then Return SetError (1, 0, 0) If $EDIT_DEF_ITEMS[0][0] = 0 Then GUIRegisterMsg (0x0111, "EDIT_DEF_WM_COMMAND") If GUICtrlRead ($hEdit) = "" Then GUICtrlSetColor ($hEdit, 0x444444) GUICtrlSetData ($hEdit, $sDef) EndIf ReDim $EDIT_DEF_ITEMS[UBound ($EDIT_DEF_ITEMS) + 1][2] $EDIT_DEF_ITEMS[UBound ($EDIT_DEF_ITEMS) - 1][0] = $hEdit $EDIT_DEF_ITEMS[UBound ($EDIT_DEF_ITEMS) - 1][1] = $sDef Return 1 EndFunc ; ==> _GUIEditSetDefault Func EDIT_DEF_WM_COMMAND ($hWnd, $msgID, $wParam, $lParam) Local $n = EDIT_DEF_GETINDEX (BitAND ($wParam, 0xFFFF)) If $n = -1 Then Return "GUI_RUNDEFMSG" Local $nMsg = BitShift($wParam, 16) If $nMsg = 256 Then ; Gained focus (EN_SETFOCUS) If (GUICtrlRead ($EDIT_DEF_ITEMS[$n][0]) == $EDIT_DEF_ITEMS[$n][1]) Then GUICtrlSetColor ($EDIT_DEF_ITEMS[$n][0], 0x000000) GUICtrlSetData ($EDIT_DEF_ITEMS[$n][0], "") EndIf ElseIf $nMsg = 512 Then ; Lost Focus (EN_KILLFOCUS) If GUICtrlRead ($EDIT_DEF_ITEMS[$n][0]) = "" Then GUICtrlSetColor ($EDIT_DEF_ITEMS[$n][0], 0x444444) GUICtrlSetData ($EDIT_DEF_ITEMS[$n][0], $EDIT_DEF_ITEMS[$n][1]) EndIf EndIf EndFunc ; ==> EDIT_DEF_WM_COMMAND Func EDIT_DEF_GETINDEX ($hEdit) For $i = 1 to UBound ($EDIT_DEF_ITEMS) - 1 If $EDIT_DEF_ITEMS[$i][0] = $hEdit Then Return $i Next Return -1 EndFunc ; ==> EDIT_DEF_GETINDEXAnd an example:GUICreate ("Testing") $hEdit = GUICtrlCreateInput ("", 2, 2, 100, 20) _GUIEditSetDefault ($hEdit, "This is the test") $hEdit2 = GUICtrlCreateInput ("", 2, 24, 80, 20) _GUIEditSetDefault ($hEdit2, "Take 2.") GUISetState () While GUIGetMsg () <> -3 Sleep (10) WEndMat Edited December 13, 2009 by Mat AutoIt Project Listing Link to comment Share on other sites More sharing options...
AlmarM Posted March 12, 2010 Share Posted March 12, 2010 Ha, thats great. Something I needed a long time ago. -Saves-But still, what about a default "style"?So you could do something like "Password" Minesweeper A minesweeper game created in autoit, source available. _Mouse_UDF An UDF for registering functions to mouse events, made in pure autoit. 2D Hitbox Editor A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes. Link to comment Share on other sites More sharing options...
Mat Posted March 12, 2010 Author Share Posted March 12, 2010 Ha, thats great. Something I needed a long time ago. -Saves-But still, what about a default "style"?So you could do something like "Password" Not a bad Idea, I'll have a look and see what I can do. AutoIt Project Listing 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