News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

drag and drop

Started by jckl, March 07, 2006, 12:54:05 PM

Previous topic - Next topic

jckl

can someone please get me started on drag and drop in a listview?

donkey

I have started a ListView tutorial that will include this, for now I will post the example code once I get home from work later today.
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

jckl

just to make sure you know what i mean... I want to be able to drag a file from the computer and drop it on the listview which then will use the filename. I know how to get the listview to allow files but i cant figure out what notification or message to look for.

donkey

I understand exactly what you mean, I just got home a few minutes ago and will slap something together shortly.
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

jckl


donkey

Here's a quick example I threw together, no commenting but here it goes..

  • Just used a very basic listview test bed I had kicking around

  • This example is in GoAsm syntax, I am too tired to translate to other assemblers right now

  • The listview has the WS_EX_ACCEPTFILES style set.

  • The listview needs to be subclassed in order to process the WM_DROPFILES message

  • DragQueryFile is called with -1 in order to obtain the number of files dropped

  • It is then called in a loop, displaying a message box with the name of each file.

  • Once the last file has been reached, DragFinish is called to close the drag handle.
Enjoy,

Donkey

[attachment deleted by admin]
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

jckl

thx for the example.. ill see if i can it workin like i want..

jckl

ok for those that want the masm format i am posting the code that i used to do the subclass and the code that creates my listview from the WM_CREATE message.


ListViewSubClass PROTO :HWND, :DWORD, :DWORD, :DWORD

.DATA
   ListViewClassName db "SysListView32",0

.DATA?
   hList dd ?
   pListviewProc dd ?

.CONST
   MAXSIZE equ 260


WndProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM

    cmp uMsg, WM_DESTROY
    jne @F
     Invoke PostQuitMessage,NULL
     jmp Return
    @@:
    cmp uMsg, WM_CREATE
    jne @F
     Invoke CreateWindowEx, WS_EX_CLIENTEDGE or WS_EX_ACCEPTFILES, addr ListViewClassName, NULL, LVS_REPORT or WS_CHILD or WS_VISIBLE, 0,0,493,318,hWnd, NULL, hInstance, NULL
     mov hList, eax
     mov eax, LVS_EX_FULLROWSELECT or LVS_EX_HEADERDRAGDROP or LVS_EX_GRIDLINES
     Invoke SendMessage, hList, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, eax
     Invoke InsertColumn

     Invoke SetWindowLong, hList, GWL_WNDPROC, offset ListViewSubClass
     mov pListviewProc,eax
     jmp Return
    @@:
     Invoke DefWindowProc,hWnd,uMsg,wParam,lParam
     ret
    Return:
     xor eax,eax
     ret
WndProc endp



ListViewSubClass proc hWnd:HWND, uMsg:DWORD, wParam:WPARAM, lParam:LPARAM
   LOCAL szDropFile[MAXSIZE]:DWORD

   cmp uMsg,WM_DROPFILES
   jne DEFPROC
    Invoke DragQueryFile,wParam,-1,ADDR szDropFile,MAXSIZE
    mov ebx,eax
   @@:
    sub ebx, 1
    js @F
    Invoke DragQueryFile,wParam,ebx,ADDR szDropFile,MAXSIZE
    Invoke MessageBox,NULL,ADDR szDropFile,ADDR AppName,MB_OK
    jmp @B
   @@:
    Invoke DragFinish,wParam
    xor eax,eax
    ret
   DEFPROC:
    Invoke CallWindowProc,pListviewProc,hWnd,uMsg,wParam,lParam
    ret
ListViewSubClass endp



Again thx donkey for the help :)

zcoder

Donky,
Do you happen to know how to
make it so you can drag to Windows
Explorer? or the desktop? I have tried
this I can drag to and from my listviews
and it works, but I can't find a window
in windows explorer that has the acceptfiles style
so it don't work.

I get the handle to the drop window where
the mouse was released then if that window is not a
exceptfile style one I get the parent of that window
to test it. I do this untill I find no more parents.

Zcoder....
Back in 1979, My computer ran so fine.
And there was no such thing,
As a Microsoft Crashed Machine.
http://zcoder.110mb.com
http://www.dietzel.com/partner/idevaffiliate.php?id=345_6  Free Domain Names

Gustav


to make it work with windows explorer you will need to use COM.
There exist some source samples for masm, but I cannot remember the names.

zcoder

Well this is kinda rud to me.

Example when I drag a file or files from windows Explorer
windows explorer sends me a WM_DROPFILES message
my app then uses DragQueryFile to first get the cound of files.

then uses DragQueryFile over and over to get each file name
all this comes from a DROPFILE structure.

This means that windows Explorer build a DROPFILE structre
with the list of files in it and then posted my app a WM_DROPFILES
message.

so I do the same to send files to explorer but it don't work
this would make you think I am sending the DROPFILE structure wrong
or building it wrong, but I can drop files to and from my apps that have
this ability to accept files using WM_DROPFILES and DragQueryFile API
method, so why is windows explorer sending it to my app this way
put expects me to send it using some other method??? like COM
or what ever???

this has me confued, as I can drag and drop files to other programs from my apps
using this method.
as I have done it without no problems.

Can someone explain this problem and how an app is to know what method to use
to send a list of files to another app? example how does the drag source app know
what the drop destination program will use to accept draged files?

Here is a program that drages and drops files it drags and drops to each window
and from windows explorer but not to explorer.

Zcoder....


[attachment deleted by admin]
Back in 1979, My computer ran so fine.
And there was no such thing,
As a Microsoft Crashed Machine.
http://zcoder.110mb.com
http://www.dietzel.com/partner/idevaffiliate.php?id=345_6  Free Domain Names

donkey

Hi ZCoder,

I did not know that, though it has some interesting applications. I am currently working on a listview tutorial (begginer to advanced) and will look into it. I have also use the IDropTarget interface in some applications that is a bit more flexible for drag and drop, I may end up posting some examples one day.
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

Gustav

I guess since explorer is able to list not only files and directories, it has to use a more general approach for drag & drop than just the file oriented DragQueryFile functions.

I did find the url of the COM example in the meantime:


www.japheth.de/Download/dragdrop.zip

zcoder

Gustav,
thanks for the example, it sure does do what I wanted.

Thing is, the example is done in a different programming style then my project is
example: you have to assemble it all into different obj's and then link them together
with your main app's obj, thats fine, but I do about the same exept I cheat.

While assembling into obj's I place them all in a lib, then assemle with my main
app. Well I took out everything that had to do with his examples main app
assembled them all into objs and then put them into a LIB when I use the
lib to use the functions I get dupclicate symbol error's and undefined proc
error's or other items missing.

So I worked on it for God nows how long to track down what was wrong
and I failed. So this example will most likely be hard for anyone to port to
another project style, I will do it, but it will take time as I have to study
this untill I know it inside and out, so I know what is needed and what
is not and to get these all into a lib for other to use.

Other then that it is what I was looking for.
Thanks alot for pointing me to the example.

Zcoder....   
Back in 1979, My computer ran so fine.
And there was no such thing,
As a Microsoft Crashed Machine.
http://zcoder.110mb.com
http://www.dietzel.com/partner/idevaffiliate.php?id=345_6  Free Domain Names

PBrennick

zcoder,
Read Japheth's site carefully.  He uses a very different windows.inc and you need to provide for that.  PM me if you need more help.  I converted another of his projects (Joe) to enable it to be built using Masm32 and it was not too hard.  Japheth does not use Masm32.

Paul
The GeneSys Project is available from:
The Repository or My crappy website