Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Drag and droping files 1

Status
Not open for further replies.

Dolman

Programmer
Feb 3, 2002
8
GB
Hi
I am writing a program that requires dragging and dropping of files into an Edit box, using the MFC Dialog based application type. I have seen the accept files option in the properties of the edit box and tried using it, but I can't add an event handler for when a file is dropped into the edit box. Can any one help me please?
 

Derive a class from CEdit. Include edit control variable m_EditBox in your dialog.

In OnInitDialog of your dialog add

m_EditBox.DragAcceptFiles(TRUE);

Then in the class derived from CEdit , override OnDropFiles(). OnDropFiles() overrided is called for the drop.
 
I have managed to derive the new class from CEdit, include an Edit box and add the appropriate code to OnInitDialog, but I can't extract the file dropped information, such as filename and path etc.
Any further help would be much appreciated. (Please note I have not been using Visual C++ for very long.)
 
test the sample code below, you will understand how it works.

void CMyEdit::OnDropFiles(HDROP hDropInfo) {

CString csMsg("Files Dropped ");
char cFileName[256];
char cFileCount[64];
int nFileCount=0,
i=0;
nFileCount=
DragQueryFile(hDropInfo, 0xffffffff, cFileName, 256);
itoa(nFileCount, cFileCount, 10);
csMsg+=cFileCount;
AfxMessageBox(csMsg, MB_OK, 0);
for (i=0;i<nFileCount;i++)
{ DragQueryFile(hDropInfo, UINT(i), cFileName, 256);
AfxMessageBox(cFileName, MB_OK, 0);
}
CEdit::OnDropFiles(hDropInfo);}
 
Success, thank you very much for your help, it has been much appreciated.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top