Jump to content
TheDcoder

Ideal way of using @GUI_DragID & @GUI_DropID

Recommended Posts

Hello, I am confused about using these 2 macros

I already have a program with some ListView controls in it... I am thinking about adding drag & drop functionality to them.. but... I can't explain...

Here is my GUI:

#include-once

; -- Created with ISN Form Studio 2 for ISN AutoIt Studio -- ;
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Include <GuiButton.au3>
#include <GuiListView.au3>

Local $hGUI = GUICreate("GUI",350,215,-1,-1,-1,-1)
GUISetBkColor(0xFFFFFF,$hGUI)
Local $hListView = GUICtrlCreatelistview("Column 1|Column 2",5,7,339,169,4,544)
Local $hButtonCopy2 = GUICtrlCreateButton("Copy Column 2",245,180,100,30,-1,-1)
Local $hButtonAdd = GUICtrlCreateButton("Add ListViewItem",110,180,128,30,-1,-1)
Local $hButtonCopy1 = GUICtrlCreateButton("Copy Column 1",4,180,100,30,-1,-1)

GUISetState()

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $hButtonAdd
            GUICtrlCreateListViewItem(InputBox("Enter", "Enter text for column 1") & '|' & InputBox("Enter", "Enter text for column 2"), $hListView)
            
        Case $hButtonCopy1
            $aData = StringSplit(GUICtrlRead(GUICtrlRead($hListView)), '|')
            If IsArray($aData) = 1 Then ClipPut($aData[1]) ; Avoid error
            
        Case $hButtonCopy2
            $aData = StringSplit(GUICtrlRead(GUICtrlRead($hListView)), '|')
            If IsArray($aData) = 1 Then ClipPut($aData[2]) ; Avoid error
            
    EndSwitch
WEnd

 

So, what I need is a good example of using them in a normal my GUI with a ListView control. Thanks in Advance, TD :)

P.S Don't blame for using magic numbers, my GUI designer did it.

Edited by TheDcoder
Added GUI Code

My contributions to the AutoIt Community - ##AutoIt at freenode, real-time chat

3fHNZJ.gif

Spoiler

If I have hurt or offended you in anyway, Please accept my apologies, I never (regardless of the situation) intend to do that to anybody.

Share this post


Link to post
Share on other sites

So you have code, but would rather people create something from scratch? Doesn't really seem fair does it now!


UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Share this post


Link to post
Share on other sites

TheDcoder,

Dragging and dropping inside and between ListViews is not that easy - look in my GUIListViewEx UDF to see how I did it. If you need help to integrate the UDF into your script then do not hesitate to ask.

M23


Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Doesn't really seem fair

​I know but I am busy. Will work on a simple GUI :)


My contributions to the AutoIt Community - ##AutoIt at freenode, real-time chat

3fHNZJ.gif

Spoiler

If I have hurt or offended you in anyway, Please accept my apologies, I never (regardless of the situation) intend to do that to anybody.

Share this post


Link to post
Share on other sites

​I know but I am busy. 

​Who Isn't?! :lol:

 


Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Share this post


Link to post
Share on other sites

Here is a simple example.
 

#include <GUIConstantsEx.au3>

Opt("GUIOnEventMode",1)

$hGUI=GUICreate("test",500,420)


$idListView1=GUICtrlCreateListView("Col1|Col2",10,10,200,150)
GUICtrlCreateListViewItem("1:Row1-Col1|Row1-Col2",$idListView1)
GUICtrlCreateListViewItem("1:Row2-Col1|Row2-Col2",$idListView1)

$idListView2=GUICtrlCreateListView("Col1|Col2",220,10,200,150)
GUICtrlCreateListViewItem("2:Row1-Col1|Row1-Col2",$idListView2)
GUICtrlCreateListViewItem("2:Row2-Col1|Row2-Col2",$idListView2)

$idListView3=GUICtrlCreateListView("Col1|Col2",10,170,200,150)
GUICtrlSetState(-1,$GUI_DROPACCEPTED)

$idListView4=GUICtrlCreateListView("Col1|Col2",220,170,200,150)
GUICtrlSetState(-1,$GUI_DROPACCEPTED)

