´ÙÀ½ ¿¹Á¦¿¡¼´Â Ç¥½Ã ÇÏ °í ¾ÕÀÇ ¿¹Á¦¿¡¼ »ç¿ë µÇ´Â ´ëÈ »óÀÚ¸¦ ÃʱâÈ ÇÕ´Ï´Ù. ±×·¯³ª,ÀÌ ÄÚµå LBS_MULTIPLESEL ½ºÅ¸ÀÏÀ» »ç¿ë ÇÏ ¿© ÇÑ ¹ø¿¡ Çϳª ÀÌ»óÀÇ ÆÄÀÏÀ» ¼±ÅÃÇÒ ¼ö ÀÖ°Ô ÇÕ´Ï´Ù. »èÁ¦ ´ÜÃ߸¦ ¼±Åà ÇÏ¸é ¿¹Á¦ (¼±ÅÃÇÑ ÆÄÀÏÀÇ ¼ö¸¦ °Ë»ö)À» LB_GETSELCOUNT ¸Þ½ÃÁö¿Í (°Ë»ö ÇÏ·Á¸é ¼±ÅÃÇÑ ¸ñ·Ï »óÀÚ Ç׸ñÀÇ ¹è¿À») LB_GETSELITEMS ¸Þ½ÃÁö¸¦ º¸³À´Ï´Ù. ÆÄÀÏÀ» »èÁ¦ ÇÑ ÈÄ ÇØ´ç Äڵ带 Á¦°Å ÇØ´ç ÇÏ´Â Ç׸ñ ¸ñ·Ï »óÀÚ¿¡¼ LB_DELETESTRING ¸Þ½ÃÁö¸¦ Àü¼Û ÇÏ ¿©.
#define BUFFER MAX_PATH
#define BIGBUFF 8192
BOOL APIENTRY DlgDelFilesProc(
HWND hDlg, // window handle to dialog box
UINT message, // type of message
UINT wParam, // message-specific information
LONG lParam)
{
DWORD cchCurDir;
LPTSTR lpszCurDir;
LPTSTR lpszFileToDelete;
int nSelItems;
int nSelItemsInBuffer;
TCHAR tchBuffer[BUFFER];
TCHAR tchMsgBuff[BUFFER];
int nBuffer[BIGBUFF];
int i;
BOOL fResult;
HWND hListBox;
switch (message) {
case WM_INITDIALOG:
// Initialize the list box by filling it with files from
// the current directory.
lpszCurDir = tchBuffer;
GetCurrentDirectory(cchCurDir, lpszCurDir);
DlgDirList(hDlg, lpszCurDir, IDL_FILES, IDS_PATHTOFILL, 0);
SetFocus(GetDlgItem(hDlg, IDL_FILES));
return FALSE;
case WM_COMMAND:
switch (LOWORD(wParam))
{
case IDOK:
// When the user presses the Delete (IDOK)
// button, delete all the selected files.
lpszFileToDelete = tchBuffer;
hListBox = GetDlgItem(hDlg, IDL_FILES);
nSelItems = SendMessage(hListBox,
LB_GETSELCOUNT, 0, 0);
nSelItemsInBuffer = SendMessage(hListBox,
LB_GETSELITEMS, 512, (LPARAM) nBuffer);
if (nSelItems > nSelItemsInBuffer)
{
MessageBox(hDlg, "Too many items selected.",
NULL, MB_OK);
}
else
{
// Go through the list backwards because after
// deleting an item the indices change for
// every subsequent item. By going backward,
// the indices are never invalidated.
for (i = nSelItemsInBuffer - 1; i >= 0; i--)
{
SendMessage(hListBox, LB_GETTEXT,
nBuffer[i],
(LPARAM) lpszFileToDelete);
fResult = DeleteFile(lpszFileToDelete);
if (!fResult)
{
sprintf(tchMsgBuff,
"Could not delete file: %s "
"GetLastError = %u",
(LPARAM) lpszFileToDelete);
// Call app-defined error handler.
ErrorHandler(tchMsgBuff);
}
else
{
SendMessage(hListBox, LB_DELETESTRING,
nBuffer[i], 0);
}
}
SendMessage(hListBox, LB_SETCARETINDEX, 0, 0);
}
return TRUE;
case IDCANCEL:
// Destroy the dialog box.
EndDialog(hDlg, TRUE);
return TRUE;
default:
return FALSE;
}
default:
return FALSE;
}
}