Solved

Drag and Drop enabling

Posted on 2000-02-16
31
742 Views
Last Modified: 2013-11-20
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?
0
Comment
Question by:jhattingh
  • 18
  • 13
31 Comments
 
LVL 1

Expert Comment

by:ScottyDawg
ID: 2527708
Also call DragAcceptFiles(true) in your InitInstance(...). Does this help?
0
 
LVL 1

Author Comment

by:jhattingh
ID: 2527737
Thanks for the response.

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

0
 
LVL 1

Expert Comment

by:ScottyDawg
ID: 2527770
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
ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

 
LVL 1

Author Comment

by:jhattingh
ID: 2527791
DragAcceptFiles() asserts on the following:

ASSERT(::IsWindow(m_hWnd));

P.S. This is a dialog app

0
 
LVL 1

Accepted Solution

by:
ScottyDawg earned 100 total points
ID: 2527833
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
 
LVL 1

Author Comment

by:jhattingh
ID: 2527854
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
 
LVL 1

Expert Comment

by:ScottyDawg
ID: 2527868
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
 
LVL 1

Author Comment

by:jhattingh
ID: 2527880
Thanks...

tried it...


Need the other ideas... ;)
0
 
LVL 1

Expert Comment

by:ScottyDawg
ID: 2527887
*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
 
LVL 1

Author Comment

by:jhattingh
ID: 2527922
Adjusted points to 60
0
 
LVL 1

Author Comment

by:jhattingh
ID: 2527923
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
 
LVL 1

Expert Comment

by:ScottyDawg
ID: 2527947
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
 
LVL 1

Author Comment

by:jhattingh
ID: 2528048
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
 
LVL 1

Expert Comment

by:ScottyDawg
ID: 2528091
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
 
LVL 1

Author Comment

by:jhattingh
ID: 2528113
I am doing a bit of overriding... Would you like me to send you the zipped project?
0
 
LVL 1

Expert Comment

by:ScottyDawg
ID: 2528131
go for it

scotnielsen@hotmail.com
0
 
LVL 1

Author Comment

by:jhattingh
ID: 2528157
Adjusted points to 70
0
 
LVL 1

Author Comment

by:jhattingh
ID: 2528158
Ok, I've sent it.
0
 
LVL 1

Expert Comment

by:ScottyDawg
ID: 2528475
on its way back
0
 
LVL 1

Author Comment

by:jhattingh
ID: 2528922
Adjusted points to 80
0
 
LVL 1

Author Comment

by:jhattingh
ID: 2528923
Ok got your mail - sounds cool! Thank you.
0
 
LVL 1

Expert Comment

by:ScottyDawg
ID: 2530496
is it working?
0
 
LVL 1

Author Comment

by:jhattingh
ID: 2530587
Adjusted points to 90
0
 
LVL 1

Author Comment

by:jhattingh
ID: 2530588
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
 
LVL 1

Author Comment

by:jhattingh
ID: 2530590
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
 
LVL 1

Expert Comment

by:ScottyDawg
ID: 2530596
ack! That'll be hotmail for you. Hang on a sec.
0
 
LVL 1

Author Comment

by:jhattingh
ID: 2530629
Adjusted points to 100
0
 
LVL 1

Author Comment

by:jhattingh
ID: 2530630
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
 
LVL 1

Expert Comment

by:ScottyDawg
ID: 2530650
I commented out the SetTimer call cos that was making it crash.

Also, it never seemed to come out of the OnPaint() function...
0
 
LVL 1

Author Comment

by:jhattingh
ID: 2531273
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
 
LVL 1

Expert Comment

by:ScottyDawg
ID: 2531307
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

Featured Post

ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Error on moodle after upgrade 3 131
Define unique primary key 9 93
sumNumber challenge 16 122
zeroFront challenge 7 99
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…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

803 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