Drag and Drop enabling

I have a CStatic Derived class and I want to enable the ability to drag and drop files onto it.

The static control is created on the dialog app using the following code:

m_stcPortal.Create("", WS_VISIBLE|SS_NOTIFY|SS_SUNKEN, C3DPortal::GetRect(IDC_STATIC_PORTAL, this),(CWnd*)this);

I have implemented the following in the header:

//{{AFX_MSG(C3DPortal)
afx_msg void OnDropFiles(HDROP hDropInfo);
//}}AFX_MSG

...and in the cpp file:

int C3DPortal::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
   ...

   DragAcceptFiles(TRUE);

   ...
}

void C3DPortal::OnDropFiles(HDROP hDropInfo)
{
   ...
}

BEGIN_MESSAGE_MAP(C3DPortal, CStatic)
      //{{AFX_MSG_MAP(C3DPortal)
      ON_WM_DROPFILES()
          .
          .
          .
      //}}AFX_MSG_MAP
END_MESSAGE_MAP()






BUT:

There is still a "no-drag-allowed" icon showing when I drag a file over this control....

Why?
LVL 1
jhattinghAsked:
Who is Participating?
 
ScottyDawgConnect With a Mentor Commented:
jhattingh,

I just knocked up a quick dialog based app and add 1 CStatic control to it. Then using class wizard I added a CStatic variable to my app called m_wndDropTarget. In OnInitDialog I did the following:

BOOL CTestDlg::OnInitDialog()
{
    CDialog::OnInitDialog()

....
....
....    
   
    m_wndDropTarget.DragAcceptFiles();

}

when I dragged a file over the static the mouse pointer changed from a no entry sign to the accept cursor. Hope this helps :)
0
 
ScottyDawgCommented:
Also call DragAcceptFiles(true) in your InitInstance(...). Does this help?
0
 
jhattinghAuthor Commented:
Thanks for the response.

DragAcceptFiles() doesn't take one parameter when called from the initinstance....?

0
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

 
ScottyDawgCommented:
this is what the AppWizard does

// create main MDI Frame window
CMainFrame* pMainFrame = new CMainFrame;

if (!pMainFrame->LoadFrame(IDR_MAINFRAME))
    return FALSE;

m_pMainWnd = pMainFrame;

// Enable drag/drop open
m_pMainWnd->DragAcceptFiles();
0
 
jhattinghAuthor Commented:
DragAcceptFiles() asserts on the following:

ASSERT(::IsWindow(m_hWnd));

P.S. This is a dialog app

0
 
jhattinghAuthor Commented:
Code changed:

m_stcPortal.Create("", WS_VISIBLE|SS_NOTIFY|SS_SUNKEN/*|WS_EX_ACCEPTFILES*/, C3DPortal::GetRect(IDC_STATIC_PORTAL, this),(CWnd*)this);

m_stcPortal.DragAcceptFiles(true);

..
..
..
..

Still not accepting files...?

Thanks for your persistence!
0
 
ScottyDawgCommented:
hmmm....I think you'll need the WS_CHILD style to. If that doesn't help I've got another idea or two to try...we'll get there in the end I'm sure :)
0
 
jhattinghAuthor Commented:
Thanks...

tried it...


Need the other ideas... ;)
0
 
ScottyDawgCommented:
*hahaha*

1st of all, can you create a new dialog app and follow what I did. If that at least doesn't work we definitely got a problem.
0
 
jhattinghAuthor Commented:
Adjusted points to 60
0
 
jhattinghAuthor Commented:
Ok....

1. Added CStatic Member variable to the dlg class

2. Called the same create function w/same parameters

3. Called DragAcceptFiles(true);

   .
   .
   .
   .

It works...! Hmmmm. What's up with my Other app I wonder?
0
 
ScottyDawgCommented:
righty....

with this same dialog app add your CPortal class to it and declare a CPortal variable m_wndPortal (or whatever you want).


Now in OnInitDialog call

BOOL CDialog::OnInitDialog()
{
   CDialog::OnInitDialog();

   VERIFY(m_wndPortal.SubclassDlgItem(IDC_PORTAL_STATIC, this));
}

where IDC_PORTAL_STATIC is the ID of the static control on the dialog.

Does it work now?
0
 
jhattinghAuthor Commented:
It's exceptional.... that is to say, exceptioning!

In D3DRM.dll

So then the problem may be related to the coolest component of my CStatic derived class.

hmmmm.

I'd like it resolved, but I'm happy to drop (without a drag!) the 'question' if you think it's getting too hairy...

Jason
0
 
ScottyDawgCommented:
sure I'll help if I can, but unless I see the source I don't know where to look next....

Are you overriding OnPaint() in the CStatic and doing something flash? or are you doing something in OnMouseMove() or OnSetCursor(), these could be the problems too...
0
 
jhattinghAuthor Commented:
I am doing a bit of overriding... Would you like me to send you the zipped project?
0
 
ScottyDawgCommented:
go for it

scotnielsen@hotmail.com
0
 
jhattinghAuthor Commented:
Adjusted points to 70
0
 
jhattinghAuthor Commented:
Ok, I've sent it.
0
 
ScottyDawgCommented:
on its way back
0
 
jhattinghAuthor Commented:
Adjusted points to 80
0
 
jhattinghAuthor Commented:
Ok got your mail - sounds cool! Thank you.
0
 
ScottyDawgCommented:
is it working?
0
 
jhattinghAuthor Commented:
Adjusted points to 90
0
 
jhattinghAuthor Commented:
The mail you sent didn't have any code in or attached, and the EE posts haven't either - I was expecting an additional email with the code.... until you asked "Is it working?"

You must have accidentally not attached code to the email.

Can't wait...!
0
 
jhattinghAuthor Commented:
The mail you sent didn't have any code in or attached, and the EE posts haven't either - I was expecting an additional email with the code.... until you asked "Is it working?"

You must have accidentally not attached code to the email.

Can't wait...!
0
 
ScottyDawgCommented:
ack! That'll be hotmail for you. Hang on a sec.
0
 
jhattinghAuthor Commented:
Adjusted points to 100
0
 
jhattinghAuthor Commented:
The dragdrop stuff appears to working... but it's removed the classes previous ability...<grin>

When I run the app, the control no longer can load and display 3D objects as it used to...
0
 
ScottyDawgCommented:
I commented out the SetTimer call cos that was making it crash.

Also, it never seemed to come out of the OnPaint() function...
0
 
jhattinghAuthor Commented:
Still having problems with it, but I think it's about time I closed this question since you have more than answered my original question
0
 
ScottyDawgCommented:
I think the biggest problem is the Group Box you had surrounding the entire set of dialog controls. Once I removed this, things went a lot smoother

:)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.