一、CDropEdit类中两个重要的消息处理函数与其它
1、OnCreate(添加DragAcceptFiles 函数);
2、OnDropFile(处理拖动文件到控件上并释放时产生的消息);
3、PreTranslateMessage(用于过滤文字输入)
注意:在程序开始运行时,需要额外添加
ChangeWindowMessageFilter(WM_DROPFILES, MSGFLT_ADD);
ChangeWindowMessageFilter(0x0049, MSGFLT_ADD); // 0x0049 == WM_COPYGLOBALDATA
否则,WM_DROPFILES被过滤, 编辑框控件接受不到;
二、代码实现
DropEdit.h
class CDropEdit : public CEdit
{
DECLARE_DYNAMIC(CDropEdit)
public:
CDropEdit(CWnd *pParentWnd=NULL);
virtual ~CDropEdit();
protected:
DECLARE_MESSAGE_MAP()
virtual BOOL PreTranslateMessage(MSG* pMsg);
public:
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
afx_msg void OnDropFiles(HDROP hDropInfo);
void SetParentWnd(CWnd* pParentWnd);
private:
CWnd * m_pParentWnd;
};
DropEdit.cpp
IMPLEMENT_DYNAMIC(CDrop