It is currently Wed Jun 19, 2013 10:20 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 12 posts ] 
Author Message
 Post subject: Howto get flename for DragnDrop from non PB window ?
PostPosted: Sun May 13, 2012 12:55 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Wed Feb 01, 2012 3:30 pm
Posts: 276
Location: Nottinghamshire UK
Hi to All

Could some kind soul show me or explain how to get filehandle for single and multiple files when drag n dropping files from a non PB gadget but instead from the windows picture folder to a listicon gadget !!!

Thanks in advance

Zebuddi. :D


Top
 Profile  
 
 Post subject: Re: Howto get flename for DragnDrop from non PB window ?
PostPosted: Sun May 13, 2012 1:30 pm 
Offline
PureBasic Protozoa
PureBasic Protozoa
User avatar

Joined: Fri Apr 25, 2003 3:08 pm
Posts: 3013
I know I'm no expert but this is how I basically do it in my document manager program and it works.

Code:
; Enable dragging and dropping files on the gadget list from outside the program

EnableGadgetDrop(#MyGadgetName, #PB_Drop_Files, #PB_Drag_Copy, 1)
 
 
; Copy filenames from Windows dropped on the gadget or window.
;
; Dragged files are always terminated with a CHR(10) character, even
; if there is only one in the buffer (I think)


Procedure GetDragNamesFromWindows()
  NumFiles.i = CountString(EventDropFiles(), Chr(10))     ; Count the number of filenames dropped
  FileNames.s = EventDropFiles()                          ; Get the string of filenames
  If NumFiles.i = 0 And FileNames.s <> ""                ; Only one file dragged
    Debug "Only one file found that was dropped"          ;
    Debug FileNames.s                                     ; Show the single filename
  ElseIf NumFiles.i > 0 And FileNames.s <> ""            ; More than one file was dropped
    Debug "More than one file was dropped"                ;
    For ListofNames.i = 1 To NumFiles.i                   ; Process the filenames
      Debug StringField(FileNames.s, ListofNames.i, Chr(10))
    Next  ListofNames.i                                   ;
  EndIf
EndProcedure


; In your event handling section, add this. it can be a gadget or a window, just modify your
; drag enabler statement above

Case #PB_Event_GadgetDrop
  Select GadgetID
    Case #MyGadgetName
      Select EventDropType()
        Case #PB_Drop_Files : GetDragNamesFromWindows()         ; Drag items from windows to a pb gadget or a window
      EndSelect
  EndSelect


Please excuse any misspellings or errors:)

_________________
Resist FaceBorg or have your ass laminated!


Top
 Profile  
 
 Post subject: Re: Howto get flename for DragnDrop from non PB window ?
PostPosted: Sun May 13, 2012 2:52 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Wed Feb 01, 2012 3:30 pm
Posts: 276
Location: Nottinghamshire UK
Hi Fangbeast

Thanks for quick reply, it seems that when the code is inserted into my app its not working, so as a test Ive rigged-up the code below but having the say problem, that is with draging an image file over the window/gadget i`m getting the windows symbol drag n drop not supported (the circle with diagonal line through it) which is the same with my app.

could you look through this example code and see if i`m having another Being thick day!!!

Code:
;{- Enumerations / DataSections
;{ Windows
Enumeration
   #Window_0
EndEnumeration
;}
;{ Gadgets
Enumeration
   #ListIcon_0
EndEnumeration
;}
;}

Procedure GetDragNamesFromWindows()
   NumFiles.i = CountString(EventDropFiles(), Chr(10))     ; Count the number of filenames dropped
   FileNames.s = EventDropFiles()                          ; Get the string of filenames
   If NumFiles.i = 0 And FileNames.s <> ""                ; Only one file dragged
      Debug "Only one file found that was dropped"          ;
      Debug FileNames.s                                     ; Show the single filename
   ElseIf NumFiles.i > 0 And FileNames.s <> ""            ; More than one file was dropped
      Debug "More than one file was dropped"                ;
      For ListofNames.i = 1 To NumFiles.i                   ; Process the filenames
         Debug StringField(FileNames.s, ListofNames.i, Chr(10))
      Next  ListofNames.i                                   ;
   EndIf
EndProcedure


