Solved

Window Message

Posted on 1998-02-27
7
313 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
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
repeatEnd java challenge 42 84
wait notify demo infinite loop 3 95
Window placement 17 74
tripleUp challenge 7 73
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

911 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now