tags:

views:

249

answers:

2

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.

A: 

I was calling Register(), but was doing it in the constructor of CMyStatic and in CMyStatic::Create(). The Register in the constructor failed and Create never got called. It does work if I register them from OnInitDialog() of the containing dialog box. How can I register them from in CMyStatic?

Jon Drnek
+1  A: 

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.

ChrisN