nu852 Posted July 14, 2008 Posted July 14, 2008 Suppose I drag drop a file onto the window, I expect that it trigger the GUI Window's $GUI_DROPACCEPTED event. However, It doesn't. The GUI Window's would only be triggerred by the $GUI_EVENT_CLOSE, $GUI_EVENT_MINIMIZE and $GUI_EVENT_RESTORE events. I would like to know whether $GUI_DROPACCEPTED event could be used in GUI window. Thanks in advance. my testing code expandcollapse popup#include <WindowsConstants.au3> #include <GUIConstantsEx.au3> Opt('MustDeclareVars', 1) Example() Func Example() Local $parent1 Opt("GUICoordMode", 2) Opt("GUIResizeMode", 1) Opt("GUIOnEventMode", 1) ;$parent1 = GUICreate("Parent1") $parent1 = GUICreate("Parent1",-1,-1,-1,-1,-1, $WS_EX_ACCEPTFILES) GUISetOnEvent($GUI_EVENT_DROPPED, "SpecialEvents") GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents") GUISetOnEvent($GUI_EVENT_MINIMIZE, "SpecialEvents") GUISetOnEvent($GUI_EVENT_RESTORE, "SpecialEvents") GUISetState(@SW_SHOW) While 1 Sleep(100) WEnd EndFunc Func SpecialEvents() MsgBox(0, "Window Event", "Trigger SpecialEvents") Select Case @GUI_CtrlId = $GUI_EVENT_DROPPED ;MsgBox(0, "Close Pressed", "ID=" & @GUI_CtrlId & " WinHandle=" & @GUI_WinHandle) MsgBox(0, "@GUI_DRAGFILE ", @GUI_DRAGFILE ) Case @GUI_CtrlId = $GUI_EVENT_CLOSE MsgBox(0, "Close Pressed", "ID=" & @GUI_CtrlId & " WinHandle=" & @GUI_WinHandle) Exit Case @GUI_CtrlId = $GUI_EVENT_MINIMIZE MsgBox(0, "Window Minimized", "ID=" & @GUI_CtrlId & " WinHandle=" & @GUI_WinHandle) Case @GUI_CtrlId = $GUI_EVENT_RESTORE MsgBox(0, "Window Restored", "ID=" & @GUI_CtrlId & " WinHandle=" & @GUI_WinHandle) EndSelect EndFunc ;==>SpecialEvents
wraithdu Posted July 14, 2008 Posted July 14, 2008 (edited) $GUI_EVENT_DROPPED is only triggered when a file/folder is dropped on a control with the $GUI_DROPACCEPTED style. Try adding this - GUICtrlCreateInput("", 10, 10) GUICtrlSetState(-1, $GUI_DROPACCEPTED) If you want to drop files/folders on the main GUI, you'll have to register and use the $WM_DROPFILES message. EDIT - Or you could hack around it like this - GUICtrlCreateLabel("", 10, 10, 100, 100) GUICtrlSetState(-1, $GUI_DROPACCEPTED) GUICtrlSetState(-1, $GUI_DISABLE) And make the label the size of your GUI. Edited July 14, 2008 by wraithdu
rasim Posted July 14, 2008 Posted July 14, 2008 nu852Example:expandcollapse popup#include <WindowsConstants.au3> #include <GUIConstantsEx.au3> Opt('MustDeclareVars', 1) Global Const $WM_DROPFILES = 0x0233 Example() Func Example() Local $parent1 Opt("GUICoordMode", 2) Opt("GUIResizeMode", 1) Opt("GUIOnEventMode", 1) ;$parent1 = GUICreate("Parent1") $parent1 = GUICreate("Parent1", 300, 200, -1, -1, -1, $WS_EX_ACCEPTFILES) GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents") GUISetOnEvent($GUI_EVENT_MINIMIZE, "SpecialEvents") GUISetOnEvent($GUI_EVENT_RESTORE, "SpecialEvents") GUIRegisterMsg($WM_DROPFILES, "WM_DROPFILES") GUISetState(@SW_SHOW) While 1 Sleep(100) WEnd EndFunc Func SpecialEvents() MsgBox(0, "Window Event", "Trigger SpecialEvents") Select Case @GUI_CtrlId = $GUI_EVENT_CLOSE MsgBox(0, "Close Pressed", "ID=" & @GUI_CtrlId & " WinHandle=" & @GUI_WinHandle) Exit Case @GUI_CtrlId = $GUI_EVENT_MINIMIZE MsgBox(0, "Window Minimized", "ID=" & @GUI_CtrlId & " WinHandle=" & @GUI_WinHandle) Case @GUI_CtrlId = $GUI_EVENT_RESTORE MsgBox(0, "Window Restored", "ID=" & @GUI_CtrlId & " WinHandle=" & @GUI_WinHandle) EndSelect EndFunc ;==>SpecialEvents Func WM_DROPFILES($hWnd, $msg, $wParam, $lParam) Local $tBuffer = DllStructCreate("char[256]") Local $iString ;Get dropped items count Local $aRet = DllCall("shell32.dll", "int", "DragQueryFile", "int", $wParam, "int", -1, "ptr", 0, "int", 0) ;Getting name from each dropped items For $i = 0 To $aRet[0] - 1 DllCall("shell32.dll", "int", "DragQueryFile", "int", $wParam, "int", $i, "ptr", DllStructGetPtr($tBuffer), _ "int", DllStructGetSize($tBuffer)) $iString &= DllStructGetData($tBuffer, 1) & @LF Next DllCall("shell32.dll", "none", "DragFinish", "int", $wParam) MsgBox(0, "Dropped files", $iString) Return $GUI_RUNDEFMSG EndFunc ;==>WM_DROPFILES
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