Jump to content

Drag and Drop - the other way around


Recommended Posts

  • Replies 94
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Posted Images

After taking a look at this, I was wondering if their struct is better. Thoughts?

http://www.vbforums.com/showpost.php?p=110...amp;postcount=4

I also found this extremely interesting:

http://www.laser.ru/evgen/articles/ARTofOS2/aos2p_20.html

Maybe but that guy isn't sure about some things that I am sure about so at the moment I have more confidence in the Delphi source you found and the msdn info I read. Also, I have thought about it again and I have realised that the error was due to the fact that I calculated the offset for the file list by using the size of a struct (dummy) which had the same elements except the file strings. This was a mistake because the size of a struct is rounded up to a multiple of 8 bytes and that is the reason for my error. So I am now going to change my last post. The function I posted is ok but I am going to set the boolean elements back to bytes because I think bool is a byte unless someone can tell me otherwise.

EDIT:

I'll look at your second link later. It does look like it could be interesting.

EDIT2: Second thoughts I'm going to ignore it because it is about OS2 and there is nothing to say that it is the applicable to Windows

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.
Link to comment
Share on other sites

Well, I've figured out how to send files to explorer and the desktop!

#include <Misc.au3>
#include <WinAPI.au3>
#include <Memory.au3>

Func DoDropFiles($wnd, $Files)
    Local $tagStruct1, $dummy, $hGlobal, $pDropFiles, $DropFiles, $Size
    ;$wnd is the handle of the control we are dropping onto
    ;$Files is the list of files separated by "|"
    $tagStruct1 = "int offset;int px;int py;wchar fNC;wchar fWide"
    $dummy = DllStructCreate($tagStruct1)

    ;grab some memory
    $hGlobal = _MemGlobalAlloc(DllStructGetSize($dummy) + StringLen($Files) + 2)
    ;DropFiles := GlobalLock(MemHandle)
    ;translates the memory handle to a pointer
    $pDropFiles = _MemGlobalLock($hGlobal)
    ;create the struct in this memory
    $DropFiles = DllStructCreate($tagStruct1 & ";char  filelist[" & StringLen($Files) + 2 & "]", $pDropFiles)
    DllStructSetData($DropFiles, "offset", DllStructGetSize($dummy))
    $dummy = 0; done its job
    DllStructSetData($DropFiles, "px", 0);tried setting a point inside Notepad
    DllStructSetData($DropFiles, "py", 0);but it makes no difference
    DllStructSetData($DropFiles, "fwide", 0)
    DllStructSetData($DropFiles, "fNC", 0)
    DllStructSetData($DropFiles, "filelist", $Files)
    ;set the nulls in place of the separaters
    $Size = 0;
    $Files = StringSplit($Files, "|")
    For $I = 1 To $Files[0]

        ;// number of characters per string (as ANSI) plus one #0 terminator
        ;Inc(Size, Length(Files[I]) + 1);
        $Size += StringLen($Files[$I]) + 1
        DllStructSetData($DropFiles, "filelist", 0, $Size)
    Next
    ConsoleWrite(DllStructGetData($DropFiles, "filelist") & @CRLF)
    ;now add the extra null to terminate the list of strings
    DllStructSetData($DropFiles, "filelist", 0, $Size + 1)
    _MemGlobalUnlock($hGlobal)
    _WinAPI_PostMessage($wnd, $WM_DROPFILES, $hGlobal, 0);
    ;// ... and finally release the memory

    _MemGlobalFree($hGlobal)
EndFunc   ;==>DoDropFiles

Func _IsMouseInWindow()
    Local $MouseX, $MouseY, $mousePos
    $mousePos = GUIGetCursorInfo()
    $MouseX = $mousePos[0] ;X Axis info from getcursorinfo()
    $MouseY = $mousePos[1] ;Y Axis info from getcursorinfo()

    ;Does the Mouse's X or Y Extend the window?
    If ($MouseX < -3 Or $MouseX > $GUI_WIDTH + 2 Or $MouseY < -29 Or $MouseY > $GUI_HEIGHT + 2) Then
        ;The mouse is not in the window, return false
        Return False
    Else
        ;Yes, the mouse is in the window, return true
        Return True
    EndIf
EndFunc   ;==>_IsMouseInWindow