Procedure OpenWindow_Window_0()
   If OpenWindow(#Window_0, 450, 200, 400, 400, "Window_0", #PB_Window_SystemMenu|#PB_Window_SizeGadget|#PB_Window_MinimizeGadget|#PB_Window_TitleBar)
      ListIconGadget(#ListIcon_0, 55, 50, 305, 300, "Gadget_0", 100, #PB_ListIcon_AlwaysShowSelection|#PB_ListIcon_GridLines|#PB_ListIcon_FullRowSelect)
      SendMessage_(GadgetID(#ListIcon_0), #LVM_SETCOLUMNWIDTH, 0, #LVSCW_AUTOSIZE_USEHEADER)
   EndIf
EndProcedure

OpenWindow_Window_0()
EnableGadgetDrop(#ListIcon_0, #PB_Drop_Files, #PB_Drag_Copy, 1)
;{- Event loop
Repeat
   Select WaitWindowEvent()
         ; ///////////////////
      Case #PB_Event_GadgetDrop
         Debug "in event drop"
         Select GadgetID
            Case #ListIcon_0
               Select EventDropType()
                  Case #PB_Drop_Files : GetDragNamesFromWindows()         ; Drag items from windows to a pb gadget or a window
               EndSelect
            Case #PB_Event_Gadget
               Select EventGadget()
                  Case #ListIcon_0
               EndSelect
               ; ////////////////////////
            Case #PB_Event_CloseWindow
               Select EventWindow()
                  Case #Window_0
                     CloseWindow(#Window_0)
                     Break
               EndSelect
         EndSelect
   EndSelect
ForEver
;
;}


Thanks a lot much appreciated


Zebuddi. :oops:


Top
 Profile  
 
 Post subject: Re: Howto get flename for DragnDrop from non PB window ?
PostPosted: Sun May 13, 2012 10:50 pm 
Offline
PureBasic Protozoa
PureBasic Protozoa
User avatar

Joined: Fri Apr 25, 2003 3:08 pm
Posts: 3013
I'm thicker than anybody and I won the belt 3 years running, ask anybody!!!

Your code works fine here (except your window won't close (grin)). Maybe it depends on how/where you added the code in your main program.

_________________
Resist FaceBorg or have your ass laminated!


Top
 Profile  
 
 Post subject: Re: Howto get flename for DragnDrop from non PB window ?
PostPosted: Mon May 14, 2012 12:10 am 
Offline
User
User

Joined: Sun Aug 14, 2011 10:32 pm
Posts: 16
The #PB_Event_CloseWindow is in the "Select GadgetID". :P

Other than that, it seems to work fine here.


Top
 Profile  
 
 Post subject: Re: Howto get flename for DragnDrop from non PB window ?
PostPosted: Mon May 14, 2012 12:33 am 
Offline
PureBasic Protozoa
PureBasic Protozoa
User avatar

Joined: Fri Apr 25, 2003 3:08 pm
Posts: 3013
Quote:
The #PB_Event_CloseWindow is in the "Select GadgetID". :P


Shhhhh, don't tell him everything!!! :):)

_________________
Resist FaceBorg or have your ass laminated!


Top
 Profile  
 
 Post subject: Re: Howto get flename for DragnDrop from non PB window ?
PostPosted: Mon May 14, 2012 4:48 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Wed Feb 01, 2012 3:30 pm
Posts: 276
Location: Nottinghamshire UK
Hi Fangbeast

closewindow was irrelevant was using my desktop when trying this and it was not recognizing any dragged objects as I described earlier.

Just trying it now on my laptop works perfect :shock: must have done something wrong also tired, the app its gonna be used in has a lot of condition
branching and xml like format documents, I swear i had made sure i had checked, double checked, and even triple checked,that i had complete them all only to find the results wrong! as i had missed 5 of them they were copied and pasted from the branching structure with only list elements to change and variables :shock:
if felt like the computer was playing tricks on me. :oops:

its now working on the laptop so will try later on the desktop.

again thanks for the code

Zebuddi. :D


Top
 Profile  
 
 Post subject: Re: Howto get flename for DragnDrop from non PB window ?
PostPosted: Mon May 14, 2012 5:00 pm 
Offline
Addict
Addict
User avatar

Joined: Tue Nov 13, 2007 12:42 pm
Posts: 1307
Location: Manchester, UK
The only thing I can see wrong with it is the CountString() and StringField() usage - if I drag and drop 5 files, the CountString correctly counts 4 linefeeds... but in your loop you aren't taking that into account, so the last file will always be missed.


Top
 Profile  
 
 Post subject: Re: Howto get flename for DragnDrop from non PB window ?
PostPosted: Mon May 14, 2012 10:05 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Wed Feb 01, 2012 3:30 pm
Posts: 276
Location: Nottinghamshire UK
OK its official "driving me bonkers"

Desktop "w7 x64 ultimate" same as laptop, laptop core i3 350m desktop q6600 @2.8ghz. copied laptop PB directory over to desktop and the appdata/roaming/pb dir to desktop so both identical. both x86 pb 4.61 b3

Code:
;{- Enumerations / DataSections
;{ Windows
Enumeration
   #Window_0
EndEnumeration
;}
;{ Gadgets
Enumeration
   #ListIcon_0
EndEnumeration
;}
;}

Procedure GetDragNamesFromWindows()
   NumFiles.i = CountString(EventDropFiles(), Chr(10))     ; Count the number of filenames dropped
   FileNames.s = EventDropFiles()                          ; Get the string of filenames
   If NumFiles.i = 0 And FileNames.s <> ""                ; Only one file dragged
      PrintN( "Only one file found that was dropped")          ;
      PrintN( FileNames.s   )                                  ; Show the single filename
   ElseIf NumFiles.i > 0 And FileNames.s <> ""            ; More than one file was dropped
      PrintN( "More than one file was dropped"  )             ;
      For ListofNames.i = 1 To NumFiles.i                   ; Process the filenames
         PrintN( StringField(FileNames.s, ListofNames.i, Chr(10)))
      Next  ListofNames.i                                   ;
   EndIf
EndProcedure


Procedure OpenWindow_Window_0()
   If OpenWindow(#Window_0, 450, 200, 400, 400, "Window_0", #PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_TitleBar|#PB_Window_ScreenCentered|#PB_Window_WindowCentered)
      ListIconGadget(#ListIcon_0, 55, 50, 305, 300, "Gadget_0", 100, #PB_ListIcon_AlwaysShowSelection|#PB_ListIcon_GridLines|#PB_ListIcon_FullRowSelect)
      ;SendMessage_(GadgetID(#ListIcon_0), #LVM_SETCOLUMNWIDTH, 0, #LVSCW_AUTOSIZE_USEHEADER)
   EndIf
EndProcedure

OpenWindow_Window_0()
EnableGadgetDrop(#ListIcon_0, #PB_Drop_Files, #PB_Drag_Copy, 1)
If OpenConsole()
   ;{- Event loop
   Repeat
      Select WaitWindowEvent()
            ; ///////////////////
         Case #PB_Event_GadgetDrop
            PrintN( "in event drop")
            Select GadgetID
               Case #ListIcon_0
                  Select EventDropType()
                     Case #PB_Drop_Files : GetDragNamesFromWindows()         ; Drag items from windows to a pb gadget or a window
                  EndSelect
            EndSelect
         Case #PB_Event_CloseWindow
            Select EventWindow()
               Case #Window_0
                  CloseConsole()
                  CloseWindow(#Window_0)
            EndSelect
      EndSelect
   ForEver
   
EndIf


both compile on each machine and give expected results.
on both machines (and opposite machines as to compiled executable`s were compiled on), Both results as expected.
But on the desktop in debug mode no play still shows icon (circle diagonal bar through it) now dragndrop available on the gadget. so identical code on both machines :!: but desktop not playing.
Desktop:
I`m using comodo internet security
1. defense switched off sill no play.
2. defense switch on all user setting cleared (PB in debug) requests access to com object, granted, lol still no play :cry:

In debug mode using PB 4.51 still no joy same results

Implemented said section i`m wanting (drag N drop) into the app i wanting to use it in and guess what no joy on either machine. :shock: :lol: :oops: :cry: :lol: :shock: :oops: :cry:

any Ideas folks

Zebuddi.


Top
 Profile  
 
 Post subject: Re: Howto get flename for DragnDrop from non PB window ?
PostPosted: Mon May 14, 2012 10:28 pm 
Offline
Addict
Addict
User avatar

Joined: Tue Nov 13, 2007 12:42 pm
Posts: 1307
Location: Manchester, UK
Hmmm if I try to drag and drop something that contains the Recycle Bin (either individually or in a group with valid files), then I get the "not allowed" sign.

If I use normal files, it works, whether it's XP or Win7.


Top
 Profile  
 
 Post subject: Re: Howto get flename for DragnDrop from non PB window ?
PostPosted: Tue May 15, 2012 2:05 am 
Offline
PureBasic Protozoa
PureBasic Protozoa
User avatar

Joined: Fri Apr 25, 2003 3:08 pm
Posts: 3013
Don't know if it's relevant or not but I had drag and drop problems initially (a few years ago now) when there were framegadgets drawn around the gadgets you were dropping to/from??

Do you have any such?

_________________
Resist FaceBorg or have your ass laminated!


Top
 Profile  
 
 Post subject: Re: Howto get flename for DragnDrop from non PB window ?
PostPosted: Wed May 16, 2012 12:49 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Wed Feb 01, 2012 3:30 pm
Posts: 276
Location: Nottinghamshire UK
Hi FangBeast
Yes i have frame gadgets. commented them all out tonight tried in debug mode, created exe still no joy, as usual after clearing Comodo request com access after dragging on listicon or window , which was granted and same result no joy.

To be honest im at a loss. The example i posted with the openconsole() works when compiled but not in debug mode :shock:

Zebuddi.

PS anyone else having trouble with DragNDrop ?


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 12 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye