amin84 2 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 Share this post Link to post Share on other sites
czardas 1,269 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 Share this post Link to post Share on other sites
amin84 2 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)... Share this post Link to post Share on other sites
czardas 1,269 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 Share this post Link to post Share on other sites