Func _WinInfoFromPoint($nX, $nY);by Saio
    Local $tStrBuff, $pStrBuff, $aRet, $hWnd, $hOwnerWnd, $sClassName, $sOwnerClass, $sWinText
    $tStrBuff = DllStructCreate("char[100]")
    $pStrBuff = DllStructGetPtr($tStrBuff)
    $aRet = DllCall("user32.dll", "hwnd", "WindowFromPoint", "uint", $nX, "uint", $nY)
    $hWnd = $aRet[0]
    $aRet = DllCall("user32.dll", "int", "GetClassName", "hwnd", $hWnd, "ptr", $pStrBuff, "int", 100)
    $sClassName = DllStructGetData($tStrBuff, 1)
    DllStructSetData($tStrBuff, 1, "")
    DllCall("user32.dll", "int", "GetWindowText", "hwnd", $hWnd, "ptr", $pStrBuff, "int", 100)
;~  DllCall("user32.dll", "int", "SendMessage", "hwnd", $hWnd, "uint", $WM_GETTEXT, "uint", 100, "ptr", $pStrBuff)
    $sWinText = DllStructGetData($tStrBuff, 1)
    DllStructSetData($tStrBuff, 1, "")
    $aRet = DllCall("user32.dll", "hwnd", "GetAncestor", "hwnd", $hWnd, "uint", 2);$GA_ROOT = 2
    $hOwnerWnd = $aRet[0]
    $aRet = DllCall("user32.dll", "int", "GetClassName", "hwnd", $hOwnerWnd, "ptr", $pStrBuff, "int", 100)
    $sOwnerClass = DllStructGetData($tStrBuff, 1)
    DllStructSetData($tStrBuff, 1, "")

    Local $Array[5] = [$sWinText, $sClassName, $hWnd, $sOwnerClass, $hOwnerWnd]

    ;Window Text: $sWinText | $Array[0]
    ;ClassName: $sClassName | $Array[1]
    ;Window Handle: $hWnd | $Array[2]
    ;Owner ClassName: $sOwnerClass | $Array[3]
    ;Owner Handle: $hOwnerWnd | $Array[4]

    ConsoleWrite(@CRLF & "{ WinInfo }" & @CRLF)
    ConsoleWrite("Window Text: " & $sWinText & @CRLF)
    ConsoleWrite("ClassName: " & $sClassName & @CRLF)
    ConsoleWrite("Window Handle: " & $hWnd & @CRLF)
    ConsoleWrite("Owner ClassName: " & $sOwnerClass & @CRLF)
    ConsoleWrite("Owner Handle: " & $hOwnerWnd & @CRLF)
    ConsoleWrite("{ WinInfo }" & @CRLF & @CRLF)

    Return $Array

EndFunc   ;==>_WinInfoFromPoint

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $GUI_EVENT_DROPPED
            $File = @GUI_DragFile
            If StringRegExp($File, "^.+\.(?i)((TTF)|(OTF))$") Then
                MsgBox(0, "", $File & @CRLF & "Is a font file.")
            Else
                MsgBox(0, "", $File & @CRLF & "Is an invalid file type.")
            EndIf
        Case $Pic2
            $startChecking = True
    EndSwitch

    If $startChecking Then
        $cInfo = GUIGetCursorInfo()
        If $cInfo[2] = 0 Then
            ;Left Mouse Key Up
            If _IsMouseInWindow() = False Then
                $mousePos = MouseGetPos()
                $wInfo = _WinInfoFromPoint($mousePos[0], $mousePos[1])
                If $wInfo[1] = "SysListView32" And $wInfo[3] = "Progman" Then
                    ;Detect Desktop
                    FileCopy("C:\testfile.txt" , @DesktopDir)
                    $startChecking = False
                ElseIf $wInfo[1] = "SysListView32" And $wInfo[3] = "CabinetWClass" Then
                    ;Detect Explorer.exe Window!!!
                    $oldData = _ClipBoard_GetData()
                    $newData = _ClipPutFile("C:\testfile.txt")
                    $conSend = ControlSend($wInfo[4], "", "SysListView321", "Paste: ^v")

                    Sleep(1000)
                    _ClipBoard_SetData($oldData)

                    ;DoDropFiles($wInfo[4], "C:\testfile.txt") - Doesn't Work :(
                    $startChecking = False
                Else
                    DoDropFiles($wInfo[4], "C:\testfile.txt")
                    $startChecking = False
                EndIf
            Else
                $startChecking = False
            EndIf
        EndIf
    EndIf
WEnd
Link to comment
Share on other sites

Well, I've figured out how to send files to explorer and the desktop!

#include <Misc.au3>
#include <WinAPI.au3>
#include <Memory.au3>

