Solved

why is GetFileData null on "OnDrop"?

Posted on 2003-12-09
6
671 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Need Help INsttalling wget on Mavericks OS X 3 90
Expand data scrubbing tool 13 32
sameEnds challenge 3 133
bigDiff challenge 17 83
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

911 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now