Solved

why is GetFileData null on "OnDrop"?

Posted on 2003-12-09
6
673 Views
Last Modified: 2013-11-20
I need a way to get the filename from a file when it is dropped into my view from explorer. I think I've added most of the code correctly, but the pointer to the COleDataObject that is given on the "OnDrop" doesn't seem to give me any info.

The CFile pointer is always null using:

CFile* pFile = pDataObject->GetFileData(m_cfPrivate);

in the section:

BOOL CDMMView::OnDrop(COleDataObject* pDataObject, DROPEFFECT dropEffect, CPoint point)


the format for the CLIPFORMAT is shown below:

CLIPFORMAT CDMMView::m_cfPrivate = NULL;

intialized like:

      if (m_cfPrivate == NULL)
            m_cfPrivate = (CLIPFORMAT)
                  ::RegisterClipboardFormat(_T("Test"));

I know this is probably easy, but I need the fix fast!!
0
Comment
Question by:JoyBurke
  • 3
  • 2
6 Comments
 
LVL 23

Expert Comment

by:Roshan Davis
ID: 9909578
Is that what you mean...?

void CDMMView::OnDropFiles(HDROP hDropInfo)
{
      CHAR            *pchDropFile;
      INT            nFileNameSize;

      INT            nFileCount = ::DragQueryFile(hDropInfo, 0xFFFFFFFF , NULL, 0);
      
      

      for ( INT nIndex = 0 ; nIndex < nFileCount; nIndex++ )
      {
            if ( 0 < (nFileNameSize = ::DragQueryFile(hDropInfo, nIndex, NULL, 0)) )
            {
                  pchDropFile = new CHAR[nFileNameSize + 1];
                  ::DragQueryFile(hDropInfo, nIndex, pchDropFile, nFileNameSize + 1);

                  AddFileToList(pchDropFile);
                  
                  delete []pchDropFile;
            }
      }

      ::DragFinish(hDropInfo);
      
      CView::OnDropFiles(hDropInfo);
}

Rosh :)
0
 
LVL 23

Expert Comment

by:Roshan Davis
ID: 9909584
Also add this line of code in your OnInitialUpdate of your CView derived class (CDMMView)

DragAcceptFiles(TRUE);

Rosh :)
0
 
LVL 9

Expert Comment

by:Priyesh
ID: 9909982
Also, make sure you have AfxOleInit() in your app's InitInstance.
0
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 

Author Comment

by:JoyBurke
ID: 9912282
I already had AfxOleInit and DragAcceptFiles(TRUE) didn't seem to do anything.

I was basically trying to use code similar to the msdn OClient example.

roshmon - how are you getting hDropInfo?

The function I was overwriting was BOOL CDMMView::OnDrop(COleDataObject* pDataObject, DROPEFFECT dropEffect, CPoint point)

The basic part of the drag & drop seems to work, but I can't get any info once dropped.

Here is my full code, both CFile and vars returned by GetObjectInfo are null.

BOOL CDMMView::OnDrop(COleDataObject* pDataObject, DROPEFFECT dropEffect, CPoint point)
{
      ASSERT_VALID(this);

      // clean up focus rect
      OnDragLeave();

      // offset point as appropriate for dragging
      GetObjectInfo(pDataObject, &m_dragSize, &m_dragOffset);
      CClientDC dc(NULL);
      dc.HIMETRICtoDP(&m_dragSize);
      dc.HIMETRICtoDP(&m_dragOffset);
      point -= m_dragOffset;

      CFile* pFile = pDataObject->GetFileData(m_cfPrivate);

      return CView::OnDrop(pDataObject, dropEffect, point);
}

0
 
LVL 23

Accepted Solution

by:
Roshan Davis earned 500 total points
ID: 9917921
Instead of verriding OnDrop of CView, just override "OnDropFiles" of CWnd, I'm using that function in my code and it is working fine..

hDropInfo is the parameter of OnDropFiles

Rosh :)
0
 

Author Comment

by:JoyBurke
ID: 9920381
OnDropFiles works great! Thank you thank you!
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
deburging in oracle form 12 99
tripleUp challenge 7 79
mapAB Challlenge 35 145
x-bar in Google Sheets 2 55
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

809 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