Func DoDropFiles($wnd, $Files)
    Local $tagStruct1, $dummy, $hGlobal, $pDropFiles, $DropFiles, $Size
    ;$wnd is the handle of the control we are dropping onto
    ;$Files is the list of files separated by "|"
    $tagStruct1 = "int offset;int px;int py;wchar fNC;wchar fWide"
    $dummy = DllStructCreate($tagStruct1)

    ;grab some memory
    $hGlobal = _MemGlobalAlloc(DllStructGetSize($dummy) + StringLen($Files) + 2)
    ;DropFiles := GlobalLock(MemHandle)
    ;translates the memory handle to a pointer
    $pDropFiles = _MemGlobalLock($hGlobal)
    ;create the struct in this memory
    $DropFiles = DllStructCreate($tagStruct1 & ";char  filelist[" & StringLen($Files) + 2 & "]", $pDropFiles)
    DllStructSetData($DropFiles, "offset", DllStructGetSize($dummy))
    $dummy = 0; done its job
    DllStructSetData($DropFiles, "px", 0);tried setting a point inside Notepad
    DllStructSetData($DropFiles, "py", 0);but it makes no difference
    DllStructSetData($DropFiles, "fwide", 0)
    DllStructSetData($DropFiles, "fNC", 0)
    DllStructSetData($DropFiles, "filelist", $Files)
    ;set the nulls in place of the separaters
    $Size = 0;
    $Files = StringSplit($Files, "|")
    For $I = 1 To $Files[0]

        ;// number of characters per string (as ANSI) plus one #0 terminator
        ;Inc(Size, Length(Files[I]) + 1);
        $Size += StringLen($Files[$I]) + 1
        DllStructSetData($DropFiles, "filelist", 0, $Size)
    Next
    ConsoleWrite(DllStructGetData($DropFiles, "filelist") & @CRLF)
    ;now add the extra null to terminate the list of strings
    DllStructSetData($DropFiles, "filelist", 0, $Size + 1)
    _MemGlobalUnlock($hGlobal)
    _WinAPI_PostMessage($wnd, $WM_DROPFILES, $hGlobal, 0);
    ;// ... and finally release the memory

    _MemGlobalFree($hGlobal)
EndFunc   ;==>DoDropFiles

Func _IsMouseInWindow()
    Local $MouseX, $MouseY, $mousePos
    $mousePos = GUIGetCursorInfo()
    $MouseX = $mousePos[0] ;X Axis info from getcursorinfo()
    $MouseY = $mousePos[1] ;Y Axis info from getcursorinfo()

    ;Does the Mouse's X or Y Extend the window?
    If ($MouseX < -3 Or $MouseX > $GUI_WIDTH + 2 Or $MouseY < -29 Or $MouseY > $GUI_HEIGHT + 2) Then
        ;The mouse is not in the window, return false
        Return False
    Else
        ;Yes, the mouse is in the window, return true
        Return True
    EndIf
EndFunc   ;==>_IsMouseInWindow

Func _WinInfoFromPoint($nX, $nY);by Saio
    Local $tStrBuff, $pStrBuff, $aRet, $hWnd, $hOwnerWnd, $sClassName, $sOwnerClass, $sWinText
    $tStrBuff = DllStructCreate("char[100]")
    $pStrBuff = DllStructGetPtr($tStrBuff)
    $aRet = DllCall("user32.dll", "hwnd", "WindowFromPoint", "uint", $nX, "uint", $nY)
    $hWnd = $aRet[0]
    $aRet = DllCall("user32.dll", "int", "GetClassName", "hwnd", $hWnd, "ptr", $pStrBuff, "int", 100)
    $sClassName = DllStructGetData($tStrBuff, 1)
    DllStructSetData($tStrBuff, 1, "")
    DllCall("user32.dll", "int", "GetWindowText", "hwnd", $hWnd, "ptr", $pStrBuff, "int", 100)
;~  DllCall("user32.dll", "int", "SendMessage", "hwnd", $hWnd, "uint", $WM_GETTEXT, "uint", 100, "ptr", $pStrBuff)
    $sWinText = DllStructGetData($tStrBuff, 1)
    DllStructSetData($tStrBuff, 1, "")
    $aRet = DllCall("user32.dll", "hwnd", "GetAncestor", "hwnd", $hWnd, "uint", 2);$GA_ROOT = 2
    $hOwnerWnd = $aRet[0]
    $aRet = DllCall("user32.dll", "int", "GetClassName", "hwnd", $hOwnerWnd, "ptr", $pStrBuff, "int", 100)
    $sOwnerClass = DllStructGetData($tStrBuff, 1)
    DllStructSetData($tStrBuff, 1, "")

    Local $Array[5] = [$sWinText, $sClassName, $hWnd, $sOwnerClass, $hOwnerWnd]

    ;Window Text: $sWinText | $Array[0]
    ;ClassName: $sClassName | $Array[1]
    ;Window Handle: $hWnd | $Array[2]
    ;Owner ClassName: $sOwnerClass | $Array[3]
    ;Owner Handle: $hOwnerWnd | $Array[4]

    ConsoleWrite(@CRLF & "{ WinInfo }" & @CRLF)
    ConsoleWrite("Window Text: " & $sWinText & @CRLF)
    ConsoleWrite("ClassName: " & $sClassName & @CRLF)
    ConsoleWrite("Window Handle: " & $hWnd & @CRLF)
    ConsoleWrite("Owner ClassName: " & $sOwnerClass & @CRLF)
    ConsoleWrite("Owner Handle: " & $hOwnerWnd & @CRLF)
    ConsoleWrite("{ WinInfo }" & @CRLF & @CRLF)

    Return $Array

