Jump to content

Recommended Posts

Posted (edited)

Title pretty much says it. I want to drag the text from a listview , and paste it onto an external app.

What would be the basic mechanism for this, I've seen some fairly dense code that does many things and only want this basic functionality.

Edited by Jdop
Posted (edited)

  Jdop said:

Title pretty much says it. I want to drag the text from a listview , and paste it onto an external app.

What would be the basic mechanism for this, I've seen some fairly dense code that does many things and only want this basic functionality.

Here is an example of one way to do it.

#include <GUIConstants.au3>

#include <guilistview.au3>


#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Choices Dialog", 353, 256, 303, 219)
GUISetIcon("D:07.ico")
$Edit1 = GUICtrlCreateEdit("", 160, 32, 185, 89)
GUICtrlSetData(-1, "Edit1")
$LV = GUICtrlCreateListView("title", 8, 24, 130, 150)
GUICtrlSendMsg(-1, 0x101E, 0, 100)
$ListView1_0 = GUICtrlCreateListViewItem("aaaaaaaaaa", $LV)
$ListView1_1 = GUICtrlCreateListViewItem("bbbbbbbbbbbb", $LV)
$ListView1_2 = GUICtrlCreateListViewItem("cccccccccccc", $LV)
$ListView1_3 = GUICtrlCreateListViewItem("dddddddddd", $LV)
$ListView1_4 = GUICtrlCreateListViewItem("eeeeeeeeeeeeee", $LV)
$ListView1_5 = GUICtrlCreateListViewItem("ffffffffffffff", $LV)
$ListView1_6 = GUICtrlCreateListViewItem("gggggggggggggg", $LV)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
$text = ""
$Dragging = False
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $GUI_EVENT_PRIMARYDOWN
            ;get info on control the mouse is over
            $Info =  GUIGetCursorInfo (WinGetHandle($Form1))
            If $Info[4] = $LV Then ;if over the Listview
                gettext()             ;get the text of the selected item
                $dragging = True ;and assume we are dragging
            Else                            ;not over the listview
                $Dragging = False
                $text = ''
            EndIf
            
        Case $GUI_EVENT_PRIMARYUP
                        If $dragging And $text <> ""  Then
              $Info =  GUIGetCursorInfo (WinGetHandle($Form1))
              If $Info[4] <> $LV    Then                
                    MouseClick("LEFT")
                    Send($text & "{ENTER}")
              EndIf
            EndIf
            $dragging = False
            $text = ''
            
    EndSwitch
WEnd


Func gettext()
    
    Local $itemIndex = _GUICtrlListViewGetCurSel ($LV)
    $text = _GUICtrlListViewGetItemText($LV, $itemIndex,0)
    
EndFunc
Edited 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.
Posted

Wow, nice solution martin :whistle: ...

This is how it would be much faster and safer (if the text is contain not latinic symbols):

#include <GUIConstants.au3>
#include <guilistview.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Choices Dialog", 353, 256, 303, 219)
GUISetIcon("D:07.ico")
$Edit1 = GUICtrlCreateEdit("", 160, 32, 185, 89)
GUICtrlSetData(-1, "Edit1")
$LV = GUICtrlCreateListView("title", 8, 24, 130, 150)
GUICtrlSendMsg(-1, 0x101E, 0, 100)
$ListView1_0 = GUICtrlCreateListViewItem("текст кириллицы", $LV)
$ListView1_1 = GUICtrlCreateListViewItem("bbbbbbbbbbbb", $LV)
$ListView1_2 = GUICtrlCreateListViewItem("тест", $LV)
$ListView1_3 = GUICtrlCreateListViewItem("dddddddddd", $LV)
$ListView1_4 = GUICtrlCreateListViewItem("eeeeeeeeeeeeee", $LV)
$ListView1_5 = GUICtrlCreateListViewItem("ffffffffffffff", $LV)
$ListView1_6 = GUICtrlCreateListViewItem("gggggggggggggg", $LV)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
$text = ""
$Dragging = False
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $GUI_EVENT_PRIMARYDOWN
            ;get info on control the mouse is over
            $Info =  GUIGetCursorInfo (WinGetHandle($Form1))
            If $Info[4] = $LV Then ;if over the Listview
                gettext()             ;get the text of the selected item
                $dragging = True ;and assume we are dragging
            Else                            ;not over the listview
                $Dragging = False
                $text = ''
            EndIf
        Case $GUI_EVENT_PRIMARYUP
            If $dragging And $text <> ""  Then
              $Info =  GUIGetCursorInfo (WinGetHandle($Form1))
              If $Info[4] <> $LV Then
                    MouseClick("LEFT")
                    $OldClip = ClipGet()
                    ClipPut($text)
                    Send("+{Insert}")
                    ClipPut($OldClip)
                EndIf
            EndIf
            $dragging = False
            $text = ''
    EndSwitch
