Sign in to follow this  
Followers 0
Rozek

dragging files onto a Pic control - possible?

3 posts in this topic

Hello!

I know, that it is possible to drag one or multiple files, e.g., from the windows file manager onto an edit control within an AutoIt application (and successfully use that functionality already). But is it also possible to drag them onto another control such as a pic control? Or can those controls only "accept" other AutoIt objects?

Thanks in advance for your effort!

Kind regards,

Andreas Rozek

Share this post


Link to post
Share on other sites



Hi,

Yep it is possible.. Long winded example as I had it handy at the time.

Drop some files.. if any of the files dropped are pictures click on one of them and the drop image will be set with it.

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

;~ #NoTrayIcon

Global $WM_DROPFILES = 0x233
Global $gaDropFiles[1] 
Global $State = 0, $OldPosX, $OldPosY

$GUI = GUICreate("Drop Files", 76, 71, @DesktopWidth - "160", @DesktopHeight - "300", -1 _
                                                                                    , $WS_EX_ACCEPTFILES _
                                                                                    + $WS_EX_TOPMOST _
                                                                                    + $WS_EX_TOOLWINDOW)
$PIC = GUICtrlCreatePic (@WindowsDir & "\Rhododendron.bmp", -1, -1, 77, 72, $GUI_SS_DEFAULT_PIC _
                                                                                , $GUI_WS_EX_PARENTDRAG)
GUICtrlSetState ($PIC, $GUI_DROPACCEPTED)
GUICtrlSetTip($PIC, @WindowsDir & "\Rhododendron.bmp")
GUISetState(@SW_SHOW, $GUI)

$GUIFileList = GUICreate("", 300, 200, @DesktopWidth - 460, @DesktopHeight - 300, $WS_POPUP _
                                                                                    , $WS_EX_TOPMOST  _
                                                                                    + $WS_EX_TOOLWINDOW, $GUI)
$ListBox = GUICtrlCreateList("", 10, 10, 280, 160, BitOR($WS_BORDER, $WS_VSCROLL, $LBS_NOTIFY, $WS_HSCROLL))
GUICtrlSetLimit(-1, 600)
$FilterCheckBox = GUICtrlCreateCheckbox("Filter (*.bmp;*.jpg;*.gif) only.", 10, 170, 170, 20)
$ClearButton = GUICtrlCreateButton("Clear", 180, 170, 50, 20)
$DoneButton = GUICtrlCreateButton("Done", 240, 170, 50, 20)
GUISetState(@SW_HIDE, $GUIFileList)

GUIRegisterMsg ($WM_DROPFILES, "WM_DROPFILES_FUNC")

While 1
    $msg = GUIgetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            Exit
        Case $msg = $GUI_EVENT_DROPPED
            If $State = 0 Then
                $State = 1
                GUISetState(@SW_SHOW, $GUIFileList)
            EndIf   
            For $i = 0 To UBound($gaDropFiles) - 1
                If GUICtrlRead($FilterCheckBox) = $GUI_CHECKED Then
                    If StringRight($gaDropFiles[$i], 4) = _DropFilter(StringRight($gaDropFiles[$i], 4)) Then
                        GUICtrlSetData($ListBox, $gaDropFiles[$i])
                    EndIf
                ElseIf GUICtrlRead($FilterCheckBox) = $GUI_UNCHECKED Then
                    GUICtrlSetData($ListBox, $gaDropFiles[$i])
                EndIf   
            Next    
        Case $msg = $ListBox
            If StringRight(GuiCtrlRead($ListBox), 4) = _DropFilter(StringRight(GuiCtrlRead($ListBox), 4)) Then
                GUICtrlSetImage($PIC, GuiCtrlRead($ListBox))
                GUICtrlSetTip($PIC, GuiCtrlRead($ListBox))
            EndIf   
        Case $msg = $FilterCheckBox
            If GUICtrlRead($FilterCheckBox) = $GUI_CHECKED Then
                Local $sTemp = ''
                If _GUICtrlListCount($ListBox) <> 0 And _GUICtrlListCount($ListBox) <> $LB_ERR Then
                    For $c = 0 To _GUICtrlListCount($ListBox)
                        If StringRight(_GUICtrlListGetText($ListBox, $c), 4) = _DropFilter(StringRight(_GUICtrlListGetText($ListBox, $c), 4)) Then
                            $sTemp &= "|" & _GUICtrlListGetText($ListBox, $c) 
                        EndIf
                    Next
                    If $sTemp <> '' Then 
                        Dim $Valid = StringSplit(StringTrimLeft($sTemp, 1), "|")
                        GUICtrlSetData($ListBox, "")
                        For $add = 1 To $Valid[0]   
                            GUICtrlSetData($ListBox, $Valid[$add])
                        Next
                    EndIf   
                EndIf
            EndIf   
        Case $msg = $ClearButton
            GUICtrlSetData($ListBox, "")
        Case $msg = $DoneButton
            $State = 0
            GuiSetState(@SW_HIDE, $GUIFileList)
    Endselect
    Dock()  
Wend

Func Dock()
    $WGP = WinGetPos($GUI, "")
    If $WGP[0] <> $OldPosX Or $WGP[1] <> $OldPosY Then
        WinMove($GUIFileList, "", $WGP[0] - 300, $WGP[1])
        $OldPosX = $WGP[0]
        $OldPosY = $WGP[1]
    EndIf   
EndFunc

Func WM_DROPFILES_FUNC($hWnd, $msgID, $wParam, $lParam)
    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

Func _DropFilter($dFile)
    Dim $dFilter = StringSplit(".jpg|.bmp|.gif", "|")
    For $i = 1 To $dFilter[0]
        If $dFilter[$i] = $dFile Then Return $dFile
    Next
    Return ""   
EndFunc

Cheers

Share this post


Link to post
Share on other sites

Incredible!

I sometimes think that there is nothing which cannot be done with AutoIt (although you might have to know the proper API calls)

Thanks for your example - I had to modify it a bit, but now it's running on my machine!

Kind regards,

Andreas Rozek

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
Sign in to follow this  
Followers 0