Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

WM_DROPFILES

318 views
Skip to first unread message

David Webber

unread,
Nov 15, 2007, 4:24:31 PM11/15/07
to
I have a list box which lists files, and I thought it would be nice to come
into the 21st century by letting folk drag and drop more files onto it.
But I'm having problems making it work.

I call DragAcceptFiles( TRUE ) during the OnInitDialog() of the parent
dialogue (actually a property page). I am rewarded by the mouse cursor
changing appropriately when I drag a file over the list box.

And then having

class CMyListBox : public CListBox
{
};

I include for the moment:

BEGIN_MESSAGE_MAP( CMyListBox, CListBox )
ON_WM_DROPFILES()
END_MESSAGE_MAP()


void CMyListBox::OnDropFiles( HDROP hDropInfo )
{
AfxMessageBox( _T("Hello"), MB_OK );

CListBox::OnDropFiles( hDropInfo );
return;
}

I put the message box in there because I didn't expect it to work in the
debug code as drag and drop seems not to work there (under Vista at least).
But I'm not getting the message in a release build either.

Any ideas why not?

[There seems to be no such thing as ON_WM_DROPFILES_REFLECT() and so I
assume the control *should* be getting the message!]

Dave
--
David Webber
Author of 'Mozart the Music Processor'
http://www.mozart.co.uk
For discussion/support see
http://www.mozart.co.uk/mozartists/mailinglist.htm


AliR (VC++ MVP)

unread,
Nov 15, 2007, 4:48:54 PM11/15/07
to
Try calling the listbox's DragAcceptFile() in the OnInitDialog.

m_ListBox.DragAcceptFile();

AliR.


"David Webber" <da...@musical-dot-demon-dot-co.uk> wrote in message
news:O4$3438JI...@TK2MSFTNGP06.phx.gbl...

AliR (VC++ MVP)

unread,
Nov 15, 2007, 4:50:32 PM11/15/07
to
I forgot to say, that I have never heard of drag and drop not working in
debug mode.

AliR.


"AliR (VC++ MVP)" <Al...@online.nospam> wrote in message
news:od3%i.5560$852....@newssvr17.news.prodigy.net...

David Webber

unread,
Nov 15, 2007, 6:26:35 PM11/15/07
to

"AliR (VC++ MVP)" <Al...@online.nospam> wrote in message
news:Xe3%i.5561$852....@newssvr17.news.prodigy.net...

>I forgot to say, that I have never heard of drag and drop not working in
>debug mode.

It seems to be a feature of Vista. I have drag and drop to my main frame
window to open files in an MDI program. It has always worked, but it
doesn't work in debug mode under Vista. (No WM_DROPFILES message arrives.)

I think someone else asked about he here too, a while back.

David Webber

unread,
Nov 15, 2007, 6:24:22 PM11/15/07
to

"AliR (VC++ MVP)" <Al...@online.nospam> wrote in message
news:od3%i.5560$852....@newssvr17.news.prodigy.net...

> Try calling the listbox's DragAcceptFile() in the OnInitDialog.
>
> m_ListBox.DragAcceptFile();

Sorry - I wasn't clear - that's exactly what I do.

Tom Serface

unread,
Nov 15, 2007, 6:54:54 PM11/15/07
to
Hi Dave,

The problem I've seen is that I have to run Explorer and my application as
the same privileges or else have UAC off. If I run my application from
Visual Studio it starts up as Administrator (since I use David Ching's great
suggestion to change the shortcut privileges). If I simply start the
Explorer I can't drag and drop files, but if I right click and say "Start as
administrator" it works fine. I think this is a klunky interface for Vista,
but it is easy to work around.

Tom

"David Webber" <da...@musical-dot-demon-dot-co.uk> wrote in message

news:%234FfB89...@TK2MSFTNGP06.phx.gbl...

David Ching

unread,
Nov 15, 2007, 9:43:13 PM11/15/07
to
"Tom Serface" <tom.n...@camaswood.com> wrote in message
news:CB116214-75F7-4285...@microsoft.com...

