?
Solved

why is GetFileData null on "OnDrop"?

Posted on 2003-12-09
6
Medium Priority
?
685 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

 

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 2000 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
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.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

741 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