WEnd

Func gettext()
    Local $itemIndex = _GUICtrlListViewGetCurSel ($LV)
    $text = _GUICtrlListViewGetItemText($LV, $itemIndex,0)
EndFunc

 

  Reveal hidden contents

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Posted

  MsCreatoR said:

Wow, nice solution martin

This is how it would be much faster and safer (if the text is contain not latinic symbols):

Thanks MsCreator.

Good improvement, I've made a copy for my reference.

Interesting you've used Shift Insert. I always use Ctrl V in Windows and I have always used Shift Insert for DOS programs, so I wondered if that's how you came to use it. But I see from your profile that it is unlikely.

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.
  • 2 weeks later...
Posted (edited)

Here is mutch more easyer way:

#include <GUIConstants.au3>
#include <GuiListView.au3>

$Form1 = GUICreate("Choices Dialog", 353, 256, 303, 219)

$Edit1 = GUICtrlCreateEdit("", 160, 32, 185, 89)
GUICtrlSetData(-1, "Edit1")

$LV = GUICtrlCreateListView("Column", 8, 24, 130, 150, $LVS_SHOWSELALWAYS)

$ListView1_0 = GUICtrlCreateListViewItem("текст кириллицы", $LV)
$ListView1_1 = GUICtrlCreateListViewItem("bbbbbbbbbbbb", $LV)
$ListView1_2 = GUICtrlCreateListViewItem("тест", $LV)
$ListView1_3 = GUICtrlCreateListViewItem("dddddddddd", $LV)
$ListView1_4 = GUICtrlCreateListViewItem("eeeeeeeeeeeeee", $LV)
$ListView1_5 = GUICtrlCreateListViewItem("ffffffffffffff", $LV)
$ListView1_6 = GUICtrlCreateListViewItem("gggggggggggggg", $LV)

GUICtrlSendMsg($LV, $LVM_SETCOLUMNWIDTH, 0, -1)

GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $GUI_EVENT_PRIMARYDOWN
            Local $CurInfo = GUIGetCursorInfo($Form1)
            If IsArray($CurInfo) And $CurInfo[4] = $LV Then
                Local $SelText = GetSelectedText($LV)
                While IsArray($CurInfo) And $CurInfo[2] = 1
                    $CurInfo = GUIGetCursorInfo($Form1)
                    Sleep(10)
                WEnd
                If $SelText <> "" And IsArray($CurInfo) And $CurInfo[4] <> $LV Then
                    MouseClick("LEFT")
                    $OldClip = ClipGet()
                    ClipPut($SelText)
                    Send("+{Insert}")
                    ClipPut($OldClip)
                 EndIf
            EndIf
    EndSwitch
WEnd

Func GetSelectedText($ListView)
    Local $ItemIndexArr = _GUICtrlListViewGetSelectedIndices($ListView, 1)
    If Not IsArray($ItemIndexArr) Then Return SetError(1, 0, -1)
    Local $SelText = "", $Ubound = UBound($ItemIndexArr)-1, $CRLF = @CRLF
    
    For $i = 1 To $Ubound
        If $i = $Ubound Then $CRLF = ""
        $SelText &= _GUICtrlListViewGetItemText($ListView, $ItemIndexArr[$i], 0) & $CRLF
    Next
    Return $SelText
EndFunc

EDIT: Now possible to drag & drop more then one item :)

Edited by MsCreatoR

 

  Reveal hidden contents

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Posted

Edited my post, now it's possible to drag & drop more then one item.

 

  Reveal hidden contents

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Posted
  MsCreatoR said:

Edited my post, now it's possible to drag & drop more then one item.

:)
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.

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
  • Recently Browsing   0 members

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