Search the Community
Showing results for tags 'dropaccepted'.
-
Generally speaking, the support for autoit AU3 file drag and drop is not perfect AU3 built-in GUI $WS_ EX_ ACCESSFILES, Control $GUI_ DROPACCEPTED, then @ GUI_ DropId distinguishes the control that occurs, but @ GUI_ DragFile does not support multiple files, only the first file is recognized! And dragging into the window means dragging and dropping the cursor, without distinguishing the display of controls. Common WM_DROPFILES_FUNC, DllCall shell32.dll DragQueryFile, GUI window also $WS_ EX_ ACCESSFILES, supports multiple files, but requires GUI event mode 1, and cannot distinguish which control occurred, making it difficult to handle when there are multiple different drag and drop destinations. Similarly, dragging the cursor into the window does not distinguish the display of controls. Here is an example of AU3 source code that can determine which control triggers the drag, and can support multiple files being dragged in at once, which can be processed one by one without setting GUIOnEventMode to 1 Running under WIN11 has passed. The image shows the system wallpaper of WIN11 or WIN7. If you don't have it, please replace it yourself Select multiple files in the system file browser, then drag them into the program window. When pointing to the blank space, cursor as disabled. When pointing to the Input input box and image, you can release the mouse to complete the drag and drop. The effect is that the input box displays all the file names that were dragged and dropped, and displays the recently dragged control hWnd,for easy differentiation ================== #include <GUIConstants.au3> #include <WinAPI.au3> #include <Array.au3> Global $aFileList, $lastDragID $hGUI = GUICreate("Independent control multi file drag", 565, 247, -1, -1, -1, $WS_EX_WINDOWEDGE) $Input1 = GUICtrlCreateInput("", 32, 16, 505, 121) ; Now only here the drop sign appears $defpic1 = "C:\Windows\Web\Wallpaper\Spotlight\img50.jpg" ;win11壁纸1 $defpic2 = "C:\Windows\Web\Wallpaper\Windows\img19.jpg" ;win11壁纸2 $defpic = "" For $i = 1 To 5 If Random(0, 1, 1) Then $defpic = $defpic1 Else $defpic = $defpic2 EndIf Assign("Pic" & $i & "Handle", GUICtrlCreatePic($defpic, 20 + (($i - 1) * 100), 180, 90, 50, -1, $WS_EX_ACCEPTFILES)) GUICtrlSetState(Eval("Pic" & $i & "Handle"), $GUI_DROPACCEPTED) Next GUICtrlSetState(-1, $GUI_DROPACCEPTED) Global $idDummy = GUICtrlCreateDummy() GUISetState() $wProcHandle = DllCallbackRegister("_WindowProc", "ptr", "hwnd;uint;wparam;lparam") For $i = 1 To 5 Assign("gchp" & $i, GUICtrlGetHandle(Eval("Pic" & $i & "Handle"))) Assign("wProcOld" & $i, _WinAPI_SetWindowLong(Eval("gchp" & $i), $GWL_WNDPROC, DllCallbackGetPtr($wProcHandle))) Next While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $idDummy For $i = 1 To $aFileList[0] ConsoleWrite($aFileList[$i] & @CRLF) ;拖放处理文件段 Next GUICtrlSetData($Input1, $lastDragID & "##" & _ArrayToString($aFileList, "|", 1)) For $i = 1 To 5;提示哪个控件响应 If Eval("gchp" & $i) = $lastDragID Then MsgBox(0, "idP-" & $i, _ArrayToString($aFileList, @CRLF, 1)) Next EndSwitch WEnd GUIDelete($hGUI) DllCallbackFree($wProcHandle) Func _WindowProc($hWnd, $Msg, $wParam, $lParam) For $j = 1 To 5 ;拖放识别控件段 If $hWnd = GUICtrlGetHandle(Eval("Pic" & $j & "Handle")) Then isDrag($hWnd, $Msg, $wParam, $lParam, Eval("wProcOld" & $j)) Next EndFunc ;==>_WindowProc Func isDrag($hWnd2, $Msg2, $wParam2, $lParam2, $wProcOldx) If $Msg2 = $WM_DROPFILES Then $lastDragID = $hWnd2 ConsoleWrite($lastDragID & @CRLF) $aFileList = _WinAPI_DragQueryFileEx($wParam2) If Not @error Then GUICtrlSendToDummy($idDummy) _WinAPI_DragFinish($wParam2) Return 0 Else Return _WinAPI_CallWindowProc($wProcOldx, $hWnd2, $Msg2, $wParam2, $lParam2) ;放行相应控件的其它消息 EndIf EndFunc ;==>isDrag ================= 单控件多文件拖放22.au3