-
Du mußt die ListBox als DropTarget registrieren. Danach bekommst Du im Ernstfall WM_DROPTARGET gesendet. Wenn Du die ListBox subclassed, kannst Du die Nachricht schön an das Parent weiterleiten. Ich hab da mal was ganz einfaches für Dich gemacht. Es handelt sich hier um einen Dialog. Der Dialog beinhaltet eine ListBox. Der Identifier der ListBox ist IDC_LIST1.
WNDPROC wndpList;
LRESULT CALLBACK ListProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch(uMsg)
{
case WM_DROPFILES:
return(SendMessage(GetParent(hWnd), uMsg, wParam, lParam));
default:
break;
}
return(CallWindowProc(wndpList, hWnd, uMsg, wParam, lParam));
}
INT_PTR CALLBACK DlgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch(uMsg)
{
case WM_INITDIALOG:
wndpList = (WNDPROC)SetWindowLongPtr(GetDlgItem(hWnd, IDC_LIST1), GWLP_WNDPROC, (LONG_PTR)ListProc);
DragAcceptFiles(GetDlgItem(hWnd, IDC_LIST1), TRUE);
return(TRUE);
case WM_DROPFILES:
{
INT_PTR nCnt, nIndex, nSize;
LPTSTR pszFileName;
HDROP hDrop;
hDrop = (HDROP)wParam;
nCnt = DragQueryFile(hDrop, (UINT)-1, NULL, 0);
for(nIndex = 0; nIndex < nCnt; ++nIndex)
{
if(0 == (nSize = DragQueryFile(hDrop, nIndex, NULL, 0)))
continue;
++nSize;
pszFileName = new TCHAR[nSize];
if(DragQueryFile(hDrop, nIndex, pszFileName, nSize))
SendDlgItemMessage(hWnd, IDC_LIST1, LB_ADDSTRING, 0, (LPARAM)pszFileName);
delete [] pszFileName;
}
}
return(TRUE);
case WM_DESTROY:
DragAcceptFiles(GetDlgItem(hWnd, IDC_LIST1), FALSE);
break;
default:
break;
}
return(FALSE);
}