首页 > 代码库 > MFC 文件拖拽

MFC 文件拖拽

技术分享

 

对话框,Accept Files(True)

 

void CMFCDragFileDlg::OnDropFiles(HDROP hDropInfo)
{
    TCHAR szPath[MAX_PATH] = {0};
    UINT nCount = DragQueryFile(hDropInfo, 0xFFFFFFFF, NULL, 0);
    for(UINT i = 0; i < nCount; i++) 
    {
        DragQueryFile(hDropInfo, i, szPath, MAX_PATH);
        
        int iGender = GetCheckedRadioButton(IDC_RADIO1, IDC_RADIO2);
        switch (iGender)
        {
        case IDC_RADIO1:
            SetDlgItemText(IDC_EDIT1,szPath);
            break;
        case IDC_RADIO2:            
            if (m_combobox.FindString(0, szPath) < 0)//已存在则不添加
            {
                m_combobox.AddString(szPath);
            }
            break;        
        }
    }

    CDialog::OnDropFiles(hDropInfo);
}

 

MFC 文件拖拽