Solved

Window Message

Posted on 1998-02-27
7
312 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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.
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…

762 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

18 Experts available now in Live!

Get 1:1 Help Now