Drag and Drop Files using VC++

Posted: July 16, 2009 in Programming Tips
Tags: ,

Add the following code to the OnInitialUpdate() of the View Class

void CMyAppView::OnInitialUpdate()
{
 CView::OnInitialUpdate();

 //Support Drag and Drop
 DragAcceptFiles();

 .......
 ......
}

Then add WM_DROPFILES to the View class. when it is added OnDropFiles() will be added to the View Class implement the follwing code

void CMyAppView::OnDropFiles(HDROP hDropInfo)
{
 CString strFileName;    // The name of the dropped file is stored here

 ::DragQueryFile(hDropInfo, 0, strFileName.GetBufferSetLength
 (_MAX_PATH), _MAX_PATH);
 strFileName.ReleaseBuffer();
 ::DragFinish(hDropInfo);

// After this the specific functionality can be added. For eg. OpenFile()
}

The same method can be implemented in the MainFrame Class also.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s