Drag and drop file in windows 8.1 possible?

Just starting out? Need help? Post your questions and find answers here.
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Re: Drag and drop file in windows 8.1 possible?

Post by Sparkie »

Fangles, download this exe and see what happens. Here is the source:

Code: Select all

EnableExplicit

#Window = 0

Enumeration    ; Gadgets
  #TargetFiles
EndEnumeration

Define Event, Count, i
Define Files$

If OpenWindow(#Window, 0, 0, 800, 600, "Drag & Drop", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
  ; Create the target gadgets
  ListIconGadget(#TargetFiles, 5, 5, 7900, 590, "Drop Files here", 250)

 
  ; Now enable the dropping on the target gadgets
  EnableGadgetDrop(#TargetFiles,    #PB_Drop_Files,   #PB_Drag_Copy)
 
  Repeat
    Event = WaitWindowEvent()
       
    ; Drop event on the target gadgets, receive the dropped data
    ;
    If Event = #PB_Event_GadgetDrop
      Select EventGadget()
        Case #TargetFiles
          Files$ = EventDropFiles()
          Count  = CountString(Files$, Chr(10)) + 1
          For i = 1 To Count
            AddGadgetItem(#TargetFiles, -1, StringField(Files$, i, Chr(10)))
          Next i
      EndSelect
   
    EndIf
   
  Until Event = #PB_Event_CloseWindow
EndIf
End
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4789
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Re: Drag and drop file in windows 8.1 possible?

Post by Fangbeast »

Sparkie wrote:Fangles, download this exe and see what happens. Here is the source:

Code: Select all

EnableExplicit

#Window = 0

Enumeration    ; Gadgets
  #TargetFiles
EndEnumeration

Define Event, Count, i
Define Files$

If OpenWindow(#Window, 0, 0, 800, 600, "Drag & Drop", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
  ; Create the target gadgets
  ListIconGadget(#TargetFiles, 5, 5, 7900, 590, "Drop Files here", 250)

 
  ; Now enable the dropping on the target gadgets
  EnableGadgetDrop(#TargetFiles,    #PB_Drop_Files,   #PB_Drag_Copy)
 
  Repeat
    Event = WaitWindowEvent()
       
    ; Drop event on the target gadgets, receive the dropped data
    ;
    If Event = #PB_Event_GadgetDrop
      Select EventGadget()
        Case #TargetFiles
          Files$ = EventDropFiles()
          Count  = CountString(Files$, Chr(10)) + 1
          For i = 1 To Count
            AddGadgetItem(#TargetFiles, -1, StringField(Files$, i, Chr(10)))
          Next i
      EndSelect
   
    EndIf
   
  Until Event = #PB_Event_CloseWindow
EndIf
End
No drag and drop, circle with diagonal line through it.

I still blame srod's festering, used sheep!!
Amateur Radio/VK3HAF, (D-STAR/DMR and more), Arduino, ESP32, Coding, Crochet
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Re: Drag and drop file in windows 8.1 possible?

Post by Sparkie »

Just a few ideas I've come across on the net in regards to your drag drop issue:

Have you tried disabling various items in your Win startup?
What are your UAC settings?
Create a new Win account and try drag drop from the new account.
Are you using 3rd party desktop manager type apps?
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: Drag and drop file in windows 8.1 possible?

Post by srod »

Try the following fangles. Drag from explorer to the main window. If it works then the file names should be shown in the debugger.

This uses OLE drop handling which, behind the scenes, should be the way the PB drag/drop lib is doing it. The other possibility is already covered by one of Rashad's posts (#WM_DROPFILES) and you had that working.

If this code works then the fault is definitely with PB's lib.

I think it more likely though that the code will fail and the fault lies elsewhere.

Code: Select all

Structure _IDropTarget
  *vTable
  refCount.i
  blnAllowDrop.i
EndStructure

OleInitialize_(0)

#Window = 0

If OpenWindow(#Window, 0, 0, 800, 600, "Drag & Drop", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
  
  *this._IDropTarget = AllocateMemory(SizeOf(_IDropTarget))
  *this\vTable = ?VTable_IDropTarget
  RegisterDragDrop_(WindowID(#Window), *this) ; declare our gadget as a potential drop target
 
  Repeat
    Event = WaitWindowEvent()
  Until Event = #PB_Event_CloseWindow
EndIf
End


;-Drop enable function.

;-Internal functions.

;/////////////////////////////////////////////////////////////////////////////////
;*pdwEffect guaranteed to be non-null.
Procedure DropTarget_SetEffects(grfKeyState, *pdwEffect.LONG)
  If grfKeyState&#MK_CONTROL
    If *pdwEffect\l & #DROPEFFECT_COPY
      *pdwEffect\l = #DROPEFFECT_COPY
    Else
      *pdwEffect\l = #DROPEFFECT_NONE
    EndIf
  ElseIf *pdwEffect\l & #DROPEFFECT_MOVE
    *pdwEffect\l = #DROPEFFECT_MOVE
  Else
    *pdwEffect\l = #DROPEFFECT_NONE
  EndIf
EndProcedure
;/////////////////////////////////////////////////////////////////////////////////



;-iDropTarget methods.

;/////////////////////////////////////////////////////////////////////////////////
Procedure.i DropTarget_QueryInterface(*this._IDropTarget, iid, *ppvObject.INTEGER)
  Protected result
  If CompareMemory(iid, ?IID_IUnknown, SizeOf(CLSID)) Or CompareMemory(iid, ?IID_IDropTarget, SizeOf(CLSID))
    *ppvObject\i = *this
    *this\refCount + 1
    result = #S_OK
  Else
    *ppvObject\i=0
    result = #E_NOINTERFACE
  EndIf
  ProcedureReturn result
EndProcedure
;/////////////////////////////////////////////////////////////////////////////////


;/////////////////////////////////////////////////////////////////////////////////
Procedure.i DropTarget_AddRef(*this._IDropTarget)
  *this\refCount + 1
  ProcedureReturn 0
EndProcedure
;/////////////////////////////////////////////////////////////////////////////////


;/////////////////////////////////////////////////////////////////////////////////
Procedure.i DropTarget_Release(*this._IDropTarget)
  Protected result
  *this\refCount - 1
  If *this\refCount > 0
    result = *this\refCount
  Else
    FreeMemory(*this)
  EndIf
  ProcedureReturn result
EndProcedure
;/////////////////////////////////////////////////////////////////////////////////


;/////////////////////////////////////////////////////////////////////////////////
Procedure.i DropTarget_DragEnter(*this._IDropTarget, dataObject.IDataobject, grfKeyState, pt.q, *pdwEffect.LONG)
  Protected result=#S_OK, thisFormatEtc.FORMATETC
  *this\blnAllowDrop = #False
  If *pdwEffect = 0
    result = #E_INVALIDARG
  Else
    ;Check to see if the data object supports our text format.
      With thisFormatEtc
        \cfFormat = #CF_HDROP
        \dwAspect = #DVASPECT_CONTENT
        \lindex = -1
        \tymed = #TYMED_HGLOBAL
      EndWith
      If dataObject\QueryGetData(thisFormatEtc) = #S_OK
        *this\blnAllowDrop = #True
        DropTarget_SetEffects(grfKeyState, *pdwEffect)
      Else
        *pdwEffect\l = #DROPEFFECT_NONE
      EndIf
  EndIf
  ProcedureReturn result
EndProcedure
;/////////////////////////////////////////////////////////////////////////////////


;/////////////////////////////////////////////////////////////////////////////////
Procedure.i DropTarget_DragOver(*this._IDropTarget, grfKeyState, pt.q, *pdwEffect.LONG)
  Protected result = #S_OK
  If *pdwEffect = 0
    result = #E_INVALIDARG
  Else
    If *this\blnAllowDrop
      DropTarget_SetEffects(grfKeyState, *pdwEffect)
    Else
      *pdwEffect\l = #DROPEFFECT_NONE
    EndIf
  EndIf
  ProcedureReturn result
EndProcedure
;/////////////////////////////////////////////////////////////////////////////////


;/////////////////////////////////////////////////////////////////////////////////
Procedure.i DropTarget_DragLeave(*this._IDropTarget)
  ProcedureReturn #S_OK
EndProcedure
;/////////////////////////////////////////////////////////////////////////////////


;/////////////////////////////////////////////////////////////////////////////////
;*pdwEffect\l contains the original combination of effects.
Procedure.i DropTarget_Drop(*this._IDropTarget, Dataobject.IDataobject, grfKeyState, pt.q, *pdwEffect.LONG)
  Protected result = #S_OK, anchWnd, tempAnchWnd, thisFormatEtc.FORMATETC, thisStgMedium.STGMEDIUM, *ptrChar.CHARACTER
  If *pdwEffect = 0
    result = #E_INVALIDARG
  ElseIf *this\blnAllowDrop
    ;Set effects.
      DropTarget_SetEffects(grfKeyState, *pdwEffect)
    ;Do we proceed?
      If *pdwEffect\l <> #DROPEFFECT_NONE
        ;Retrieve the data. We have previously checked for valid data.
        ;Windows automatically converts between #CF_TEXT and #CF_UNICODETEXT as appropriate.
          With thisFormatEtc
            \cfFormat = #CF_HDROP
            \dwAspect = #DVASPECT_CONTENT
            \lindex = -1
            \tymed = #TYMED_HGLOBAL
          EndWith
          If Dataobject\GetData(thisFormatEtc, thisStgMedium) = #S_OK
            If thisStgMedium\hGlobal ;Only prudent to be sure here!
              buffer = AllocateMemory(1024)
              If buffer
                numFiles = DragQueryFile_(thisStgMedium\hGlobal, -1, 0, 0)
                For i = 0 To numFiles-1
                  DragQueryFile_(thisStgMedium\hGlobal, i, buffer, 1024)
                  Debug PeekS(buffer)
                Next
                FreeMemory(buffer)
              EndIf
            EndIf
            ReleaseStgMedium_(thisStgMedium)          
          Else
            result = #E_FAIL
          EndIf
      EndIf
  EndIf
  ProcedureReturn result
EndProcedure
;/////////////////////////////////////////////////////////////////////////////////


DataSection 
  VTable_IDropTarget:
   Data.i @DropTarget_QueryInterface()
   Data.i @DropTarget_AddRef()
   Data.i @DropTarget_Release()
   Data.i @DropTarget_DragEnter()
   Data.i @DropTarget_DragOver()
   Data.i @DropTarget_DragLeave()
   Data.i @DropTarget_Drop()

  CompilerIf Defined(IID_IUnknown, #PB_Label) = 0
    IID_IUnknown:   ;"{00000000-0000-0000-C000-000000000046}"
      Data.l $00000000
      Data.w $0000,$0000
      Data.b $C0,$00,$00,$00,$00,$00,$00,$46 
  CompilerEndIf

  CompilerIf Defined(IID_IDropTarget, #PB_Label) = 0
    IID_IDropTarget:  ;{00000122-0000-0000-C000-000000000046}
      Data.l $00000122
      Data.w $0000,$0000
      Data.b $C0,$00,$00,$00,$00,$00,$00,$46
  CompilerEndIf
EndDataSection
Last edited by srod on Fri Feb 14, 2014 10:34 pm, edited 1 time in total.
I may look like a mule, but I'm not a complete ass.
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Re: Drag and drop file in windows 8.1 possible?

Post by Sparkie »

Fangles, which came first on your PC, PB 5.21 or Win 8.1?

If PB 5.21 was first, try re-installing (PB 5.21).
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4789
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Re: Drag and drop file in windows 8.1 possible?

Post by Fangbeast »

Have you tried disabling various items in your Win startup?
Everything except motherboard drivers, ADSL statistics and backup program.
What are your UAC settings?
"Always Notify"
Create a new Win account and try drag drop from the new account.
Righty ho, will do that today.
Are you using 3rd party desktop manager type apps?
No, never saw the need for them.
Amateur Radio/VK3HAF, (D-STAR/DMR and more), Arduino, ESP32, Coding, Crochet
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4789
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Re: Drag and drop file in windows 8.1 possible?

Post by Fangbeast »

Sparkie wrote:Fangles, which came first on your PC, PB 5.21 or Win 8.1?

If PB 5.21 was first, try re-installing (PB 5.21).
Totally clean install of an upgrade window 8 and then to 8.1. Found a way *not* to upgrade windows 7 to 8 but actually do a clean install.

Then installed PB 5.21.
Amateur Radio/VK3HAF, (D-STAR/DMR and more), Arduino, ESP32, Coding, Crochet
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4789
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Re: Drag and drop file in windows 8.1 possible?

Post by Fangbeast »

If this code works then the fault is definitely with PB's lib.

I think it more likely though that the code will fail and the fault lies elsewhere.
Yes, the code failed darn it.
Amateur Radio/VK3HAF, (D-STAR/DMR and more), Arduino, ESP32, Coding, Crochet
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Re: Drag and drop file in windows 8.1 possible?

Post by Sparkie »

Running out of ideas here Fangles....how about restarting IDE and Run as Administrator?
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4789
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Re: Drag and drop file in windows 8.1 possible?

Post by Fangbeast »

Sparkie wrote:Running out of ideas here Fangles....how about restarting IDE and Run as Administrator?
Tried that too Sir Sparkie. Thanks for sticking with me thus far. Windows 8/8.1 has done some funny things to be, especially on the 64 bit version. Don't have a 32 bit version handy to test unfortunately.

Thanks to srod as well for taking the time to stop rotating sheep and help. I mean, the sheep are a full time occupation for him (apart from deliberately festering and steaming underpants of course)!

I bet that the fix will be a simple one that I haven't thought of because I am very stupid these days (Shaddap LuciferSD!!).

Maybe I have to go back to windows 7 for now as it works there and I need to finish this code, or simply adopt RASHAD's kind solution for now.
Amateur Radio/VK3HAF, (D-STAR/DMR and more), Arduino, ESP32, Coding, Crochet
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Re: Drag and drop file in windows 8.1 possible?

Post by Sparkie »

What other things are not working properly for you on Win 8.1 Fangles?
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
User avatar
Kuron
Addict
Addict
Posts: 1626
Joined: Sat Oct 17, 2009 10:51 pm
Location: Pacific Northwest

Re: Drag and drop file in windows 8.1 possible?

Post by Kuron »

Drag and drop file in windows 8.1 possible?
Yes, but you need to manually set proper permissions for your applications due to the security features in Windows 8. More info can be found here on how to properly set up your permissions for each app.

http://www.c-sharpcorner.com/UploadFile ... windows-8/
http://forum.thewindowsclub.com/windows ... lders.html
http://www.mladengradev.com/en/how-to-g ... windows-8/
Best wishes to the PB community. Thank you for the memories. ♥️
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Re: Drag and drop file in windows 8.1 possible?

Post by Sparkie »

Well I never had to manually set permissions but certainly worth a try. I would first try hitting the [Esc] key to see if that fix works for you Fangles. :wink:

Nice find Kuron. 8)
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4946
Joined: Sun Apr 12, 2009 6:27 am

Re: Drag and drop file in windows 8.1 possible?

Post by RASHAD »

It looks that Drag n Drop in windows 8.1 is a nightmare for many users (see the web)
Fangles, can you run (Programs and Features) and post a list of your installed programs ?
Someone had a problem with a program called Fence for example
Maybe one of your software causing the problem

And take it easy :)
Egypt my love
User avatar
Kuron
Addict
Addict
Posts: 1626
Joined: Sat Oct 17, 2009 10:51 pm
Location: Pacific Northwest

Re: Drag and drop file in windows 8.1 possible?

Post by Kuron »

Sparkie wrote:Nice find Kuron. 8)
Sadly, it is a well-known issue. I am sorry for not seeing this thread before now, or I would have posted the info sooner. I generally do NOT read this forum category and clicked on it by mistake tonight. But one of the three links will usually sort most people out.

I took the easy way out and no longer provide drag and drop functionality in any of my software. :mrgreen:
Best wishes to the PB community. Thank you for the memories. ♥️
Post Reply