Window Message

I have a MFC MDI application (Myapp). I select CEditView as the view's base class and add DragAcceptFiles to the InitInstance() in myapp.cpp, the application can accept dropping of multi-files. But as I add OnDropFiles()  Window-message function to my view class by ClassWizzard, it is not called at all as I drop files (although the files are opened). What might be the problem(s)?  
yingchunliAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

jhanceCommented:
CEditView doesn't normally receive the WM_DROPFILES message.  It's sent to the containing frame window.  If you want to receive and process WM_DROPFILES in a CEditView, you need to derive your own class from CEditView and then subclass it.  Then you will be able to use your own message handler.  Usually, it's just easier to process WM_DROPFILES in the frame window and send the files to the appropriate CEditView.
0
yingchunliAuthor Commented:
Hi jhance:

Pleased to talk to you another time.

It is ok for the MainFram class. But I am more interested in having OnDropFiles() in CMyappView class.

My CMyappView class is derived from CEditView, and the message handler WS_DROPFILES is there (I suppose it is my "own" message handler for the subclass). I still do not know how to make the function OnDropFiles in my CMyappView work.

0
Tommy HuiEngineerCommented:
Each window can be a drop target. You cannot do what you're trying to do in the app's InitInstance(). You need to call DragAcceptFiles() in your view's InitialUpdate() or OnCreate() methods.


0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

yingchunliAuthor Commented:
I think it is OK to call  DragAcceptFiles() in the app's InitInstance(). It turns out that every window can be a drop target. My problem is that the WS_DROPFILES message does not cause the processing of OnDropFile() in my view class (derived from CEditView). If I really want to do it this way, what I need to do?
0
mikeblasCommented:
There's no reason to derive your own class from CEditView, as you _must've_ already done that because CEditView is an abstract base class. AppWizard and ClassWizard do the derivation for if you've used them to get the class into your app.

You don't mention which window you're calling DragAcceptFiles() upon in your InitInstance().  I guess it must be your frame window.

If you're calling it on your frame window, MFC itself is handling the drag-and-drop operation for you because MFC's own CFrameWnd class supplies an OnDropFiles() handler that simply tries to open the dragged files by calling CYourApp::OpenDocumentFile() on each of the passed file names.

Can add a handler to OnDropFiles() in your your own CFrameWnd-derived window and handle the drop operation any way you'd like to.

It's also wrong to think that about the view is not offered the dropped files; just call DragAcceptFiles() on whichever window you want to be the drop target. You're right, it is OK to call DragAcceptFiles() in InitInstance(), but InitInstance() only runs once in your application--and you may have several instances of your view, or you might destroy and recreate your view.

So, if you must handle the drop message in your view, you must call DragAcceptFiles() on your view class. Putting that code in InitInstance() of the view is a fine place to do that. Then, write an OnDropFiles() handler for the WM_DROPFILES message and process the dropped files in whatever way you'd like.

If you're making your view the drop target, only your view is the drop target--dropping on your frame, on the MDI Client Area, or on the child frame will not result in WM_DROPFILES being sent to your window.

.B keiM

0
yingchunliAuthor Commented:
Hi   Mikeblas:

Thanks for you helpful points. But there is one thing on which I did not get your idea.

You said: "if you must handle the drop message in your view, you must call DragAcceptFiles() on your view class."

I just have no idea on how to do this. please show me where and how you can call this function and then make the OnDropFiles() work.


0
mikeblasCommented:
I already indicated where and how to call DragAcceptFiles() in my previous response.  The best I can do is type my answer slower:

Add an override for OnInitialUpdate().  Inside that override, call DragAcceptFiles().

void CYourView::OnInitialUpdate()
{
   DragAcceptFiles();
   CTheBaseClassOfYourView::OnInitialUpdate();
}

Instead of "CYourView", type in the name of your own view.  Instead of "CTheBaseClassOfYourView", type in the base class name of your own view.

.B ekiM

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.