Solved

Window Message

Posted on 1998-02-27
7
318 Views
Last Modified: 2013-11-20
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)?  
0
Comment
Question by:yingchunli
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 32

Expert Comment

by:jhance
ID: 1316619
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
 

Author Comment

by:yingchunli
ID: 1316620
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
 
LVL 15

Expert Comment

by:Tommy Hui
ID: 1316621
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:yingchunli
ID: 1316622
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
 
LVL 11

Expert Comment

by:mikeblas
ID: 1316623
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
 

Author Comment

by:yingchunli
ID: 1316624
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
 
LVL 11

Accepted Solution

by:
mikeblas earned 30 total points
ID: 1316625
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

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question