EndFunc   ;==>_WinInfoFromPoint

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $GUI_EVENT_DROPPED
            $File = @GUI_DragFile
            If StringRegExp($File, "^.+\.(?i)((TTF)|(OTF)){:content:}quot;) Then
                MsgBox(0, "", $File & @CRLF & "Is a font file.")
            Else
                MsgBox(0, "", $File & @CRLF & "Is an invalid file type.")
            EndIf
        Case $Pic2
            $startChecking = True
    EndSwitch

    If $startChecking Then
        $cInfo = GUIGetCursorInfo()
        If $cInfo[2] = 0 Then
            ;Left Mouse Key Up
            If _IsMouseInWindow() = False Then
                $mousePos = MouseGetPos()
                $wInfo = _WinInfoFromPoint($mousePos[0], $mousePos[1])
                If $wInfo[1] = "SysListView32" And $wInfo[3] = "Progman" Then
                    ;Detect Desktop
                    FileCopy("C:\testfile.txt" , @DesktopDir)
                    $startChecking = False
                ElseIf $wInfo[1] = "SysListView32" And $wInfo[3] = "CabinetWClass" Then
                    ;Detect Explorer.exe Window!!!
                    $oldData = _ClipBoard_GetData()
                    $newData = _ClipPutFile("C:\testfile.txt")
                    $conSend = ControlSend($wInfo[4], "", "SysListView321", "Paste: ^v")

                    Sleep(1000)
                    _ClipBoard_SetData($oldData)

                    ;DoDropFiles($wInfo[4], "C:\testfile.txt") - Doesn't Work :( 
                    $startChecking = False
                Else
                    DoDropFiles($wInfo[4], "C:\testfile.txt")
                    $startChecking = False
                EndIf
            Else
                $startChecking = False
            EndIf
        EndIf
    EndIf
WEnd
I tried to use that but no luck so far :P

Can you post a working example?

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.
Link to comment
Share on other sites

Hmm...try this, you drag from box 2 to the white part of the explorer window.

#include <GUIConstants.au3>
#include <Misc.au3>
#include <WinAPI.au3>
#include <Memory.au3>
#include <SendMessage.au3>
#include <Clipboard.au3>

_Singleton("RBC")
Global Const $WS_EX_ACCEPTFILES = 16
Global Const $WM_DROPFILES = 0x233
$GUI_HEIGHT = 323
$GUI_WIDTH = 441
$startChecking = False

#Region ### START Koda GUI section ### Form=C:\Program Files\Koda 1.7.01\Forms\QuickFTP\FNTConvert.kxf
$Form1 = GUICreate("Rockbox FNT Converter", 441, 323, 293, 202, -1, $WS_EX_ACCEPTFILES)
$Tab1 = GUICtrlCreateTab(6, 7, 428, 308)
GUICtrlSetResizing(-1, $GUI_DOCKWIDTH + $GUI_DOCKHEIGHT)
$TabSheet1 = GUICtrlCreateTabItem("Convert")
$Label1 = GUICtrlCreateLabel("Drop the font(s) onto the left (1st) pane,", 71, 50, 189, 17)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
$Label2 = GUICtrlCreateLabel("then drag the converted font(s) from the right (2nd) pane.", 71, 70, 271, 17)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
$Pic1 = GUICtrlCreatePic("C:\Documents and Settings\Owner\My Documents\Autoit Applications\DropBox.jpg", 71, 101, 130, 130)
GUICtrlSetState(-1, $GUI_DROPACCEPTED)
$Label3 = GUICtrlCreateLabel("Status: Waiting...", 71, 248, 85, 17)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
$Progress1 = GUICtrlCreateProgress(71, 271, 297, 17)
$Pic2 = GUICtrlCreatePic("C:\Documents and Settings\Owner\My Documents\Autoit Applications\DropBox.jpg", 234, 101, 130, 130)
$Label5 = GUICtrlCreateLabel("1.)", 127, 160, 19, 17)
GUICtrlSetState(-1, $GUI_DROPACCEPTED)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0x808080)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
$Label6 = GUICtrlCreateLabel("2.)", 291, 160, 19, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0x808080)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
$TabSheet2 = GUICtrlCreateTabItem("About")
$Label4 = GUICtrlCreateLabel("Developed by motionman95, 2009, All Rights Reserved.", 15, 286, 274, 17)
GUICtrlCreateTabItem("")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

