Jump to content

Recommended Posts

Posted (edited)

In the example below I am dropping multiple files on a ListView using _GUICtrlListView_Create() but for some reason even though the function WM_DROPFILES responds in the Console, it doesn't add the files to the ListView. But when using the in-built GUICtrlCreateListView, it works as it should. Normally when adding single files I use something like the Melba23 example. Because I like to use the ListView UDF I am hoping there is a work around? Thanks

Example taken and modified from: Here

; *** Start added by AutoIt3Wrapper ***
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
; *** End added by AutoIt3Wrapper ***
#AutoIt3Wrapper_Add_Constants=n
;***************************************************
; by Lazycat
;***************************************************
#include <GUIConstants.au3>
#include <GuiListView.au3>

Global $WM_DROPFILES = 0x233
Global $gaDropFiles[1], $str = ""

$hGUI = GUICreate("Test", 400, 200, 219, 178, -1, BitOR($WS_EX_ACCEPTFILES, $WS_EX_TOPMOST))
;$hEdit = GUICtrlCreateEdit("", 5, 5, 390, 190)
;$hEdit = _GUICtrlListView_Create($hGUI, "", 5, 5, 390, 190) ;UnComment
$hEdit = GUICtrlCreateListView("", 5, 5, 390, 190) ;Comment
GUICtrlSetState(-1, $GUI_DROPACCEPTED)
_GUICtrlListView_InsertColumn($hEdit, 0, "File Name", 120)
GUISetState(@SW_SHOW)

GUIRegisterMsg($WM_DROPFILES, "WM_DROPFILES_FUNC")
_GUICtrlListView_AddItem($hEdit, "First_Line")
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $GUI_EVENT_DROPPED
            $str = ""
            For $i = 0 To UBound($gaDropFiles) - 1
                _GUICtrlListView_AddItem($hEdit, $gaDropFiles[$i])
            Next
    EndSwitch
WEnd

Func WM_DROPFILES_FUNC($hWnd, $msgID, $wParam, $lParam)
    ConsoleWrite("aaaaaaaaaa" & @CRLF)
    Local $nSize, $pFileName
    Local $nAmt = DllCall("shell32.dll", "int", "DragQueryFile", "hwnd", $wParam, "int", 0xFFFFFFFF, "ptr", 0, "int", 255)
    For $i = 0 To $nAmt[0] - 1
        $nSize = DllCall("shell32.dll", "int", "DragQueryFile", "hwnd", $wParam, "int", $i, "ptr", 0, "int", 0)
        $nSize = $nSize[0] + 1
        $pFileName = DllStructCreate("char[" & $nSize & "]")
        DllCall("shell32.dll", "int", "DragQueryFile", "hwnd", $wParam, "int", $i, "ptr", DllStructGetPtr($pFileName), "int", $nSize)
        ReDim $gaDropFiles[$i + 1]
        $gaDropFiles[$i] = DllStructGetData($pFileName, 1)
        $pFileName = 0
    Next
EndFunc   ;==>WM_DROPFILES_FUNC
Edited by guinness

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

Posted (edited)