GUISetOnEvent($GUI_EVENT_CLOSE,"Close")
GUISetOnEvent($GUI_EVENT_DROPPED,"DragDrop")

GUISetState()

While 1
    Sleep(10)
WEnd


Func Close()
    Exit
EndFunc

Func DragDrop()
    ConsoleWrite("DragID=" & @GUI_DragId & @CRLF)
    GUICtrlCreateListViewItem(GUICtrlRead(GUICtrlRead(@GUI_DragId)),@GUI_DropId)
EndFunc

 

Share this post


Link to post
Share on other sites

@ahmet Thanks for the nice example but,

So, what I need is a good example of using them in my GUI

​Ok :)?


My contributions to the AutoIt Community - ##AutoIt at freenode, real-time chat

3fHNZJ.gif

Spoiler

If I have hurt or offended you in anyway, Please accept my apologies, I never (regardless of the situation) intend to do that to anybody.

Share this post


Link to post
Share on other sites

Do you actually want to copy item into the same listview?

Edited by ahmet

Share this post


Link to post
Share on other sites

@ahmet I think you have misunderstood, The code is just a decoy. I wanted to know the ideal way of implementation of D&D in a already complete script :)


My contributions to the AutoIt Community - ##AutoIt at freenode, real-time chat

3fHNZJ.gif

Spoiler

If I have hurt or offended you in anyway, Please accept my apologies, I never (regardless of the situation) intend to do that to anybody.

Share this post


Link to post
Share on other sites

Hello, I found the Ideal way (IMHO) to make your (existing) GUI Drag & Drop friendly...

All you need is:

Case $GUI_EVENT_DROPPED ; This will go in your GUI loop
    Drag_N_DropManager(@GUI_DropId, @GUI_DragFile)





Func Drag_N_DropManager($hDropID, $sDropFile) ; Your D&D Manager
    ; Modify as required
EndFunc

So implementing this method in my GUI would result in:

#include-once

; -- Created with ISN Form Studio 2 for ISN AutoIt Studio -- ;
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Include <GuiButton.au3>
#include <GuiListView.au3>

Local $hGUI = GUICreate("GUI", 350, 215, -1, -1, -1, $WS_EX_ACCEPTFILES)
GUISetBkColor(0xFFFFFF,$hGUI)
Local $hListView = GUICtrlCreatelistview("Column 1|Column 2",5,7,339,169,4,544)
GUICtrlSetState(-1, $GUI_DROPACCEPTED)
Local $hButtonCopy2 = GUICtrlCreateButton("Copy Column 2",245,180,100,30,-1,-1)
Local $hButtonAdd = GUICtrlCreateButton("Add ListViewItem",110,180,128,30,-1,-1)
Local $hButtonCopy1 = GUICtrlCreateButton("Copy Column 1",4,180,100,30,-1,-1)

GUISetState()

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

        Case $hButtonAdd
            GUICtrlCreateListViewItem(InputBox("Enter", "Enter text for column 1") & '|' & InputBox("Enter", "Enter text for column 2"), $hListView)

        Case $hButtonCopy1
            $aData = StringSplit(GUICtrlRead(GUICtrlRead($hListView)), '|')
            If IsArray($aData) = 1 Then ClipPut($aData[1]) ; Avoid error

        Case $hButtonCopy2
            $aData = StringSplit(GUICtrlRead(GUICtrlRead($hListView)), '|')
            If IsArray($aData) = 1 Then ClipPut($aData[2]) ; Avoid error

        Case $GUI_EVENT_DROPPED
            Drag_N_DropManager(@GUI_DropId, @GUI_DragFile)

    EndSwitch
WEnd

Func Drag_N_DropManager($hDropID, $sDropFile)
    GUICtrlCreateListViewItem(FileRead(FileOpen($sDropFile)), $hListView)

EndFunc

 

Thanks @ahmet for the Idea :thumbsup:. Hope it may help you, TD :)


My contributions to the AutoIt Community - ##AutoIt at freenode, real-time chat

3fHNZJ.gif

Spoiler

If I have hurt or offended you in anyway, Please accept my apologies, I never (regardless of the situation) intend to do that to anybody.

Share this post


Link to post
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

×
×
  • Create New...