SlimShady Posted June 25, 2009 Share Posted June 25, 2009 Can you drop an executable on a button and trigger a function?I can't get $WS_EX_ACCEPTFILES to work AND trigger an event on a button.On a window it's fine, but I don't want that (+ icon in the window client area).Could anyone meddle with this test code and see if it's possible? Thanks.expandcollapse popup#include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Opt("GUIOnEventMode", 1) #Region ### START Koda GUI section ### Form= global $Form1 = GUICreate("Form1", 625, 443, 192, 124, -1, $WS_EX_ACCEPTFILES) global $input1 = GUICtrlCreateInput("", 120, 140, 120, 17, $WS_GROUP, $WS_EX_ACCEPTFILES) global $Button1 = GUICtrlCreateButton("Button1", 120, 88, 97, 41, $WS_GROUP, $WS_EX_ACCEPTFILES) GUICtrlSetState($input1, $GUI_DROPACCEPTED); GUICtrlSetState($Button1, $GUI_DROPACCEPTED); GUISetOnEvent($GUI_EVENT_CLOSE, '_onClose'); GUISetOnEvent($GUI_EVENT_DROPPED, "_evDroppedFiles2") GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### Const $WM_DROPFILES = 0x233; GUIRegisterMsg($WM_DROPFILES, "On_WM_DROPFILES") While 1 Sleep(100) WEnd Func _onClose() GUIDelete() Exit EndFunc Func _evDroppedFiles2() MsgBox(64, 'fun2', @GUI_DragFile) EndFunc Func _evDroppedFiles(ByRef $dFiles) local $x, $files; For $x = 0 To UBound($dFiles)-1 $files &= $dFiles[$x] & ', ' Next MsgBox(64, 'func1', StringTrimRight($dFiles, 2)); EndFunc Func On_WM_DROPFILES($hWnd, $Msg, $wParam, $lParam) Local $tDrop, $i, $aRet, $iCount; ;string buffer for file path $tDrop = DllStructCreate("char[260]") ;get file count $aRet = DllCall("shell32.dll", "int", "DragQueryFile", _ "hwnd", $wParam, _ "uint", -1, _ "ptr", DllStructGetPtr($tDrop), _ "int", DllStructGetSize($tDrop) _ ) $iCount = $aRet[0] ;get file paths local $aDraggedFiles[$iCount]; For $i = 0 To $iCount-1 $aRet = DllCall("shell32.dll", "int", "DragQueryFile", _ "hwnd", $wParam, _ "uint", $i, _ "ptr", DllStructGetPtr($tDrop), _ "int", DllStructGetSize($tDrop) _ ) $aDraggedFiles[$i] = DllStructGetData($tDrop, 1); Next ;finalize DllCall("shell32.dll", "int", "DragFinish", "hwnd", $wParam) Return _evDroppedFiles($aDraggedFiles); EndFunc Link to comment Share on other sites More sharing options...
ProgAndy Posted June 25, 2009 Share Posted June 25, 2009 (edited) This way it works: expandcollapse popup#include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Opt("GUIOnEventMode", 1) #Region ### START Koda GUI section ### Form= global $Form1 = GUICreate("Form1", 625, 443, 192, 124) global $input1 = GUICtrlCreateInput("", 120, 140, 120, 17) Global $hDropGUI = GUICreate("DropGUI", 97, 41, 120, 88, BitOR($WS_CHILD, $WS_VISIBLE), BitOR($WS_EX_ACCEPTFILES, $WS_EX_CONTROLPARENT), $Form1) global $Button1 = GUICtrlCreateButton("Button1", 0, 0, 97, 41) GUICtrlSetState($Button1, $GUI_DROPACCEPTED); GUISwitch($Form1) GUISetOnEvent($GUI_EVENT_CLOSE, '_onClose'); GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### Const $WM_DROPFILES = 0x233; GUIRegisterMsg($WM_DROPFILES, "On_WM_DROPFILES") While 1 Sleep(100) WEnd Func _onClose() GUIDelete() Exit EndFunc Func _evDroppedFiles(ByRef $dFiles) local $x, $files; For $x = 0 To UBound($dFiles)-1 $files &= $dFiles[$x] & @CRLF Next MsgBox(64, 'func1', StringTrimRight($files, 2)); EndFunc Func On_WM_DROPFILES($hWnd, $Msg, $wParam, $lParam) Local $tDrop, $i, $aRet, $iCount; ;get file count $aRet = DllCall("shell32.dll", "int", "DragQueryFileW", "ptr", $wParam, "uint", -1, "ptr", 0, "uint", 0 ) $iCount = $aRet[0] ;get file paths local $aDraggedFiles[$iCount]; For $i = 0 To $iCount-1 $aRet = DllCall("shell32.dll", "int", "DragQueryFileW", "ptr", $wParam, "uint", $i, "ptr", 0, "uint", 0) Local $tDrop = DllStructCreate("wchar[" & $aRet[0]+1 & "]") $aRet = DllCall("shell32.dll", "int", "DragQueryFileW", "ptr", $wParam, "uint", $i, "ptr", DllStructGetPtr($tDrop), "uint", $aRet[0]+1) $aDraggedFiles[$i] = DllStructGetData($tDrop, 1); Next ;finalize DllCall("shell32.dll", "int", "DragFinish", "ptr", $wParam) Return _evDroppedFiles($aDraggedFiles); EndFunc Edited June 25, 2009 by ProgAndy *GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now