If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register or Login
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Re: How to capture a folder address with drag and drop ?

While those references are generally informative, they don't really tell you how to get a folder address when you drag a folder onto a window. In fact, there so wordy and convoluted and lacking in example that they are IMHO misleading. It is really not all that difficult to set up a drag and drop window. I have used the following code to drag/drop files onto a static window. Note that here I used a derived CStatic class to implement dragging onto a CStatic window, but the principle for any window should remain largely the same.

This works fine with both files and with folders but not with a CRichEditView derived window ( ASSERT(nFileCount != 0); ), even though the correct folder name shows up as a single element of the m_vcsPathnames vector.

So my question boils down to how does one set this code up so that it can discriminate between a file (with a suffix) and a folder (no suffix)? What is the most clever and efficient way to programatically tell 'C:/.../mywhatever' from 'C/.../mywhatever/my.txt' ?

For any interested, here's a small demo to illustrate the point. To use the class in your app:

- create a dialog based app
- add CStaticDragDrop.h and CStaticDragDrop.cpp to your project
- add a CStatic derived control to your dialog interface
- rename the control id IDC_STATIC_TARGET (or some such but must match that in CStaticDragDrop.cpp)
- add a variable to the control and relabel it CStaticDragDrop
- set Notify and Accept Files true (default is false)
- compile and run
- files will have suffixes, folders will not
- check for the presence of '.' using int n = CString::Find(_T("."), 0); if (n >= 0) it's a file, else it's a folder

Re: How to capture a folder address with drag and drop ?

Originally Posted by Mike Pliam

So my question boils down to how does one set this code up so that it can discriminate between a file (with a suffix) and a folder (no suffix)? What is the most clever and efficient way to programatically tell 'C:/.../mywhatever' from 'C/.../mywhatever/my.txt' ?

So your real question essentially has nothing to do with drag-n-drop.

The most reliable way to tell files from folders is to query the file system object attributes and see if FILE_ATTRIBUTE_DIRECTORY is set.