【发布时间】:2017-07-28 05:49:48
【问题描述】:
根据this article,要允许Drop Only on the Target,我们必须
使用 SubclassDlgItem() 将一条消息重新路由到对话框对象,以便可以在那里完成所有处理。
先生。 DanRollins(文章作者)也提供了一个例子
class CEditDropNotif : public CEdit
{
virtual BOOL PreTranslateMessage(MSG* pMsg) {
if ( pMsg->message == WM_DROPFILES ) {
GetParent()->SendMessage(WM_DROPFILES, pMsg->wParam, pMsg->lParam);
return TRUE; // eat it
}
return FALSE; // allow default processing
}
};
BOOL CMyDlg::OnInitDialog()
{
...
static CEditDropNotif cEd; // must persist (usually a dlg member)
cEd.SubclassDlgItem( IDC_EDIT1, this );
::DragAcceptFiles( cEd.m_hWnd, true ); // the editbox, not the dialog
...
但我不明白为什么编辑控件(CEdit)在属性窗口(Visual Studio 资源视图)中有 Accept Files,但无法为自己注册消息 WM_DROPFILES 而不必创建一个继承类(或者可以,但我还不知道)。
我看到我们可以通过以下代码注册按钮的点击消息
BEGIN_MESSAGE_MAP(CSimpleDlg, CDialogEx)
...
ON_BN_CLICKED(IDC_BTN_01, &CSimpleDlg::OnBnClickedBtn01)
END_MESSAGE_MAP()
有没有办法我可以为拖放事件做类似的事情,比如
ON_DRAW_DROP(IDC_TXT_01, &CSimpleDlg::OnDragDrop01)//Is exist?
【问题讨论】:
标签: mfc textbox drag-and-drop editcontrol