Sign in to follow this  
Followers 0
Lupo73

Drop file on png target image

1 post in this topic

I have created a software (DropIt) that allows to move files using pattern rules.

The program use a target image and users can drop file onto it, to process them. Actually the software use gif images, but I'd like to substitute them with png images. I tried to modify my code, but it doesn't work fine. (I write only part of the code, given that is too long.. I'll write other parts if needed). Can you help me? Thanks!

Func WM_DROPFILES_UNICODE_FUNC($hWnd, $msgID, $wParam, $lParam)
    Local $nSize, $pFileName
    Local $nAmt = DllCall("shell32.dll", "int", "DragQueryFileW", "hwnd", $wParam, "int", 0xFFFFFFFF, "ptr", 0, "int", 255)
    For $i = 0 To $nAmt[0] - 1
        $nSize = DllCall("shell32.dll", "int", "DragQueryFileW", "hwnd", $wParam, "int", $i, "ptr", 0, "int", 0)
        $nSize = $nSize[0] + 1
        $pFileName = DllStructCreate("wchar[" & $nSize & "]")
        DllCall("shell32.dll", "int", "DragQueryFileW", "hwnd", $wParam, "int", $i, "int", DllStructGetPtr($pFileName), "int", $nSize)
        ReDim $gaDropFiles[$i + 1]
        $gaDropFiles[$i] = DllStructGetData($pFileName, 1)
        $pFileName = 0
    Next
EndFunc


Func WM_SYSCOMMAND($hWnd, $Msg, $wParam, $lParam)
    If IniRead($sIni, "General", "LockPos", "True") = "True" Then
        If BitAND($wParam, 0x0000FFF0) = $SC_MOVE Then Return False
    EndIf
    Return 'GUI_RUNDEFMSG'
EndFunc


Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
    Local $tNMITEMACTIVATE = DllStructCreate($tagNMITEMACTIVATE, $lParam)
    Local $hWndFrom = DllStructGetData($tNMITEMACTIVATE, 'hWndFrom')
    Local $Index = DllStructGetData($tNMITEMACTIVATE, 'Index')
    Local $Code = DllStructGetData($tNMITEMACTIVATE, 'Code')
    Switch $hWndFrom
        Case $hListView
            Switch $Code
                Case $NM_RCLICK
                    GUICtrlSendToDummy($Dummy, $Index)
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc


Func MY_WM_PAINT($hWnd, $Msg, $wParam, $lParam)
    _WinAPI_RedrawWindow($hGUI1, 0, 0, $RDW_UPDATENOW)
    _GDIPlus_GraphicsDrawImage($hGraphic, $hImage, 0, 0)
    _WinAPI_RedrawWindow($hGUI1, 0, 0, $RDW_VALIDATE)
    Return $GUI_RUNDEFMSG
EndFunc


Func _Main()
    Local $icon, $menu, $nMsg, $x, $y, $dim, $gif, $pos, $j, $func1, $func3, $func2, $func4, $func5, $func6, $list, $custom, $prof[16], $profiles[16]
    
    ; Creation of INI files
    If Not FileExists($sIni) Then
        $sData = "Profile=Default" & @LF & "PosX=-1" & @LF & "PosY=-1" & @LF & "LockPos=False" & @LF & "OnTop=True" & @LF & "SizeX=64" & @LF & "SizeY=64" & @LF & "NoAsk=False" & @LF & "Duplicates=Overwrite" & @LF & "Mode=Move" & @LF & "AskMode=False" & @LF & "AskForFolders=False"
        IniWriteSection($sIni, "General", $sData)
    EndIf
    $sData = IniRead($sIni, "General", "Profile", "")
    If $sData = "" Then
        $sData = "Default"
        IniWrite($sIni, "General", "Profile", $sData)
    EndIf
    $sIniPr = $PrDir & "\" & $sData & ".ini"
    If Not FileExists($PrDir) Then DirCreate($PrDir)
    $temp = IniReadSection($sIni, "Patterns")
    If @error Then
        If Not FileExists($sIniPr) Then
            ; create the default profile
            IniWriteSection($sIniPr, "Target", "Image=" & $ImDef)
            IniWriteSection($sIniPr, "Patterns", "")
        EndIf
    Else
        ; restore patterns from an old DropIt version
        IniWriteSection($sIniPr, "Patterns", $temp)
        IniDelete($sIni, "Patterns")
    EndIf
    $sIm = IniRead($sIniPr, "Target", "Image", "")
    If $sIm = "" Then $sIm = $ImDef
    $sIm = $ImDir & "\" & $sIm
    If FileExists($sIm) Then
        $list = ProcessList(@ScriptName)
        If $list[0][0] > 1 Then Exit
    Else
        MsgBox(0, "Image not found", 'Software image not found. You need to have a "img\' & $ImDef & '" image, to popup it as drop target.')
        Exit
    EndIf
    
    $x = IniRead($sIni, "General", "PosX", "-1")
    $y = IniRead($sIni, "General", "PosY", "-1")
    $hGUI1 = GUICreate($sName, $xD, $yD, $x, $y, $WS_POPUP, BitOR($WS_EX_ACCEPTFILES, $WS_EX_LAYERED, $WS_EX_TOOLWINDOW, $WS_EX_TOPMOST))
    
    ; Load PNG image
    _GDIPlus_StartUp()
    $hImage = _GDIPlus_ImageLoadFromFile($sIm)
    $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI1)
    GUIRegisterMsg($WM_PAINT, "MY_WM_PAINT")
    
    ;$icon = GUICtrlCreatePic($sIm, 0, 0, $xD, $yD, $SS_NOTIFY, $GUI_WS_EX_PARENTDRAG)
    GUICtrlSetState($hGraphic, $GUI_DROPACCEPTED)
    GUICtrlSetTip($hGraphic, $ii)
    $profiles = ListProfiles()
    
    ; Background mode
    If $CmdLine[0] > 0 Then
        If FileExists($CmdLine[1]) Then
            GUISetState(@SW_HIDE, $hGUI1)
            ReDim $gaDropFiles[$CmdLine[0]]
            For $j = 1 To $CmdLine[0]
                $gaDropFiles[$j - 1] = $CmdLine[$j]
            Next
            DropEvent()
            Exit
        Else
            $sData = StringTrimLeft($CmdLine[1], 1)
            If StringLeft($CmdLine[1], 1) = "-" And FileExists($PrDir & "\" & $sData & ".ini") Then
                IniWrite($sIni, "General", "Profile", $sData)
                $sIniPr = $PrDir & "\" & $sData & ".ini"
            Else
                MsgBox(0, "Invalid Command", "You have run " & $sName & " with an invalid command." & @LF & "It will be normally started.")
            EndIf
        EndIf
    EndIf
    
    ; Context menu
    $menu = GUICtrlCreateContextMenu($hGraphic)
    $func1 = GUICtrlCreateMenuItem("Manage", $menu, 0)
    GUICtrlCreateMenuItem("", $menu, 1)
    $func2 = GUICtrlCreateMenu("Profiles", $menu, 2)
    $func3 = GUICtrlCreateMenuItem("Options", $menu, 3)
    $func4 = GUICtrlCreateMenuItem("Hide", $menu, 4)
    $func5 = GUICtrlCreateMenuItem("About...", $menu, 5)
    GUICtrlCreateMenuItem("", $menu, 6)
    $func6 = GUICtrlCreateMenuItem("Exit", $menu, 7)
    $custom = GUICtrlCreateMenuItem("Customize", $func2)
    GUICtrlCreateMenuItem("", $func2)
    For $i = 1 To $profiles[0]
        $prof[$i] = GUICtrlCreateMenuItem($profiles[$i], $func2, $i+1, 1)
        If $profiles[$i] = IniRead($sIni, "General", "Profile", "Default") Then GUICtrlSetState($prof[$i], $GUI_CHECKED)
    Next
    
    GUIRegisterMsg($WM_DROPFILES, "WM_DROPFILES_UNICODE_FUNC")
    GUIRegisterMsg($WM_SYSCOMMAND, "WM_SYSCOMMAND")
    GUISetState(@SW_SHOW, $hGUI1)
    
    $pos = WinGetPos($hGUI1)
    $hGUI2 = GUICreate("Positioning", 16, 16, $pos[0]+7, $pos[1]+7, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_TOPMOST), $hGUI1)
    $gif = GUICtrlCreatePic($sPic, 0, 0, 16, 16, $SS_NOTIFY, $GUI_WS_EX_PARENTDRAG)
    GUIRegisterMsg($WM_ENTERSIZEMOVE, "SetRelPos")
    GUIRegisterMsg($WM_MOVE, "FollowMe")
    GUISetState(@SW_HIDE, $hGUI2)
    
    $top = IniRead($sIni, "General", "OnTop", "True")
    If $top = "True" Then
        WinSetOnTop($hGUI1, "", 1)
    Else
        WinSetOnTop($hGUI1, "", 0)
    EndIf
    
    While 1
        $nMsg = GUIGetMsg()
        Select
            Case $nMsg = $GUI_EVENT_DROPPED
                GUISetState(@SW_SHOW, $hGUI2)
                DropEvent()
                GUISetState(@SW_HIDE, $hGUI2)
                
            Case $nMsg = $func1
                GUICtrlSetState($icon, $GUI_DISABLE)
                Manage()
                GUICtrlSetState($icon, $GUI_ENABLE)
            
            Case $nMsg = $custom
                GUICtrlSetState($icon, $GUI_DISABLE)
                $profiles = Customize($profiles)
                GUICtrlSetState($icon, $GUI_ENABLE)
                GUICtrlDelete($func2)
                ; Recreate submenu
                $func2 = GUICtrlCreateMenu("Profiles", $menu, 2)
                $custom = GUICtrlCreateMenuItem("Customize", $func2)
                GUICtrlCreateMenuItem("", $func2)
                For $i = 1 To $profiles[0]
                    $prof[$i] = GUICtrlCreateMenuItem($profiles[$i], $func2, $i+1, 1)
                    If $profiles[$i] = IniRead($sIni, "General", "Profile", "Default") Then
                        GUICtrlSetState($prof[$i], $GUI_CHECKED)
                        $sIm = IniRead($PrDir & "\" & $profiles[$i] & ".ini", "Target", "Image", "")
                        If $sIm = "" Then $sIm = $ImDef
                        $sIm = $ImDir & "\" & $sIm
                        GUICtrlSetImage($icon, $sIm)
                    EndIf
                Next
                
            Case $nMsg >= $prof[1] And $nMsg <= $prof[$profiles[0]]
                For $i = 1 To $profiles[0]
                    If $nMsg = $prof[$i] Then
                        IniWrite($sIni, "General", "Profile", $profiles[$i])
                        $sIniPr = $PrDir & "\" & $profiles[$i] & ".ini"
                    EndIf
                Next
                
            Case $nMsg = $func3
                GUICtrlSetState($icon, $GUI_DISABLE)
                Options()
                GUICtrlSetState($icon, $GUI_ENABLE)
                
            Case $nMsg = $func4
                MyTrayMenu()
                
            Case $nMsg = $func5
                MsgBox(0x40040, "About", "      " & $sName & $sVer & @LF & @LF & "Software developed by Lupo PenSuite Team." & @LF & "Released under Open Source GPL.")
                
            Case $nMsg = $func6
                ExitLoop
                
            Case $nMsg = $GUI_EVENT_CLOSE
                ExitLoop
                
        EndSelect
    WEnd
    ExitEvent()
EndFunc

SFTPEx, AutoCompleteInput_DateTimeStandard(), _ImageWriteResize()_GUIGraduallyHide(): some AutoIt functions.

Lupo PenSuite: all-in-one and completely free selection of portable programs and games.

DropIt: a personal assistant to automatically manage your files.

ArcThemALL!: application to multi-archive your files and folders.

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