Func DoDropFiles($wnd, $Files)
    Local $tagStruct1, $dummy, $hGlobal, $pDropFiles, $DropFiles, $Size
;$wnd is the handle of the control we are dropping onto
;$Files is the list of files separated by "|"
    $tagStruct1 = "int offset;int px;int py;wchar fNC;wchar fWide"
    $dummy = DllStructCreate($tagStruct1)

;grab some memory
    $hGlobal = _MemGlobalAlloc(DllStructGetSize($dummy) + StringLen($Files) + 2)
;DropFiles := GlobalLock(MemHandle)
;translates the memory handle to a pointer
    $pDropFiles = _MemGlobalLock($hGlobal)
;create the struct in this memory
    $DropFiles = DllStructCreate($tagStruct1 & ";char  filelist[" & StringLen($Files) + 2 & "]", $pDropFiles)
    DllStructSetData($DropFiles, "offset", DllStructGetSize($dummy))
    $dummy = 0; done its job
    DllStructSetData($DropFiles, "px", 0);tried setting a point inside Notepad
    DllStructSetData($DropFiles, "py", 0);but it makes no difference
    DllStructSetData($DropFiles, "fwide", 0)
    DllStructSetData($DropFiles, "fNC", 0)
    DllStructSetData($DropFiles, "filelist", $Files)
;set the nulls in place of the separaters
    $Size = 0;
    $Files = StringSplit($Files, "|")
    For $I = 1 To $Files[0]

    ;// number of characters per string (as ANSI) plus one #0 terminator
    ;Inc(Size, Length(Files[I]) + 1);
        $Size += StringLen($Files[$I]) + 1
        DllStructSetData($DropFiles, "filelist", 0, $Size)
    Next
    ConsoleWrite(DllStructGetData($DropFiles, "filelist") & @CRLF)
;now add the extra null to terminate the list of strings
    DllStructSetData($DropFiles, "filelist", 0, $Size + 1)
    _MemGlobalUnlock($hGlobal)
    _WinAPI_PostMessage($wnd, $WM_DROPFILES, $hGlobal, 0);
;// ... and finally release the memory

    _MemGlobalFree($hGlobal)
EndFunc  ;==>DoDropFiles

Func _IsMouseInWindow()
    Local $MouseX, $MouseY, $mousePos
    $mousePos = GUIGetCursorInfo()
    $MouseX = $mousePos[0];X Axis info from getcursorinfo()
    $MouseY = $mousePos[1];Y Axis info from getcursorinfo()

;Does the Mouse's X or Y Extend the window?
    If ($MouseX < -3 Or $MouseX > $GUI_WIDTH + 2 Or $MouseY < -29 Or $MouseY > $GUI_HEIGHT + 2) Then
    ;The mouse is not in the window, return false
        Return False
    Else
    ;Yes, the mouse is in the window, return true
        Return True
    EndIf
EndFunc  ;==>_IsMouseInWindow

Func _WinInfoFromPoint($nX, $nY);by Saio
    Local $tStrBuff, $pStrBuff, $aRet, $hWnd, $hOwnerWnd, $sClassName, $sOwnerClass, $sWinText
    $tStrBuff = DllStructCreate("char[100]")
    $pStrBuff = DllStructGetPtr($tStrBuff)
    $aRet = DllCall("user32.dll", "hwnd", "WindowFromPoint", "uint", $nX, "uint", $nY)
    $hWnd = $aRet[0]
    $aRet = DllCall("user32.dll", "int", "GetClassName", "hwnd", $hWnd, "ptr", $pStrBuff, "int", 100)
    $sClassName = DllStructGetData($tStrBuff, 1)
    DllStructSetData($tStrBuff, 1, "")
    DllCall("user32.dll", "int", "GetWindowText", "hwnd", $hWnd, "ptr", $pStrBuff, "int", 100)
;~  DllCall("user32.dll", "int", "SendMessage", "hwnd", $hWnd, "uint", $WM_GETTEXT, "uint", 100, "ptr", $pStrBuff)
    $sWinText = DllStructGetData($tStrBuff, 1)
    DllStructSetData($tStrBuff, 1, "")
    $aRet = DllCall("user32.dll", "hwnd", "GetAncestor", "hwnd", $hWnd, "uint", 2);$GA_ROOT = 2
    $hOwnerWnd = $aRet[0]
    $aRet = DllCall("user32.dll", "int", "GetClassName", "hwnd", $hOwnerWnd, "ptr", $pStrBuff, "int", 100)
    $sOwnerClass = DllStructGetData($tStrBuff, 1)
    DllStructSetData($tStrBuff, 1, "")

    Local $Array[5] = [$sWinText, $sClassName, $hWnd, $sOwnerClass, $hOwnerWnd]

