JonDrnek
JonDrnek

Reputation: 1434

How do I drag and drop something into a Static control?

How would I drag and drop something into a static control? It looks like I need to create a sub class of COleDropTarget and include that as a member variable in a custom CStatic. That doesn't appear to be working though. When I try and drag something onto the Static control I get the drop denied cursor.

Upvotes: 2

Views: 1332

Answers (2)

user1995019
user1995019

Reputation: 11

In addition to the PreSubClassWindow() addition, you also have to set your CStatic control to have the Notify flag set in its resource parameters. Otherwise the control won't let the app know about mouse movements and hence not trigger the OnDragEnter() method.

Upvotes: 1

ChrisN
ChrisN

Reputation: 16943

The static control's m_hWnd must be valid when you call COleDropTarget::Register, which is why it doesn't work from within your CMyStatic constructor. What you can do is override CWnd::PreSubclassWindow within your CMyStatic class:

class CMyStatic : public CStatic {
    ...
    virtual void PreSubclassWindow();
};

void CMyStatic::PreSubclassWindow()
{
    CStatic::PreSubclassWindow();

    m_MyDropTarget.Register(this);
}

There's a really good article here on CodeProject that you may find helpful.

Upvotes: 3

Related Questions