Solved

why is GetFileData null on "OnDrop"?

Posted on 2003-12-09
6
674 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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

808 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