> Hi Dave,
>
> The problem I've seen is that I have to run Explorer and my application as
> the same privileges or else have UAC off. If I run my application from
> Visual Studio it starts up as Administrator (since I use David Ching's
> great suggestion to change the shortcut privileges). If I simply start
> the Explorer I can't drag and drop files, but if I right click and say
> "Start as administrator" it works fine. I think this is a klunky
> interface for Vista, but it is easy to work around.
>
> Tom
>

Yes, with UAC on, it prohibits you dropping a file into an elevated app
(which your app is, since it was started by the elevated Visual Studio) that
is sourced from a non-elevated app (which Explorer is). I guess MS thought
most apps would be running non-elevated, so drag and drop would work amongst
them. I would disable UAC to see if drag and drop works.

Instead of calling


CMyDialog::OnInitDialog()
{
m_ListBox.DragAcceptFile();
...
}

call

CMyDialog::OnInitDialog()
{
DragAcceptFiles();
}


and call

void CMyDialog::OnDestroy()
{
CDialog::OnDestroy();

// Not sure if this is necessary, but it prevents bogus drop messages after
we are gone
DragAcceptFiles(FALSE);
}


You may also want to handle:

// The system calls this to obtain the cursor to display while the user
drags
// the minimized window.
HCURSOR CMyDialog::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}


-- David


Tom Serface

unread,
Nov 15, 2007, 10:46:33 PM11/15/07
to
I'm actually fine. I just try to run my applications like my users would
use it (with UAC on). I hate getting surprises after it's released. If I
run the release version without starting it from VS it works just as
expected.

Tom

"David Ching" <d...@remove-this.dcsoft.com> wrote in message
news:3t7%i.7457$TR5....@nlpi061.nbdc.sbc.com...

David Webber

unread,
Nov 16, 2007, 3:57:10 AM11/16/07
to
Thanks Chaps,

It turns out I was doing everything right - calling DragAcceptFiles(TRUE)
for the list control and having the list control respond to WM_DROPFILES.

[I'll put in a DragAcceptFiles(FALSE) before the window is destroyed; I'm
not sure it will make a difference, but my gut feeling always goes with
tidying things up neatly.]

It was the effect of UAC which I didn't understand properly. (And I
thought drag and drop worked when I build the release version and run with
Ctrl+F5 but in fact it doesn't. So that must be running with elevated
privileges too.) Anyway if I run the release version outside of Visual
studio, then everything works properly.

Other comments:

I don't seem to need CMyDialog::OnQueryDragIcon() as the cursor works fine
(even with UAC stopping the WM_DROPFILES from arriving). I assume the base
class is handling it.

I *do* like working with UAC switched on because I give support on anything
to do with running my program and sometimes the answer is "This is Mr
Gates's fault, not mine" but I still like to help out. Sooner or later, as
Vista becomes more widespread, more people are going to fall over UAC and I
want to have been there first :-)

David Webber

unread,
Nov 16, 2007, 4:07:39 AM11/16/07
to

"Tom Serface" <tom.n...@camaswood.com> wrote in message
news:CB116214-75F7-4285...@microsoft.com...

>....If I simply start the Explorer I can't drag and drop files, but if I
>right click and say "Start as administrator" it works fine....

That seems to be a useful way of testing drag and drop during development.

But how do you do it? [I get no "Start as administrator" when I right
click on "Computer".]

So I had this wonderful idea of creating a shortcut to a folder, and going
into Properties/Shortcut/Advanced. There's a check box there labelled "run
as administrator" but it is disabled :-(

