EventQueue - Drag'n'Drop

BlitzMax Forums/BlitzMax Beginners Area/EventQueue - Drag'n'Drop

Dan(Posted 2016) [#1]
Hi, im absolute beginner in BlitzMax language.

I needed a code for drag and drop, so i have googled/searched a bit, and found following code:



The code is working ok, but the limit on dropped files is 255.
So on this page, they have suggested to:

Const QUEUESIZE=256
Const QUEUEMASK=QUEUESIZE-1
Global queue:TEvent[QUEUESIZE],queue_put,queue_get


Change the Queuesize, to increase the amount of files which can be dropped in.

After several try and error, with increasing and decreasing this Queuesize,
i finaly recognized that it doesnt accept every number.

The numbers which are accepted,have to be in the binary format eg:
%0000011111111 = 255+1, so the number 256 is accepted.
So, the next binary numbers acepted would be %0111111111, then %01111111111 and so on... (+1)

I now have this Queuesize changed to 16384.

And my Questions are:

Why were it set to 256 ? edit:(ok this is not a real question)
What is the advantage/disadvantage of having higher number than that ?
or does a Higher number affect the Program in a unwanted way ?


grable(Posted 2016) [#2]
I dont think it matters that much, all it would do is use memory. IE keeping more events live even after they have been processed.
But it would also allow for less missed events, if your sink was unable to eat them faster than the producers it could potentially roll over unprocessed ones if the queue is too small.

I never liked the way it can fill the entire event queue and potentially remove other valid events.
So i propose a better fix for this, search for WM_DROPFILES in win32maxguiex.bmx and replace it with this:
			Case WM_DROPFILES
				Local hdrop,pt[2],path$
				Local pbuffer:Short[MAX_PATH]
				Local i,n,l
				Local files$[]
				DragQueryPoint wp,pt
				n=DragQueryFileW(wp,$ffffffff,Null,0);
				For i=0 Until n
					l=DragQueryFileW(wp,i,pbuffer,MAX_PATH)
					path=String.FromShorts(pbuffer,l)
					files :+ [path]
				Next
				PostGuiEvent EVENT_WINDOWACCEPT,0,0,pt[0],pt[1],files
				DragFinish wp
And read it like this:
      Case EVENT_WINDOWACCEPT 
         Local filearray:String[] = String[](CurrentEvent.Extra)

EDIT: For compatibility with both versions you can do something like:
If String(CurrentEvent.Extra) Then
  .. old way
ElseIf String[](CurrentEvent.Extra) Then
  .. new way
EndIf



grable(Posted 2016) [#3]
And just a tip, dont use Null if what you mean is 0 (zero). Even if it converts to a 0 when used with integers its really bad form.
Null is meant for to be used for Objects and pointers.

Also, all variables are implicitly set to its Null value when declared. So no need to set it to 0, Null, "" unless you want to clarify some other part of the code.


Dan(Posted 2016) [#4]
ok, when i said beginner, then i really meant beginner.
Its kinda, i have just started Blitzmax and managed to understand how types
work in Bmax, compared to blitz3d type.

The code im using, is actually this one:



Which i wrote few days ago, in blitz3d, with acceptfiles.dll to get the drag'n'drop working,
But i kinda needed an Gui and some kind of lasting output, so that i can see if any error has occured.

So i thought, let give Bmax a try. but its alot different than bb3d.
I could use the winblitz3d addon, but that one has, aswell, an limit of dropped files.


Kryzon(Posted 2016) [#5]
That line at the top of your program, "Import MaxGUI.Drivers", is importing a BlitzMax module.
A BlitzMax module is like a library (as this term is used in computing). A module is a convenient way for you to organise code that can be reused often and provides a certain functionality.
You can write your modules with plain BlitzMax code or import C and C++ files.

Grable is proposing that you modify the source code of the part of that MaxGUI module that handles the drag and dropping and emits the corresponding event.
If you know how to modify the source of a module you can make it do whatever you want, like instead of emitting 256 maximum events, emit a single event with all the filenames as items in a single string array, like I mentioned below (EDIT: It's precisely what grable's example above does):
http://www.blitzbasic.com/Community/posts.php?topic=105480#1285247


grable(Posted 2016) [#6]
Well you managed to change the size of the event queue, doing what i suggested above isnt much different.

The file in question is BlitzMax/mod/maxgui.mod/win32maxguiex.mod/win32maxguiex.bmx

There is only one instance of WM_DROPFILES, all you have to do is replace ALL the code in that Case with the one i supplied.
They both start and end with the same lines, so identifying it sholdnt post a problem.


Dan(Posted 2016) [#7]
changing lines (copying them and pasting into their right place) is not a problem,
but using the code which i havent worked out, yet, is.

I have changed the lines, as suggested, but now,
(in this example (which is not my code btw)) i cant manage to do anything with it ... after the change.

btw, my knowledge in programming is based on basic language (c64,amiga,pc) and mirc scripting (no oop part from blitzB. types).

C i havent touched yet.


grable(Posted 2016) [#8]
The only change needed is to treat the result of EventExtra() as an array instead of a string.




Kryzon(Posted 2016) [#9]
If you modify any module you need to rebuild it to commit your changes.
Modules are always in a pre-compiled form when they're imported by your programs.

To build a module you'll use the Program->Build Modules menu in the BlitzMax IDE. However, for this option to be available you need to have installed MinGW, otherwise that option will be greyed out.

There's a guide on installing MinGW here:
http://www.blitzbasic.com/Community/posts.php?topic=105745

Once it's installed and you run the IDE to see that the Build Modules option is active (or that Help->About MaxIDE shows a valid MinGW path), you can modify BlitzMax\mod\maxgui.mod\win32maxguiex.mod\win32maxguiex.bmx in the way that grable showed in post #2 above, save that file then hit Build Modules so these changes are comitted, then use the method he showed in post #8, casting the EventExtra() object to a string array, so you have all filenames in a single array that you can iterate and do what you want with them.
Every time you modify a source file from a module, that module is tagged as "dirty". When you hit Build Modules BlitzMax will rebuild all modules that were "dirty" (modified).


Dan(Posted 2016) [#10]
Mingw is installed,and building is working.
but the example, which grable pasted, just above was not working.


Iv just seen, that i had double
Case WM_DROPFILES in this module (havent commented that out), now at least drag and drop is recognized,
and strange, that the array (binary[]) is out of index has just occured ?!?


Ok its working now. Thanks for the help !

edit:
Or ... sigh, unhandled exception has occured

Ok, Drag and Drop works as intended ! Thanks again !