We help IT Professionals succeed at work.

Setting acceptable file drops to an application

pcasxd0 asked
Medium Priority
Last Modified: 2013-11-20
I want to set my application to accept only files having a particular extension by drag and drop. I have to use CWnd's 'DragAcceptFiles'in the InitInstance. Prior to calling this function, I have to set this filter that my application would reject files of any other extension, except the one I specified. I want this functionality to be in the application class, and not to be handled by various views. how to go about doing this?
Watch Question

By calling DragAcceptFiles(), you are telling Windows that the window is a drop target. It does not tell Windows which files are acceptable and which aren't. In fact, there isn't an easy way to do this. If the UI feedback isn't important, you can skip over the files you don't want.

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts


How can I 'skip'over the files I don't want?
Tommy HuiEngineer

When you are processing the WM_DROPFILES message, it is up to you to go through all the files by using DragQueryFile and DragFinish(). The DragQueryFile returns the filename. If the filename is not what you want, then don't do anything with it.


One last doubt... can the application class handle the WM-DROPFILES command, or do I have to write an independent function like it? (I want to handle this in the app class, rather than the view classes)
Tommy HuiEngineer

I don't think the application class can handle it. Although you can simulate that by having the view class call a member function in the application.


Thank you for the convincing answer. I'll do that.
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.