I obviously have something to learn about Vista. :-(

David Ching

unread,
Nov 16, 2007, 7:00:47 AM11/16/07
to
"David Webber" <da...@musical-dot-demon-dot-co.uk> wrote in message
news:eTRYRBDK...@TK2MSFTNGP05.phx.gbl...

> That seems to be a useful way of testing drag and drop during development.
>
> But how do you do it? [I get no "Start as administrator" when I right
> click on "Computer".]
>
> So I had this wonderful idea of creating a shortcut to a folder, and going
> into Properties/Shortcut/Advanced. There's a check box there labelled
> "run as administrator" but it is disabled :-(
>
> I obviously have something to learn about Vista. :-(
>

We all do! I test D&D into an elevated app by using an elevated instance of
Total Commander (a Norton Commander replacement) instead of Explorer. You
can drag and drop a file from there, no problem, and the interface is much
more productive than Explorer,IMO.

-- David


David Webber

unread,
Nov 16, 2007, 7:34:38 AM11/16/07
to

"David Ching" <d...@remove-this.dcsoft.com> wrote in message
news:PDf%i.20892$Pv2....@newssvr23.news.prodigy.net...

>> I obviously have something to learn about Vista. :-(
>>
>
> We all do! I test D&D into an elevated app by using an elevated instance
> of Total Commander (a Norton Commander replacement) instead of Explorer.
> You can drag and drop a file from there, no problem, and the interface is
> much more productive than Explorer,IMO.

Well I don't have "total commander" so I have been keeping a folder open on
my WinRel folder (still called that long after MFC changed to calling it
"Release") and running by double clicking there, with the old fashioned
method of checking that all is ok with temporary message boxes.
Golden-oldie debugging in fact :-)

David Ching

unread,
Nov 16, 2007, 10:11:07 AM11/16/07
to
"David Webber" <da...@musical-dot-demon-dot-co.uk> wrote in message
news:eaWKu$EKIHA...@TK2MSFTNGP05.phx.gbl...

>
> Well I don't have "total commander" so I have been keeping a folder open
> on my WinRel folder (still called that long after MFC changed to calling
> it "Release") and running by double clicking there, with the old fashioned
> method of checking that all is ok with temporary message boxes.
> Golden-oldie debugging in fact :-)
>

Right, but this doesn't help you debug drag and drop problems in the IDE
debugger when UAC is enabled. I suppose you could launch your app by
double-clicking in the WinRel folder, then attaching the debugger to the
running process, though.

Cheers,
David


Tom Serface

unread,
Nov 16, 2007, 11:13:23 AM11/16/07
to
BTW, "Run as administrator", on my system is 3rd item from the top of the
menu and has a little shield next too it that looks like the firewall icon.

Tom

"David Webber" <da...@musical-dot-demon-dot-co.uk> wrote in message

news:eTRYRBDK...@TK2MSFTNGP05.phx.gbl...

Tom Serface

unread,
Nov 16, 2007, 11:12:28 AM11/16/07
to
Sorry, it says "Run as administrator".

Tom

"David Webber" <da...@musical-dot-demon-dot-co.uk> wrote in message

news:eTRYRBDK...@TK2MSFTNGP05.phx.gbl...

David Webber

unread,
Nov 16, 2007, 1:42:24 PM11/16/07
to

"Tom Serface" <tom.n...@camaswood.com> wrote in message
news:46FB33EC-FFC0-469E...@microsoft.com...

> Sorry, it says "Run as administrator".

Had it been there, I'd have guessed that was it. :-)

I actually get this with right clicking on .bat files I have written (some
of which need it as they run Visual Studio to compile things).

But it isn't there when right clicking on "Computer" :-(

I notice various applications have put a menu item there (which I didn't
really want) like "Browse with paint shop pro" and "Compile to HTML help
with FAR" - I wonder if one of them has buggered the "Run as
administrator"????

Tom Serface

unread,
Nov 16, 2007, 2:43:29 PM11/16/07
to
Ah, you know... what I always do when I install a new Windows is go to the
Start/All Programs/Accessories tab and right click drag a copy of Windows
Explore icon to the quick launch bar so it's easy to get to. That's what I
am right clicking on, not the Computer one. So, at the bottom of my screen
I have icons for:

[Show Desktop] [That not so useful 3D show windows thing] [Windows Explorer]
[Windows Mail] [etc.]

You can't start it with the Windows+E key and get the same effect.

Sorry, I should have mentioned that before. What I'm really clicking on is
the Windows Explorer icon. Looks like a little monitor in Vista, but
previous versions or Windows had a little yellow folder.

Tom

"David Webber" <da...@musical-dot-demon-dot-co.uk> wrote in message

news:eC4k$BIKIH...@TK2MSFTNGP05.phx.gbl...

David Webber

unread,
Nov 17, 2007, 4:23:27 AM11/17/07
to

"Tom Serface" <tom.n...@camaswood.com> wrote in message
news:D2F92107-F917-4EEC...@microsoft.com...

> Ah, you know... what I always do when I install a new Windows is go to the
> Start/All Programs/Accessories tab and right click drag a copy of Windows

> Explore icon to the quick launch bar so it's easy to get to....

Aha! I do exactly the same thing with "Computer" for the same reason :-)

However now, following your message, I have explorer there as well, and I
can right click and "run as administrator"...

..but I still apparently get no WM_DROPFILES when I drag and drop from it
into my app launched from within Visual Studio :-(

Tom Serface

unread,
Nov 17, 2007, 12:24:34 PM11/17/07
to
Hmmm. That is curious. D&D works for me for both release and debug builds.
I wonder if we're just doing it different ways. I drag and drop into a
dialog. I have a handler for the message:

ON_WM_DROPFILES()

and I've called:

DragAcceptFiles();

In OnInitDialog()

My handler looks like this:

void CMyDialog::OnDropFiles(HDROP hDropInfo)
{
CDialog::OnDropFiles(hDropInfo);

// Find how many files we are working with
UINT nFiles = ::DragQueryFile(hDropInfo, (UINT) -1, NULL, 0);
for(UINT nThisFile = 0; nThisFile < nFiles; ++nThisFile) {
TCHAR szFile[_MAX_PATH];
::DragQueryFile(hDropInfo, nThisFile, szFile, _countof(szFile));
// Do something with file
}
::DragFinish(hDropInfo);
}

Are you doing it the same way?

Tom

"David Webber" <da...@musical-dot-demon-dot-co.uk> wrote in message

news:ukXGRuPK...@TK2MSFTNGP03.phx.gbl...

David Webber

unread,
Nov 17, 2007, 1:45:52 PM11/17/07
to

"Tom Serface" <tom.n...@camaswood.com> wrote in message
news:1447A1A1-DFD3-4B4D...@microsoft.com...

Hello Tom, it's very god ogf you to go into this detail!

> Hmmm. That is curious. D&D works for me for both release and debug
> builds. I wonder if we're just doing it different ways. I drag and drop
> into a dialog. I have a handler for the message:
>
> ON_WM_DROPFILES()
>
> and I've called:
>
> DragAcceptFiles();
>
> In OnInitDialog()
>
> My handler looks like this:
>
> void CMyDialog::OnDropFiles(HDROP hDropInfo)
> {
> CDialog::OnDropFiles(hDropInfo);
>
> // Find how many files we are working with
> UINT nFiles = ::DragQueryFile(hDropInfo, (UINT) -1, NULL, 0);
> for(UINT nThisFile = 0; nThisFile < nFiles; ++nThisFile) {
> TCHAR szFile[_MAX_PATH];
> ::DragQueryFile(hDropInfo, nThisFile, szFile, _countof(szFile));
> // Do something with file
> }
> ::DragFinish(hDropInfo);
> }
>
> Are you doing it the same way?

Yes very like that with one or two minor differences - don't they all say
that :-)

First it is not in a dialogue, but in a class derived from CListBox and
another one derived from CListCtrl. In each case the derived control class
has an "initialise" member, called from OnInitDialog which previously filled
the list, and now also calls DragAcceptFiles(TRUE);

[This looks ok as the mouse cursor changes appropriately when I'm dragging
and it goes over the list.]

Then in the message map of the control class (not the dialogue) I have
ON_WM_DROPFILES() and the derived dialogue class has a function which looks
very like yours. My call to the base class
CListBox::OnDropFiles(hDropInfo); was at the end, but I have put it at the
start and it makes no difference - I suspect it does nothing anyway. [It
actually appears to be CWnd::OnDropFiles() in fact.]

When I launch explorer with "run as administrator, I have to confirm I want
to do it of course, but thereafter, as I drill down to the folder I'm
looking for, I see no hint that it is any different from a normal instance.
Should I?

Anyway it is ok running with normal privileges, but I had hoped to find an
easy way of debugging drag and drop, and am puzzled why this isn't working
for me.

[BTW also adding WM_ON_DROPFILES() and a handler to the CDialog- derived
class, means that it too gets called, but after the Control's version. I
found that out when I was experimenting with the app running with normal
privileges.]

Tom Serface

unread,
Nov 17, 2007, 7:40:53 PM11/17/07
to
OK, I don't know what else to suggest :o)

One thing you might try as well is don't run Visual Studio 2005 as
administrator and perhaps you can debug in normal mode. I only really need
to be admin running VS when I'm doing debugging for ASP.NET. Maybe that
would work for you.

Otherwise, sorry...

Tom

"David Webber" <da...@musical-dot-demon-dot-co.uk> wrote in message

news:uJ56goUK...@TK2MSFTNGP03.phx.gbl...

> First it is not in a dialogue, but in a class derived from CListBox and
> another one derived from CListCtrl. In each case the derived control
> class has an "initialise" member, called from OnInitDialog which
> previously filled the list, and now also calls DragAcceptFiles(TRUE);
>
> [This looks ok as the mouse cursor changes appropriately when I'm dragging
> and it goes over the list.]

Yeah, it must be UAC goofing it up somehow. Does it work OK if you
temporarily turn off UAC?

> Then in the message map of the control class (not the dialogue) I have
> ON_WM_DROPFILES() and the derived dialogue class has a function which
> looks very like yours. My call to the base class
> CListBox::OnDropFiles(hDropInfo); was at the end, but I have put it at the
> start and it makes no difference - I suspect it does nothing anyway. [It
> actually appears to be CWnd::OnDropFiles() in fact.]

Yeah, I think that is in from my by habit.

> When I launch explorer with "run as administrator, I have to confirm I
> want to do it of course, but thereafter, as I drill down to the folder I'm
> looking for, I see no hint that it is any different from a normal
> instance. Should I?

It looks the same to me as well.

> Anyway it is ok running with normal privileges, but I had hoped to find an
> easy way of debugging drag and drop, and am puzzled why this isn't working
> for me.

See above.

> [BTW also adding WM_ON_DROPFILES() and a handler to the CDialog- derived
> class, means that it too gets called, but after the Control's version. I
> found that out when I was experimenting with the app running with normal
> privileges.]

Yeah, it sounds like in your case you just want it in the control,
especially if you plan to reuse the control elsewhere and/or you only want
the drop to work when the user is over the control rather than over anywhere
on the dialog.

Tom

David Webber

unread,
Nov 18, 2007, 6:15:40 AM11/18/07
to

"Tom Serface" <tom.n...@camaswood.com> wrote in message
news:554F41A4-ED7D-41B5...@microsoft.com...

> One thing you might try as well is don't run Visual Studio 2005 as
> administrator and perhaps you can debug in normal mode. I only really
> need to be admin running VS when I'm doing debugging for ASP.NET. Maybe
> that would work for you.

I seem to have it set up so it runs automatically as an administrator -
probably the shortcut, but I can experiment.

> Otherwise, sorry...

Nothing to apologise for - you have been incredibly helpful. For the
moment I seem to have got it working the hard way, so this may be for
another day.

Just for the sake of interest, and a propos of what I am doing:

When you do File/New in MOZART you get a choice of "score templates" in a
list box. These are a bit like Microsoft Word's document templates and
define score formats for Orchestra, Big band, String Quartet etc etc etc.
The templates live in a specific folder (in the "appdata" area), and the
FileNew dialogue just lists all the ones in the folder.

I have had requests for using templates from elsewhere. So I thought it
would be a neat idea just to drag and drop one from elsewhere onto the list
box which shows them. This copies it into the templates folder and updates
the list. Now it's working it feels like a nice interface!

[It turns out, as usual, that most of the effort was in the nitty gritty
which checks if you're attempting to overwrite an existing template, and
selects the new one (or the first of any collection you import) in the
list.]

Tom Serface

unread,
Nov 19, 2007, 1:48:50 PM11/19/07
to
I needed a similar interface for my program (collecting files to put on CD,
DVD, Blu-ray) so I finally ended up just writing my own "browser" interface.
People can still use the Explorer, but my browser is built in so a little
easier to control as part of the program. Unfortunately, I could never get
drag and drop to work from File Open dialogs and trying to work between
Folders and Files was a drag (pun intended) as well.

Glad you got something that works for you.

Tom

"David Webber" <da...@musical-dot-demon-dot-co.uk> wrote in message

news:ujppjRdK...@TK2MSFTNGP02.phx.gbl...

0 new messages