Windows Drag Drop

Just starting out? Need help? Post your questions and find answers here.
BarryG
Addict
Addict
Posts: 4130
Joined: Thu Apr 18, 2019 8:17 am

Re: Windows Drag Drop

Post by BarryG »

Fluent's code modified so that only the CanvasGadget() itself will accept dropped files, even when the exe is run as admin.

Code: Select all

#MainWindow = 0
#CanvasGadget = 1

OpenWindow(#MainWindow, 240, 140, 500, 400, "Drop onto gadget when admin" )
StickyWindow(#MainWindow, 1)

droptarget = CanvasGadget(#CanvasGadget, 50, 50, 300, 300)

hWND = WindowID(#MainWindow)

ChangeWindowMessageFilter_(#WM_DROPFILES, #MSGFLT_ADD)
ChangeWindowMessageFilter_(#WM_COPYDATA, #MSGFLT_ADD)
ChangeWindowMessageFilter_(73, #MSGFLT_ADD)          

; Next line makes the CanvasGadget() accept dropped files when the app is running with Administrator rights.
SetWindowLongPtr_(droptarget, #GWL_EXSTYLE, GetWindowLongPtr_(droptarget, #GWL_EXSTYLE) | #WS_EX_ACCEPTFILES)  

Repeat
  
  e = WaitWindowEvent()
  
  Select e
      
    Case  #WM_DROPFILES
      
      Define Dropped.l, Num.l, Index.l, Size.l, FileName.s
      Define PhraseFilename.s = ""
      
      Dropped.l = EventwParam()
      Num.l = DragQueryFile_(Dropped, - 1, "", 0) - 1
      
      For Index = 0 To Num
        
        Size.l = DragQueryFile_(Dropped, Index, 0, 0)
        FileName.s = Space(Size)
        DragQueryFile_(dropped, Index, FileName, Size + 1)
        MessageRequester("", "File ''" + FileName + "'' Dropped")
        
      Next
      
      DragFinish_(Dropped)
      
    Case  #PB_Event_CloseWindow : End
      
  EndSelect
  
ForEver
Post Reply