amin84 Posted July 14, 2012 Share Posted July 14, 2012 (edited) I searched for a while and I couldn't find much on this so here it is. This is used when you have the Edit menu with all of these in it. The problem with sending Ctrl+C or Ctrl+V is that you will loose the selection. This code will work with selection too. In this example the GUICtrlEdi is called $Edit1 and to use them you just assign the function to the button or menu... Func _selectAll() _GUICtrlEdit_SetSel($Edit1,0,-1) EndFunc Func _cut() $range = _GUICtrlEdit_GetSel(GUICtrlGetHandle($Edit1)) If $range[0] <> $range[1] Then ClipPut(StringMid(GUICtrlRead($Edit1), $range[0] + 1, $range[1] - $range[0])) EndIf _GUICtrlEdit_ReplaceSel(GUICtrlGetHandle($Edit1),'') EndFunc Func _copy() $range = _GUICtrlEdit_GetSel(GUICtrlGetHandle($Edit1)) If $range[0] <> $range[1] Then ClipPut(StringMid(GUICtrlRead($Edit1), $range[0] + 1, $range[1] - $range[0])) EndIf EndFunc Func _paste() $range = _GUICtrlEdit_GetSel(GUICtrlGetHandle($Edit1)) _GUICtrlEdit_ReplaceSel(GUICtrlGetHandle($Edit1),'') _GUICtrlEdit_InsertText($Edit1,ClipGet(),$range[0]) EndFunc Edited July 14, 2012 by leomoon Link to comment Share on other sites More sharing options...
czardas Posted July 14, 2012 Share Posted July 14, 2012 (edited) I don't loose selection after pressing Ctrl+C. Ctrl+A doesn't seem to work for me (and several others), so I have always created an accel key to handle that. You will always loose selected text after a paste action anyway. So do you have a question?EditI agree that it is a good idea to write the code rather than relying on the Send function. Edited July 14, 2012 by czardas operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
amin84 Posted July 14, 2012 Author Share Posted July 14, 2012 No I was just sharing the code I got. I added Cut, Copy and Paste as a menu (hotkeys work fine) but in order to get that menu working (not using keyboard) I had to either set the GUICtrlEdit as active then send ctrl+c or do it this way. If you use the first method, by the time we set it as active, it will loose the selection if the user had any. So I wrote this instead of setting active and sending hotkeys... Cuz lets say the user has selected a portion and wants to paste (replace) the selected with clipboard... That Ctrl+A only works if you only have one Edit box which I do (called $Edit1)... Link to comment Share on other sites More sharing options...
czardas Posted July 14, 2012 Share Posted July 14, 2012 You can use the style $ES_NOHIDESEL when you create the Edit control. Then you can always see the selection. You can also identify the control which has focus, so you can make your code work with as many edits as you can create. operator64 ArrayWorkshop 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