squadjot Posted August 12, 2014 Posted August 12, 2014 (edited) Hi, i'd like to create a GUI with multiple "dropzones" (labels) , The basics are working fine, - but how do i find out which label the files was dropped on to? My script goes something like this Global $__DropFiles Global $hGUI = GUICreate('DragNDrop', 550, 550, -1, -1, -1, $WS_EX_ACCEPTFILES) Global $dropZone1 = GUICtrlCreateLabel("", 0, 0, 150, 150) GUICtrlSetBkColor(-1, $COLOR_RED) GUICtrlSetResizing(-1, $GUI_DOCKALL) GUICtrlSetState(-1, $GUI_DROPACCEPTED) Global $dropZone2 = GUICtrlCreateLabel("", 160, 0, 150, 150) GUICtrlSetBkColor(-1, $COLOR_BLUE) GUICtrlSetResizing(-1, $GUI_DOCKALL) GUICtrlSetState(-1, $GUI_DROPACCEPTED) GUIRegisterMsg($WM_DROPFILES, "WM_DROPFILES") GUISetState(@SW_SHOW, $hGUI) Func WM_DROPFILES($hWnd, $iMsg, $iwParam, $ilParam) #forceref $hWnd, $iMsg, $ilParam Local $aError[1] = [0], $aReturn Switch $iMsg Case $WM_DROPFILES $aReturn = _WinAPI_DragQueryFileEx($iwParam) If IsArray($aReturn) Then $__DropFiles = $aReturn Else $__DropFiles = $aError EndIf ; _WinAPI_DragFinish($iwParam) EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_DROPFILES Edited August 12, 2014 by squadjot
Solution BrewManNH Posted August 12, 2014 Solution Posted August 12, 2014 (edited) From the help file: If $GUI_DROPACCEPTED (8) is set to a visible control a drag & drop can be taken in account. The edit/input control will be set with the filename. For other controls on reception of $GUI_EVENT_DROPPED, @GUI_DragId will return the controlID from where the drag start (-1 if from a file, @GUI_DragFile contain the filename being dropped) and @GUI_DropId returns the controlID of the dropped control. Edited August 12, 2014 by BrewManNH If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator
squadjot Posted August 12, 2014 Author Posted August 12, 2014 (edited) Ahh, @GUI_DropId was what i needed - thanks a bunch! Just a side question while trying to make a solution (trying to learn) Any reason why this would not work? (Abstract) (To clarify a bit, the problem is that $cPos = ControlGetPos , does not end up as an array) Global $dropZone1 = GUICtrlCreateLabel("", 0, 0, 150, 150) GUICtrlSetBkColor(-1, $COLOR_RED) GUICtrlSetResizing(-1, $GUI_DOCKALL) GUICtrlSetState(-1, $GUI_DROPACCEPTED) test() Func test() $wasOver = isMouseOver($dropZone1) EndFunc Func isMouseOver($ctrlRef) Local $mp = MouseGetPos() Local $cPos = ControlGetPos("","",$ctrlRef) Local $res = False if(IsArray($cPos)) Then if($mp[0] < $cPos[0]+$cPos[2] And $mp[1] < $cPos[2]+$cPos[3] And $mp[0] > $cPos[0] And $mp[1] > $cPos[1] ) Then $res = True Else EndIf Else ; not array EndIf return $res EndFunc Edited August 12, 2014 by squadjot
BrewManNH Posted August 12, 2014 Posted August 12, 2014 Can you post a script that can be tested instead of a piece of it? Without knowing exactly how you're calling the test function, it's impossible to tell why controlgetpos doesn't work as expected. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator
squadjot Posted August 12, 2014 Author Posted August 12, 2014 Yeah i know it's not "runnable".. but it's more or less it.. The only change was that i was making the isMouseOver($dropZone1) call from inside WM_DROPFILES. I checked that the parameter $ctrlRef is the integer of the guictrl.. Anyways, i'll see if i can post a more complete example. thanks for your help so far!
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