Jump to content

Problem with My Edit Copy/Cut UDF


BrettF
 Share

Recommended Posts

My _GUICtrlEditTextClipboard function will copy/cut text from an edit to the clipboard. The problem- it wont cut. COuld some one please tell me why??

#Include <GuiEdit.au3>
Func _GUICtrlEditTextClipboard($Edit, $type = "Copy")
        $a_sel = _GUICtrlEditGetSel($Edit)
    If ($a_sel == $EC_ERR) Then
        Return 2 ;Error Getting Selection Pos
    EndIf
    Local $WholeEdit = GUICtrlRead($Edit)
    Local $Trim = StringLeft(StringTrimLeft($WholeEdit, $a_sel[1]), $a_sel[2] - $a_sel[1])
    If $type = "Copy" Then
        ClipPut($Trim)
        Return 0 ;Sucsessful Copy
    ElseIf $type = "Cut" Then
        ClipPut($Trim)
        _GUICtrlEditReplaceSel($Edit, 1, "")
        Return 1 ;Sucsessful Cut
    Else 
        Return 3 ; Error with type of clipboard
    EndIf
EndFunc   ;==>_GUICtrlEditTextClipboard
Link to comment
Share on other sites

Hi,

it does the cut for me.

#Include <GuiEdit.au3>
#include <GUIConstants.au3>

GUICreate("My GUI edit")  ; will create a dialog box that when displayed is centered
$myedit = GUICtrlCreateEdit("First line" & @CRLF, 176, 32, 121, 97, BitOR($ES_AUTOVSCROLL, $WS_VSCROLL, $ES_MULTILINE, $WS_HSCROLL))

$b = GUICtrlCreateButton("ok", 10, 160, 40, 20)
GUISetState()

; will be append dont' forget 3rd parameter
GUICtrlSetData($myedit, "Second line" & @CRLF & " Hallo", 1)

; Run the GUI until the dialog is closed
While 1
    $msg = GUIGetMsg()

    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
    If $msg = $b Then _GUICtrlEditTextClipboard($myedit, "Cut")
WEnd
Func _GUICtrlEditTextClipboard($Edit, $type = "Copy")
    $a_sel = _GUICtrlEditGetSel($Edit)
    If ($a_sel == $EC_ERR) Then
        Return 2 ;Error Getting Selection Pos
    EndIf
    Local $WholeEdit = GUICtrlRead($Edit)
    Local $Trim = StringLeft(StringTrimLeft($WholeEdit, $a_sel[1]), $a_sel[2] - $a_sel[1])
    If $type = "Copy" Then
        ClipPut($Trim)
        Return 0 ;Sucsessful Copy
    ElseIf $type = "Cut" Then
        ClipPut($Trim)
        _GUICtrlEditReplaceSel($Edit, 1, "")
        Return 1 ;Sucsessful Cut
    Else
        Return 3 ; Error with type of clipboard
    EndIf
EndFunc   ;==>_GUICtrlEditTextClipboard

So long,

Mega

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

  • Moderators

That function could be shrunk a tad:

Func _GUICtrlEditTextClipboard($nCID, $sType = '')
    Local $aSel = _GUICtrlEditGetSel($nCID)
    If $aSel = -1 Then Return SetError(1, 0, -1)
    Local $sText = StringMid(GUICtrlRead($nCID), $aSel[1] + 1, ($aSel[2] - $aSel[1]) + 1)
    If $sType = 'copy' Then Return ClipPut($sText)
    ClipPut($sText)
    Return _GUICtrlEditReplaceSel($nCID, 1, "")