;Window Text: $sWinText | $Array[0]
;ClassName: $sClassName | $Array[1]
;Window Handle: $hWnd | $Array[2]
;Owner ClassName: $sOwnerClass | $Array[3]
;Owner Handle: $hOwnerWnd | $Array[4]

    ConsoleWrite(@CRLF & "{ WinInfo }" & @CRLF)
    ConsoleWrite("Window Text: " & $sWinText & @CRLF)
    ConsoleWrite("ClassName: " & $sClassName & @CRLF)
    ConsoleWrite("Window Handle: " & $hWnd & @CRLF)
    ConsoleWrite("Owner ClassName: " & $sOwnerClass & @CRLF)
    ConsoleWrite("Owner Handle: " & $hOwnerWnd & @CRLF)
    ConsoleWrite("{ WinInfo }" & @CRLF & @CRLF)

    Return $Array

EndFunc  ;==>_WinInfoFromPoint

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $GUI_EVENT_DROPPED
            $File = @GUI_DragFile
            If StringRegExp($File, "^.+\.(?i)((TTF)|(OTF))$") Then
                MsgBox(0, "", $File & @CRLF & "Is a font file.")
            Else
                MsgBox(0, "", $File & @CRLF & "Is an invalid file type.")
            EndIf
        Case $Pic2
            $startChecking = True
    EndSwitch

    If $startChecking Then
        $cInfo = GUIGetCursorInfo()
        If $cInfo[2] = 0 Then
        ;Left Mouse Key Up
            If _IsMouseInWindow() = False Then
                $mousePos = MouseGetPos()
                $wInfo = _WinInfoFromPoint($mousePos[0], $mousePos[1])
                If $wInfo[1] = "SysListView32" And $wInfo[3] = "Progman" Then
                ;Detect Desktop
                    FileCopy("C:\testfile.txt" , @DesktopDir)
                    $startChecking = False
                ElseIf $wInfo[1] = "SysListView32" And $wInfo[3] = "CabinetWClass" Then
                ;Detect Explorer.exe Window
                    $oldData = _ClipBoard_GetData()
                    $newData = _ClipPutFile("C:\testfile.txt")
                    $conSend = ControlSend($wInfo[4], "", "SysListView321", "Paste: ^v")

                    Sleep(1000)
                    _ClipBoard_SetData($oldData)

                ;DoDropFiles($wInfo[4], "C:\testfile.txt")
                    $startChecking = False
                Else
                    DoDropFiles($wInfo[4], "C:\testfile.txt")
                    $startChecking = False
                EndIf
            Else
                $startChecking = False
            EndIf
        EndIf
    EndIf
WEnd

If that doesn't work, you're either using vista or there is no "C:\testfile.txt" in your PC...

Link to comment
Share on other sites

Hmm...try this, you drag from box 2 to the white part of the explorer window.

Yes I could get that to work by substituting the files I have for the files you used. But it I also had to replace CabinetWClass with ExploreWClass. Maybe you need to have an or case there to allow for either.

That's very good motionman95, and it's easier than I expected.

I see that if you want to paste more than one file to an explorer window then you can add files paths together but separated with '|'.

eg

$newData = _ClipPutFile("T:\netdev\ccrat.obj|T:\netdev\cc2.sym")

It would be nice to have some visual indication of dragging being shown. Maybe something like I suggested in post #45?

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.
Link to comment
Share on other sites

This is all I've come up with so far, but I'm not sure how to change the cursor back, beside going to "Control Panel > Mouse > Pointer".

EDIT: Whoops, forgot to attach the.cur file. I had to attach in a zip file because .cur files aren't allowed.

drag_cursor.zip

; Set Mouse Cursor Style
; Author - gafrost

Global Const $OCR_NORMAL = 32512

_SetCursor("C:\Documents and Settings\Owner\My Documents\Autoit Applications\drag_cursor2.cur", $OCR_NORMAL)

Func _SetCursor($s_file, $i_cursor)
   Local $newhcurs, $lResult
   $newhcurs = DllCall("user32.dll", "int", "LoadCursorFromFile", "str", $s_file)
   If Not @error Then
      $lResult = DllCall("user32.dll", "int", "SetSystemCursor", "int", $newhcurs[0], "int", $i_cursor)
      If Not @error Then
         $lResult = DllCall("user32.dll", "int", "DestroyCursor", "int", $newhcurs[0])
      Else
         MsgBox(0, "Error", "Failed SetSystemCursor")
      EndIf
   Else
      MsgBox(0, "Error", "Failed LoadCursorFromFile")
   EndIf
