FuryCell Posted February 1, 2010 Share Posted February 1, 2010 (edited) #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 295, 71, 192, 124) $Input1 = GUICtrlCreateInput("Input1", 13, 27, 273, 21) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Why is the text in $Input1 selected when the script is executed? I have tested this on both my Windows 7 Host OS and in a virtual machine running Windows XP. Is this a bug or am I do something wrong? Edited February 1, 2010 by P5ych0Gigabyte HKTunes:Softpedia | GoogleCodeLyricToy:Softpedia | GoogleCodeRCTunes:Softpedia | GoogleCodeMichtaToolsProgrammer n. - An ingenious device that turns caffeine into code. Link to comment Share on other sites More sharing options...
FuryCell Posted February 1, 2010 Author Share Posted February 1, 2010 I'm quite sure that has always been the default behavior of an input control that has focus.EDIT: I assume it is to make it easier for the user to change the text in the input. doh. I need some sleep. HKTunes:Softpedia | GoogleCodeLyricToy:Softpedia | GoogleCodeRCTunes:Softpedia | GoogleCodeMichtaToolsProgrammer n. - An ingenious device that turns caffeine into code. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 1, 2010 Moderators Share Posted February 1, 2010 P5ych0Gigabyte, A quick way to place the cursor at the end of the Input text if you would prefer that: #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> $Form1 = GUICreate("Form1", 295, 71, 192, 124) $Input1 = GUICtrlCreateInput("Input1", 13, 27, 273, 21) GUISetState(@SW_SHOW) GUICtrlSendMsg($Input1, $EM_SETSEL, -1, -1) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd That solution will only work the initial time the edit gets focus. If you wanted to prevent the selection of the text every time the edit control gains focus as you tab around the GUI, you would need to subclass the control which is rather more work. If you are interested I could take a shot at it for you - just let me know. 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...
Moderators Melba23 Posted February 1, 2010 Moderators Share Posted February 1, 2010 (edited) Thanubis, Why not just use WM_COMMAND?Why not indeed? As often, there are lots of ways to solve a problem. M23 Edit: Here is the subclassing method that I spoke of above. Tab through the controls and see both Inputs highlight all text each time. Then press the "SubClass" button and see that the right-hand Input no longer highlights all the text. If you press the "Revert" button, the right-hand Input returns to the default behaviour: expandcollapse popup#include <GUIConstantsEX.au3> #include <EditConstants.au3> #include <WinAPI.au3> Global $pOriginal_EditProc, $hNew_EditProc = 0 $hGUI = GUICreate("Subclassed Edit", 200, 100) GUICtrlCreateInput("Example text", 10, 10, 80, 20) $hInput = GUICtrlCreateInput("Example text", 100, 10, 80, 20) $hButton = GUICtrlCreateButton("SubClass", 60, 50, 80, 30) GUISetState() GUICtrlSendMsg($hInput, 0xB1, -1, -1) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ; Must delete subclassed controls before freeing DLLCallbacks GUIDelete($hGUI) ; Now free DLLCallbacks DllCallbackFree($hNew_EditProc) Exit Case $hButton If GUICtrlRead($hButton) = "SubClass" Then GUICtrlSetData($hButton, "Revert") _EditSubClass() GUICtrlSetState($hInput, $GUI_FOCUS) Else GUICtrlSetData($hButton, "SubClass") _EditRevert() GUICtrlSetState($hInput, $GUI_FOCUS) EndIf EndSwitch WEnd Func _EditSubClass() ; Create callback $hNew_EditProc = DllCallbackRegister("_EditProc", "int", "hwnd;uint;wparam;lparam") ; get pointer Local $pNew_EditProc = DllCallbackGetPtr($hNew_EditProc) ; Subclass the Input $pOriginal_EditProc = _WinAPI_SetWindowLong(GUICtrlGetHandle($hInput), -4, $pNew_EditProc) If @error Then Return SetError(1, 0, 0) If $pOriginal_EditProc = 0 Then Return SetError(1, 0, 0) EndFunc ;==>_EditSubClass Func _EditRevert() _WinAPI_SetWindowLong(GUICtrlGetHandle($hInput), -4, $pOriginal_EditProc) If @error Then Return SetError(1, 0, 0) EndFunc Func _EditProc($hWnd, $iMsg, $wParam, $lParam) If $iMsg = $EM_SETSEL And $lParam <> -1 Then GUICtrlSendMsg($hInput, 0xB1, -1, -1) ; Use StringLen(GUICtrlRead($hInput)), -1) if you want the caret at the end of the input Return 0 Else ; Other messages go to default WindowProc Return _WinAPI_CallWindowProc($pOriginal_EditProc, $hWnd, $iMsg, $wParam, $lParam) EndIf EndFunc ;==>_EditProc A bit of overkill for this particular case I will be the first to admit, but I hope it is instructive! M23 Edited February 1, 2010 by Melba23 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...
FuryCell Posted February 1, 2010 Author Share Posted February 1, 2010 P5ych0Gigabyte, A quick way to place the cursor at the end of the Input text if you would prefer that: #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> $Form1 = GUICreate("Form1", 295, 71, 192, 124) $Input1 = GUICtrlCreateInput("Input1", 13, 27, 273, 21) GUISetState(@SW_SHOW) GUICtrlSendMsg($Input1, $EM_SETSEL, -1, -1) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd That solution will only work the initial time the edit gets focus. If you wanted to prevent the selection of the text every time the edit control gains focus as you tab around the GUI, you would need to subclass the control which is rather more work. If you are interested I could take a shot at it for you - just let me know. M23 Thanks that is perfect for what I am working on. HKTunes:Softpedia | GoogleCodeLyricToy:Softpedia | GoogleCodeRCTunes:Softpedia | GoogleCodeMichtaToolsProgrammer n. - An ingenious device that turns caffeine into code. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 2, 2010 Moderators Share Posted February 2, 2010 One final method - just to show that you do not need the fancy stuff at all! expandcollapse popup#include <GUIConstantsEX.au3> #include <EditConstants.au3> #include <WinAPI.au3> Global $pOriginal_EditProc, $hNew_EditProc = 0 $hGUI = GUICreate("Input Caret Position", 200, 100) $hInput_1 = GUICtrlCreateInput("Caret to front", 10, 10, 80, 20) $hHandle_1 = GUICtrlGetHandle(-1) $hInput_2 = GUICtrlCreateInput("Caret to end", 100, 10, 80, 20) $hHandle_2 = GUICtrlGetHandle(-1) GUISetState() $hCurrInput = 0 While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch $hCurrFocus = _WinAPI_GetFocus() If $hCurrFocus <> $hCurrInput Then Switch $hCurrFocus Case $hHandle_1 GUICtrlSendMsg($hInput_1, 0xB1, 0, 0) $hCurrInput = $hCurrFocus Case $hHandle_2 GUICtrlSendMsg($hInput_2, 0xB1, StringLen(GUICtrlRead($hInput_2)), -1) $hCurrInput = $hCurrFocus EndSwitch EndIf WEnd 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