Learned something useful from this one: MSDN lies! :(

PostMessage(

(HWND) hWndControl, // handle to destination control

(UINT) WM_DROPFILES, // message ID

(WPARAM) wParam, // = (WPARAM) (HDROP) hDrop;

(LPARAM) lParam // = 0; not used, must be zero

);

The $hWnd parameter in WM_DROPFILES is the handle of the WINDOW, not the CONTROL. To ID the control, you have to get the X/Y coordinates with DragQueryPoint, and then check which control it was by POS. Note this demo has both a native and UDF listview, and they both work:
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>

Global Const $WM_DROPFILES = 0x0233
Global $hGUI, $hLV_1, $hLV_2, $idLV_2

$hGUI = GUICreate("Test", 400, 400, 219, 178, -1, BitOR($WS_EX_ACCEPTFILES, $WS_EX_TOPMOST))
ConsoleWrite("$hGUI = " & $hGUI & @LF)
$hLV_1 = _GUICtrlListView_Create($hGUI, "", 5, 5, 390, 190)
ConsoleWrite("$hLV_1 = " & $hLV_1 & @LF)
_GUICtrlListView_InsertColumn($hLV_1, 0, "LV1: File Name", 120)

$idLV_2 = GUICtrlCreateListView("", 5, 200, 390, 190)
$hLV_2 = ControlGetHandle($hGUI, "", $idLV_2)
ConsoleWrite("$hLV_2 = " & $hLV_2 & @LF)
_GUICtrlListView_InsertColumn($hLV_2, 0, "LV2: File Name", 120)

GUIRegisterMsg($WM_DROPFILES, "WM_DROPFILES_FUNC")
GUISetState(@SW_SHOW)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Func WM_DROPFILES_FUNC($hWnd, $msgID, $wParam, $lParam)
    ConsoleWrite("WM_DROPFILES_FUNC:  $hWnd = " & $hWnd & @LF)
    Switch $hWnd
        Case $hGUI ; Our GUI
            Local Const $tagPOINT = "int X;int Y"
            Local $tPOINT = DllStructCreate($tagPOINT), $iX, $iY
            Local $aRET, $hCtrl, $nSize, $tFileName

            ; Get X/Y coord dropped to
            $aRET = DllCall("shell32.dll", "int", "DragQueryPoint", "hwnd", $wParam, "ptr", DllStructGetPtr($tPOINT))
            $iX = DllStructGetData($tPOINT, "X")
            $iY = DllStructGetData($tPOINT, "Y")
            $hCtrl = _GetCtrlHandleFromPoint($iX, $iY)
            ConsoleWrite("$iX = " & $iX & "; $iY = " & $iY & "; $hCtrl = " & $hCtrl & @LF)

            Switch $hCtrl
                Case $hLV_1, $hLV_2
                    ; Get count of files dropped
                    $aRET = DllCall("shell32.dll", "int", "DragQueryFile", "hwnd", $wParam, "int", 0xFFFFFFFF, "ptr", 0, "int", 255)
                    For $i = 0 To $aRET[0] - 1
                        $nSize = DllCall("shell32.dll", "int", "DragQueryFile", "hwnd", $wParam, "int", $i, "ptr", 0, "int", 0)
                        $nSize = $nSize[0] + 1
                        $tFileName = DllStructCreate("char[" & $nSize & "]")
                        DllCall("shell32.dll", "int", "DragQueryFile", "hwnd", $wParam, "int", $i, "ptr", DllStructGetPtr($tFileName), "int", $nSize)
                        _GUICtrlListView_AddItem($hCtrl, DllStructGetData($tFileName, 1))
                        $tFileName = 0
                    Next
                    Return 0 ; End processing only for our LVs
            EndSwitch
    EndSwitch
EndFunc   ;==>WM_DROPFILES_FUNC

Func _GetCtrlHandleFromPoint($iX, $iY)
    $aLV_Pos = ControlGetPos($hGUI, "", $hLV_1)
    If ($iX >= $aLV_Pos[0]) And ($iX <= $aLV_Pos[0] + $aLV_Pos[2]) And ($iY >= $aLV_Pos[1]) And ($iY <= $aLV_Pos[1] + $aLV_Pos[3]) Then
        Return $hLV_1
    Else
        $aLV_Pos = ControlGetPos($hGUI, "", $hLV_2)
        If ($iX >= $aLV_Pos[0]) And ($iX <= $aLV_Pos[0] + $aLV_Pos[2]) And ($iY >= $aLV_Pos[1]) And ($iY <= $aLV_Pos[1] + $aLV_Pos[3]) Then
            Return $hLV_2
        Else
            Return 0
        EndIf
    EndIf
EndFunc   ;==>_GetCtrlHandleFromPoint

:mellow:

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Posted (edited)

TESTED: Works :mellow:

Thanks for that. I did search the forum (scouts honour) but couldn't find anything on the subject. Just goes to show you AutoIt MVPs know what you're doing.

I try not to post answers that can easily be found by the search tool.

Edited by guinness

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

Posted

While this is good information, I think the error in your original code (and your learning opportunity) was not pointed out clearly. When using UDF created controls, internal AutoIt things that you would normally take advantage of (like $GUI_EVENT_DROPPED) do NOT work. The problem with your code was that you didn't have code to add items to your listview in your WM_DROPFILES function. PsaltyDS fixed that, but didn't clearly point out that's WHY your problem was fixed. If you parse the array in your original code you'll see that indeed you do have all the information you require.

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