EndFunc   ;==>_GUICtrlEditTextClipboardoÝ÷ ØGb´k²Â,¥vè¾'^jw±jjezíá!(§q쨹Øm=«­¢+Ø¥¹±Õ±ÐíU%
½¹ÍѹÑ̹ÔÌÐì(¥¹±Õ±ÐíÕ¥¥Ð¹ÔÌÐì)¥´ÀÌØíµå¥Ð°ÀÌØíMÑÑÕÌ°ÀÌØíµÍ°ÀÌØí   ѹ}P°ÀÌØí}Í°)U%
ÉÑ ÅÕ½Ðí¥ÐÐ1¥¹
½Õ¹ÐÅÕ½Ðì°ÌäÈ°ÈÔФ(ÀÌØíµå¥ÐôU%
Ñɱ
ÉѥРÅÕ½Ðí¥ÉÍб¥¹ÅÕ½ÐìµÀì
I1°ÄÐÀ°ÌÈ°ÄÈÄ°äÜ°    ¥Ñ=H ÀÌØíM}UQ=YM
I=10°ÀÌØí]M}YM
I=10°ÀÌØíM}5U1Q%1%9¤¤)U%
ÑɱMÑ1¥µ¥Ð ÀÌØíµå¥Ð°ÄÔÀÀ¤(ÀÌØíMÑÑÕÌôU%
Ñɱ
ÉÑ1° ÅÕ½ÐìÅÕ½Ðì°À°ÈÌаÌäÈ°ÈÀ°    ¥Ñ=H ÀÌØíMM}MU9-8°ÀÌØíMM}
9QH¤¤(ÀÌØí    ѹ}PôU%
Ñɱ
ÉÑ    ÕÑѽ¸ ÅÕ½ÐíÐM°ÅÕ½Ðì°ÄÔÀ°ÄÌÀ°äÀ°ÐÀ°ÀÌØí  M}5U1Q%1%9¤(ìÝ¥±°ÁÁ¹½¹ÐÌäì½ÉÐÍÉÁɵÑÈ)U%
ÑɱMÑÑ ÀÌØíµå¥Ð°ÅÕ½Ðìɹ±¥¹ÅÕ½ÐìµÀì
I1µÀìÅÕ½ÐìÍɱ¥¹ÅÕ½ÐìµÀì
I1µÀìÅÕ½ÐìÑÑ ±¥¹ÅÕ½ÐìµÀì
I1µÀì|(ÅÕ½ÐìÕÑ ±¥¹ÅÕ½ÐìµÀì
I1µÀìÅÕ½ÐìÙÑ ±¥¹ÅÕ½ÐìµÀì
I1µÀìÅÕ½ÐìÝÑ ±¥¹ÅÕ½ÐìµÀì
I1µÀìÅÕ½ÐìáÑ ±¥¹ÅÕ½ÐìµÀì
I1µÀìÅÕ½ÐìåÑ ±¥¹ÅÕ½Ðì°Ä¤)U%MÑMÑÑ ¤(ìIոѡU$չѥ°Ñ¡¥±½¥Ì±½Í)]¡¥±Ä(ÀÌØíµÍôU%Ñ5Í ¤(M±Ð(
ÍÀÌØíµÍôÀÌØíU%}Y9Q}
1=M(á¥Ñ1½½À(
ÍÀÌØíµÍôÀÌØí    ѹ}P($$%}U%
Ñɱ¥ÑQáÑ
±¥Á½É ÀÌØíµå¥Ð¤(¹M±Ð)]¹)Õ¹}U%
Ñɱ¥ÑQáÑ
±¥Á½É ÀÌØí¹
%°ÀÌØíÍQåÁôÌäìÌäì¤(1½°ÀÌØíM°ô}U%
Ñɱ¥ÑÑM° ÀÌØí¹
%¤(%ÀÌØíM°ô´ÄQ¡¸IÑÕɸMÑÉÉ½È Ä°À°´Ä¤(1½°ÀÌØíÍQáÐôMÑÉ¥¹5¥¡U%
ÑɱI ÀÌØí¹
%¤°ÀÌØíM±lÅt¬Ä° ÀÌØíM±lÉt´ÀÌØíM±lÅt¤¬Ä¤(%ÀÌØíÍQåÁôÌäí½ÁäÌäìQ¡¸IÑÕɸ
±¥ÁAÕÐ ÀÌØíÍQáФ(
±¥ÁAÕÐ ÀÌØíÍQáФ(IÑÕɸ}U%
Ñɱ¥ÑIÁ±M° ÀÌØí¹
%°QÉÕ°ÅÕ½ÐìÅÕ½Ðì¤)¹Õ¹ìôôÐí}U%
Ñɱ¥ÑQáÑ
±¥Á½É

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...