PhoenixXL Posted September 27, 2012 Share Posted September 27, 2012 Hey Every1 I'm having a problem with the Func _GUICtrlRichEdit_GetSelAA When I have a Selection in the RichEdit that is from High level to Low Level [Done by holding shift and pressing the Left Arrow Key] and then I execute the the same function mentioned above [in my script done by Alt+N] Then If we press Right Arrow Key holding Shift Key Instead of getting deselected, the selection proceeds towards the Right. That is the Anchor Point Shifts from the High Level to the Low Level Recreation of the Problem. #include <GuiRichEdit.au3> #include <WindowsConstants.au3> #include <GUIConstantsEx.au3> HotKeySet('!n', 'Debug') Local $hGui, $iMsg, $btnNext, $iStep = 0 $hGui = GUICreate("Example (" & StringTrimRight(@ScriptName, 4) & ")", 320, 350, -1, -1) $hRichEdit = _GUICtrlRichEdit_Create($hGui, "This is a test.", 10, 10, 300, 220, BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL)) ;Global Const $___pOld_WndProc=_WinAPI_SetWindowLong($hRichEdit,-4,$___pNew_WndProc) GUISetState() _GUICtrlRichEdit_SetText($hRichEdit, "Paragraph 1") While True $iMsg = GUIGetMsg() Switch $iMsg Case $GUI_EVENT_CLOSE _GUICtrlRichEdit_Destroy($hRichEdit) ; needed unless script crashes GUIDelete() ; is OK too Exit EndSwitch WEnd Func Debug() ConsoleWrite('cWord: "' & _GetCaretOffset($hRichEdit) & '" Extended: ' & @error & @CR) EndFunc ;==>NewWndProc Func _GetCaretOffset($nRichEdit) Local $_LineIndex = _GUICtrlRichEdit_GetSel($nRichEdit) If Not IsArray($_LineIndex) Then Return SetError(1, @error, -1) Switch $_LineIndex[0] Case $_LineIndex[1] Return SetExtended(0, $_LineIndex[1]) Case Else Local $_LineIndex = _GUICtrlRichEdit_GetSelAA($nRichEdit) Return SetExtended(1, $_LineIndex[1]) EndSwitch EndFunc ;==>_GetCaretOffset Just wanted to Know is it a known bug or Im missing some point ? My code: PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners. MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression. Link to comment Share on other sites More sharing options...
martin Posted September 27, 2012 Share Posted September 27, 2012 (edited) The reason is, as far as I understand it is (in my view) a bug in the udf. The EM_GETSEL return a CHARRANGE structure. EM_SETSEL uses the start selection and end selection which are not always the same as the min and max values in the CHARRANGE. So in the udf this Func _GUICtrlRichEdit_GetSelAA($hWnd) If Not _WinAPI_IsClassName($hWnd, $_GRE_sRTFClassName) Then Return SetError(101, 0, 0) Local $aiLowHigh = _GUICtrlRichEdit_GetSel($hWnd) If $aiLowHigh[0] = $aiLowHigh[1] Then Return SetError(-1, 0, 0) ; no text selected _SendMessage($hWnd, $EM_SETSEL, -1, 0) ; deselect Local $aiNoSel = _GUICtrlRichEdit_GetSel($hWnd) Local $aRet[2] If $aiLowHigh[0] = $aiNoSel[0] Then ; if active < anchor $aRet[0] = $aiLowHigh[1] $aRet[1] = $aiLowHigh[0] Else $aRet = $aiLowHigh EndIf ; restore selection _SendMessage($hWnd, $EM_SETSEL, $aiLowHigh[0], $aiLowHigh[1]) _WinAPI_SetFocus($hWnd) ; need to have the selection updated Return $aRet EndFunc ;==>_GUICtrlRichEdit_GetSelAA should be changed to Func _GUICtrlRichEdit_GetSelAA($hWnd) If Not _WinAPI_IsClassName($hWnd, $_GRE_sRTFClassName) Then Return SetError(101, 0, 0) Local $aiLowHigh = _GUICtrlRichEdit_GetSel($hWnd) If $aiLowHigh[0] = $aiLowHigh[1] Then Return SetError(-1, 0, 0) ; no text selected _SendMessage($hWnd, $EM_SETSEL, -1, 0) ; deselect Local $aiNoSel = _GUICtrlRichEdit_GetSel($hWnd) Local $aRet[2] If $aiLowHigh[0] = $aiNoSel[0] Then ; if active < anchor $aRet[0] = $aiLowHigh[1] $aRet[1] = $aiLowHigh[0] Else $aRet = $aiLowHigh EndIf ; restore selection _SendMessage($hWnd, $EM_SETSEL, $aRet[0], $aRet[1]) _WinAPI_SetFocus($hWnd) ; need to have the selection updated Return $aRet EndFunc ;==>_GUICtrlRichEdit_GetSelAA Without the change to the udf you could add a line to your code to overcome the problem like this Func _GetCaretOffset($nRichEdit) Local $_LineIndex = _GUICtrlRichEdit_GetSel($nRichEdit) If Not IsArray($_LineIndex) Then Return SetError(1, @error, -1) Switch $_LineIndex[0] Case $_LineIndex[1] Return SetExtended(0, $_LineIndex[1]) Case Else Local $_LineIndex = _GUICtrlRichEdit_GetSelAA($nRichEdit) _SendMessage($nRichEdit, $EM_SETSEL, $_LineIndex[0], $_LineIndex[1]);<=========== add this Return SetExtended(1, $_LineIndex[1]) EndSwitch EndFunc ;==>_GetCaretOffset That change will still work even if the udf gets changed. I think you should report this as a bug, but first check it hasn't already been reported and get someone else to agree or tell me I'm wrong. Edited September 27, 2012 by martin Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
PhoenixXL Posted September 28, 2012 Author Share Posted September 28, 2012 Thnks My code: PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners. MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression. 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