EndFunc;==>_SetCursor
Edited by motionman95
Link to comment
Share on other sites

Any idea how to restore the old normal cursor?

Not at the moment. I did it by Control Panel|Mouse|Pointer then I clicked twice on the 'Enable Pointer Shadow' check box so that the Apply button was enabled and clicked Apply.

I'll have a look tonight if there's no answer here.

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.
Link to comment
Share on other sites

I have found out why there was a problem with the paths, why setting the working directory was sometimes needed and why prefixing with "\\" helped. It was of course an error in the function.

Here is the corrected version and it seems to work faster now. (Possibly me kidding myself.)

...

EDIT:I changed it yet again after I realized that the problem had been to do with byte alignment with the dummy struct which I have stopped using.

I had to add
Local $dummy
to the top of the function so it wouldn't throw an error.

I grabbed the class of the drawing control in AutoCAD, and used that as the 'target' for my .dwg file, to some odd results.

I've got the following code above your DoDropFiles function:

#include <WinAPI.au3>
#include <Memory.au3>
#include <Misc.au3>

Const $WM_DROPFILES = 0x233
$HWND = ControlGetHandle("AutoCAD 2008","","[CLASS:Afx:00400000:28:00000000:00000002:000106F3; INSTANCE:1]")
DoDropFiles($HWND, "Z:\DXLIB\PLUM\wc-spec.dwg")

When I run the code, I get a message box from AutoCAD with title "Drag and Drop", and the message says

No association..Z:\DXLIB\PLUMM\\

I've tried adding double backslashes to the front, doubling the backslashes in the path, adding another backslash at the end, etc...each combination changes the path it shows, but nothing seems to make AutoCAD see the file name part of the path.

When I save a block on the desktop (Drawing1.dwg) and point to that file instead, I get three msg boxes:

No association..C:\users\myusername\desktop\e

No association..C:\users\myusername\desktop\x

No association..C:\users\myusername\desktop\e

If I grab the control of the text input area, nothing happens when I run the script.

If I send the contents of the block file instead of the path, I get a similar popup, with 7 seemingly random characters instead of the path (AC1021), and AutoCAD crashes with a return code of -1073741819

Changing the coords didn't affect the outcome at all.

If you have other thoughts, I'd love to hear them. :P Thanks anyway for this very cool function!

"There are 10 types of people in this world - those who can read binary, and those who can't.""We've heard that a million monkeys at a million keyboards could produce the complete works of Shakespeare; now, thanks to the Internet, we know that is not true." ~Robert Wilensky0101101 1001010 1100001 1101101 1100101 1110011 0110011 1001101 10001110000101 0000111 0001000 0001110 0001101 0010010 1010110 0100001 1101110
Link to comment
Share on other sites

I had to add

Local $dummy
to the top of the function so it wouldn't throw an error.

I grabbed the class of the drawing control in AutoCAD, and used that as the 'target' for my .dwg file, to some odd results.

I've got the following code above your DoDropFiles function:

#include <WinAPI.au3>
  #include <Memory.au3>
  #include <Misc.au3>
  
  Const $WM_DROPFILES = 0x233
  $HWND = ControlGetHandle("AutoCAD 2008","","[CLASS:Afx:00400000:28:00000000:00000002:000106F3; INSTANCE:1]")
  DoDropFiles($HWND, "Z:\DXLIB\PLUM\wc-spec.dwg")

When I run the code, I get a message box from AutoCAD with title "Drag and Drop", and the message says

I've tried adding double backslashes to the front, doubling the backslashes in the path, adding another backslash at the end, etc...each combination changes the path it shows, but nothing seems to make AutoCAD see the file name part of the path.

When I save a block on the desktop (Drawing1.dwg) and point to that file instead, I get three msg boxes:

If I grab the control of the text input area, nothing happens when I run the script.

If I send the contents of the block file instead of the path, I get a similar popup, with 7 seemingly random characters instead of the path (AC1021), and AutoCAD crashes with a return code of -1073741819

Changing the coords didn't affect the outcome at all.

If you have other thoughts, I'd love to hear them. :P Thanks anyway for this very cool function!

I have just changed the error in post #60. I shouldn't have had $dummy there at all, and the version in that post no longer needs the '\\' in front which was due to rounding up of the $dummy dllstruct size.

I'm not sure but I think the $WM_DROPFILES message should be sent to the parent window.

If I do this with TurboCad then it opens the file fine.

