Mungo Posted September 18, 2012 Share Posted September 18, 2012 (edited) I am trying restrict the drag and drop action to folder paths only (rather than path and file names).I am using the extended style $WS_EX_ACCEPTFILES during gui creation and GUICtrlSetState(-1, $GUI_DROPACCEPTED) on the input control (sample code below).Thanks for any hints.#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> f_gui_drop() Func f_gui_drop() Local $msg GUICreate("Test drop DIR only", 300, 300, -1, -1, -1, $WS_EX_ACCEPTFILES) GUICtrlCreateLabel("Drop a dir only ... " , 10, 10, 200, 20) Local $dir_dropped = GUICtrlCreateInput("", 10, 30, 280, 20) GUICtrlSetState(-1, $GUI_DROPACCEPTED) GUISetState(@SW_SHOW) While 1 $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then ExitLoop WEnd GUIDelete() EndFunc Edited September 18, 2012 by Mungo Link to comment Share on other sites More sharing options...
UEZ Posted September 18, 2012 Share Posted September 18, 2012 Try this: #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> f_gui_drop() Func f_gui_drop() Local $msg GUICreate("Test drop DIR only", 300, 300, -1, -1, -1, $WS_EX_ACCEPTFILES) GUICtrlCreateLabel("Drop a dir only ... " , 10, 10, 200, 20) Local $dir_dropped = GUICtrlCreateInput("", 10, 30, 280, 20) GUICtrlSetState(-1, $GUI_DROPACCEPTED) GUISetState(@SW_SHOW) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $GUI_EVENT_DROPPED GUICtrlSetData($dir_dropped, StringRegExpReplace(GUICtrlRead($dir_dropped), "(.*).*", "$1")) EndSwitch WEnd GUIDelete() EndFunc Br, UEZ mesale0077 1 Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
Mungo Posted September 20, 2012 Author Share Posted September 20, 2012 (edited) Thanks UEZ!That works fine ! It strips off the filename nicely if a file is being dropped. However, the problem is if the user actually does what he is supposed to do (in my program) and drops a DIR onto the input control, it strips off one dir level (to the next ""), which shouldn't be.I found a way by using FileGetAttrib in a condition to check for the file attribute to be "D" for DIRECTORY within the dropped string and combined it with your StringRegExpReplace line. That seems to do the trick :-)Cheers#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Opt('MustDeclareVars', 1) f_gui_drop() Func f_gui_drop() GUICreate("Test drop DIR only", 400, 300, -1, -1, -1, $WS_EX_ACCEPTFILES) GUICtrlCreateLabel("Drop a dir only ... " , 10, 10, 200, 20) Local $dir_dropped = GUICtrlCreateInput("", 10, 30, 380, 20) GUICtrlSetState(-1, $GUI_DROPACCEPTED) Local $clear_button = GUICtrlCreateButton("Clear", 160, 200, 80, 24) GUISetState(@SW_SHOW) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $GUI_EVENT_DROPPED Local $dir_string = GUICtrlRead($dir_dropped) Local $attribute = FileGetAttrib($dir_string) ; Retrieve the file/dir attributes If StringInStr($attribute, "D") Then ; If the attribute string contains the letter 'D' then it is a DIR. MsgBox(4096, "", "It is a DIR - OK !") Else GUICtrlSetData($dir_dropped, StringRegExpReplace(GUICtrlRead($dir_dropped), "(.*).*", "$1")) ; Strip filename from path MsgBox(4096, "", "It is a FILE - Filename stripped from PATH!") EndIf Case $clear_button GUICtrlSetData($dir_dropped, "") EndSwitch WEnd GUIDelete() EndFunc Edited September 20, 2012 by Mungo Link to comment Share on other sites More sharing options...
cyberbit Posted January 5, 2013 Share Posted January 5, 2013 ... Local $attribute = FileGetAttrib($dir_string) ; Retrieve the file/dir attributes If StringInStr($attribute, "D") Then ; If the attribute string contains the letter 'D' then it is a DIR. MsgBox(4096, "", "It is a DIR - OK !") ... Why not use _WinAPI_PathIsDirectory from WinAPIEx? It's included in the beta. Regards, Cyberbit _ArrayConcatenate2D · Aero Flip 3D · EPOCH (destroy timestamps) · File Properties Modifier · _GetFileType · UpdateEngine<new> · In-line Case (_ICase) <new> [hr] 50% of the time, it works all the time. -PezoFaSho Link to comment Share on other sites More sharing options...
guinness Posted January 6, 2013 Share Posted January 6, 2013 Because not everyone is using WinAPIEx and/or has the beta version of AutoIt installed. Nothing wrong with using native functions. UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
GHOSTSKIKDA Posted April 11, 2013 Share Posted April 11, 2013 try this : #include #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> f_gui_drop() Func f_gui_drop() Local $msg GUICreate("Test drop DIR only", 300, 300, -1, -1, -1, $WS_EX_ACCEPTFILES) GUICtrlCreateLabel("Drop a dir only ... " , 10, 10, 200, 20) Local $dir_dropped = GUICtrlCreateInput("", 10, 30, 280, 20) GUICtrlSetState(-1, $GUI_DROPACCEPTED) GUISetState(@SW_SHOW) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $GUI_EVENT_DROPPED Local $attribute = FileGetAttrib(GUICtrlRead($dir_dropped)) ; Retrieve the file/dir attributes If StringInStr($attribute, "D") Then ; If the attribute string contains the letter 'D' then it is a DIR. Else GUICtrlSetData($dir_dropped,"") EndIf EndSwitch WEnd GUIDelete() EndFunc [center]I LOVE ALGERIA .... ;-)[/center] Link to comment Share on other sites More sharing options...
MilesAhead Posted January 14, 2014 Share Posted January 14, 2014 (edited) Case $GUI_EVENT_DROPPED I'm using this technique. It works fine if the input is empty. But if I load the input from an .ini file, then later if a file path is dropped, the old data is not erased. I end up with, as example, C:MyFolderMyFile.txtC:OtherFolderotherfile.txt in the input. Since I have 2 inputs I don't know where the drop is going to try to erase it with SetData("") Edit: and just having the inputs start blank is no help as the user will want to know what files were saved to the ini file. I'm using AutoIt 3.3.8.1 Edit: @GUI_DropId did the trick Edited January 16, 2014 by MilesAhead My Freeware Page 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