Click to See Complete Forum and Search --> : Dropping files on RichEdit Controls


aurbach
September 16th, 2005, 07:30 PM
In a C++/WinAPI (non-MFC) context, I am trying to add the ability to drag and drop .txt and .rtf files on a RichEdit control. I can get part way there, but no further.

Here's what I'm already doing...

I call DragAcceptFiles() for the control to enable file-dropping at the window level
I send an EM_SETEVENTMASK to the control with ENM_DROPFILES set to enable file dropping at the RichEdit Level.
I include a case in my WM_NOTIFY handler for the EN_DROPFILES message. In that handler I return a value of 1 if and only if there is exactly one file being dropped and its file extension is either .txt or .rtf. (And this handler is being called and is returning 1 when an appropriate test file is dropped.)
I have a minimal IRichEditOleCallback function which is implementing QueryAcceptData and returning S_OK.


But the text is not appearing. My suspicion is that I need to implement more of the IRichEditOleCallback, but I have no idea which methods need to be implemented.

So my questions are:

Am I on the right track?
Can you offer suggestions or sample code to help?


Thank you for your help.

aurbach
September 20th, 2005, 12:01 PM
I've figured out my Drag and Drop problem, so I thought I'd answer my own question in case anyone else is interested...

As I posted originally, I had already called DragAcceptFiles for the control and set the ENM_DROPFILES flag in the RichEdit's EventMask. And I was getting drop notifications in my OnNotify handler. What I wasn't doing was handling them.

What I mean by that is that the place to handle the file import is right in the EN_DROPFILES subhandler to your WM_NOTIFY handler. Use the ENDROPFILES structure passed (by reference) to you in the message; decide whether to accept the file (I check to see that I'm only dropping a single file and that its file type is .txt or .rtf); if you want to accept it, handle the import right there in the handler. Then you can return 0, since you've already imported the file.

Simple. Like why didn't I try that to start with? :o