Solved

why is GetFileData null on "OnDrop"?

Posted on 2003-12-09
6
670 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
Comment Utility
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
Comment Utility
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
Comment Utility
Also, make sure you have AfxOleInit() in your app's InitInstance.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:JoyBurke
Comment Utility
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
Comment Utility
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
Comment Utility
OnDropFiles works great! Thank you thank you!
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Mac OS 9 (Classic Environment) vs. MacBook Pro OS 10 8 36
Host to IP 7 73
maxBlock challenge 30 99
canBalance challenge 34 65
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
This video discusses moving either the default database or any database to a new volume.

744 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

13 Experts available now in Live!

Get 1:1 Help Now