;by motionman95 and martin feb 2009
 
 #include <WinAPI.au3>
 #include <Memory.au3>
 #include <Misc.au3>
 opt("WInTitleMatchMode",2)
 Const $WM_DROPFILES = 0x233
 
 $HWND = WinGetHandle("TurboCAD Professional");Untitled - Notepad")
 ConsoleWrite("handle = " & $HWND & @CRLF)
 
;set the path to the file to be dropped
 $path = FileGetLongName("G:\1stglass.tcw")
 ConsoleWrite($path & @CRLF)
 DoDropFiles($HWND, $path)
 
 
 Func DoDropFiles($wnd, $Files)
;$wnd is the handle of the control we are dropping onto
;$Files is the list of files separated by "|"
   $tagStruct1 = "int offset;int px;int py;byte fNC;byte fWide"
 
;grab some memory
     $hGlobal = _MemGlobalAlloc(14 + StringLen($Files) + 2)
;DropFiles := GlobalLock(MemHandle)
;translates the memory handle to a pointer
     $pDropFiles = _MemGlobalLock($hGlobal)
;create the struct in this memory
     $DropFiles = DllStructCreate($tagStruct1 & ";char  filelist[" & StringLen($Files) + 2 & "]", $pDropFiles)
     DllStructSetData($DropFiles, "offset", 14);14 = int+int+int+byte+byte
     $dummy = 0; done its job
     DllStructSetData($DropFiles, "px", 0);tried setting a point inside Notepad
     DllStructSetData($DropFiles, "py", 0);but it makes no difference
     DllStructSetData($DropFiles, "fwide", 0)
     DllStructSetData($DropFiles, "fNC", 0)
     DllStructSetData($DropFiles, "filelist", $Files)
;set the nulls in place of the separaters
     $Size = 0;
     $Files = StringSplit($Files, "|")
     For $I = 1 To $Files[0]
 
  ; number of characters per string (as ANSI) plus one #0 terminator
  ;Inc(Size, Length(Files[I]) + 1);
         $Size += StringLen($Files[$I]) + 1
         DllStructSetData($DropFiles, "filelist", 0, $Size)
     Next
     ConsoleWrite(DllStructGetData($DropFiles, "filelist") & @CRLF)
;now add the extra null to terminate the list of strings
     DllStructSetData($DropFiles, "filelist", 0, $Size + 1)
     _MemGlobalUnlock($hGlobal)
     _WinAPI_PostMessage($wnd, $WM_DROPFILES, $hGlobal, 0);
; ... and finally release the memory
 
     _MemGlobalFree($hGlobal)
 EndFunc;==>DoDropFiles

EDIT: I removed some commented out text

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.
Link to comment
Share on other sites

I have just changed the error in post #60. I shouldn't have had $dummy there at all, and the version in that post no longer needs the '\\' in front which was due to rounding up of the $dummy dllstruct size.

I'm not sure but I think the $WM_DROPFILES message should be sent to the parent window.

If I do this with TurboCad then it opens the file fine.

...

EDIT: I removed some commented out text

Viola! I tried it first switching to the window handle like you suggested, and it continued to open the file, rather than inserting it (as if I'd dragged the file into the window myself). But, as I was posting that it still wasn't working, I thought to change it back to use the drawing control as the target, and it worked just like I wanted; just like I'd dragged the file in myself!

Thanks so much for the help, both of you!

~james3mg

"There are 10 types of people in this world - those who can read binary, and those who can't.""We've heard that a million monkeys at a million keyboards could produce the complete works of Shakespeare; now, thanks to the Internet, we know that is not true." ~Robert Wilensky0101101 1001010 1100001 1101101 1100101 1110011 0110011 1001101 10001110000101 0000111 0001000 0001110 0001101 0010010 1010110 0100001 1101110
Link to comment
Share on other sites

Viola! I tried it first switching to the window handle like you suggested, and it continued to open the file, rather than inserting it (as if I'd dragged the file into the window myself). But, as I was posting that it still wasn't working, I thought to change it back to use the drawing control as the target, and it worked just like I wanted; just like I'd dragged the file in myself!

Thanks so much for the help, both of you!

~james3mg

That's great :P

Thanks for the feedback james3mg. I'm surpised how much can be done with the function. I've looked up the msdn information on drag and drop a few times since motionman started this thread and still I have no idea how to implement full drag and drop the way it happens when you drag files from explorer. The OLE part looses me every time :unsure: .

It's lucky that you tried sending the message to the drawing control again. Perhaps you could add something to the function to detect if the drop was over the drawing control or somewhere else over the AutoCad window and send the message to the correct handle automatically.

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.
Link to comment
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
 Share

  • Recently Browsing   0 members

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