16,548
社区成员




//{{NO_DEPENDENCIES}}
// Microsoft Developer Studio generated include file.
// Used by delfile.rc
//
#define DELFILE 101
#define IDL_FILES 1000
#define IDDEL 1003
#define IDS_PATHTOFILL -1
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NO_MFC 1
#define _APS_NEXT_RESOURCE_VALUE 102
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1004
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif
#include <windows.h>
#include "resource.h"
#define BUFFER MAX_PATH
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{
static TCHAR szAppName[] = TEXT ("DelFile") ;
HWND hwnd ;
MSG msg ;
WNDCLASS wndclass ;
wndclass.style = CS_HREDRAW | CS_VREDRAW ;
wndclass.lpfnWndProc = WndProc ;
wndclass.cbClsExtra = 0 ;
wndclass.cbWndExtra = DLGWINDOWEXTRA;
wndclass.hInstance = hInstance ;
wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION) ;
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ;
wndclass.hbrBackground = CreateSolidBrush (0X00FFFFFF) ;
wndclass.lpszMenuName = NULL ;
wndclass.lpszClassName = szAppName ;
if (!RegisterClass (&wndclass))
{
MessageBox (NULL, TEXT ("This program requires Windows NT!"),
szAppName, MB_ICONERROR) ;
return 0 ;
}
hwnd = CreateDialog (hInstance, MAKEINTRESOURCE(DELFILE), 0, NULL) ;
ShowWindow(hwnd,iCmdShow);
while (GetMessage (&msg, NULL, 0, 0))
{
{
TranslateMessage (&msg) ;
DispatchMessage (&msg) ;
}
}
return msg.wParam ;
}
LRESULT CALLBACK WndProc(HWND hDlg, UINT message,
WPARAM wParam, LPARAM lParam)
{
DWORD cchCurDir=MAX_PATH;
LPTSTR lpszCurDir;
LPTSTR lpszFileToDelete;
int nItem;
int nTotal;
TCHAR tchBuffer[BUFFER];
BOOL fResult;
switch (message)
{
// case WM_KEYDOWN:
// MessageBox(hDlg,"aaa","bbb",MB_OK);
// break;
case WM_COMMAND:
{
switch (LOWORD(wParam))
{
case IDOK:
pszCurDir = tchBuffer;
GetCurrentDirectory(cchCurDir, lpszCurDir);
DlgDirList(hDlg, lpszCurDir, IDL_FILES, IDS_PATHTOFILL, DDL_READWRITE);
SetFocus(GetDlgItem(hDlg, IDL_FILES));
break;
case IDDEL:
lpszFileToDelete = tchBuffer;
DlgDirSelectEx(hDlg, lpszFileToDelete, MAX_PATH,
IDL_FILES);
fResult = DeleteFile(lpszFileToDelete);
if (!fResult)
{
MessageBox(hDlg, "Could not delete file.",
NULL, MB_OK);
}
else
{
nItem = SendMessage(GetDlgItem(hDlg,
IDL_FILES), LB_GETCURSEL, 0, 0);
nTotal = SendMessage(GetDlgItem(hDlg,
IDL_FILES), LB_DELETESTRING, nItem, 0);
// Update the list box.
if (nTotal > nItem)
{
SendMessage(GetDlgItem(hDlg, IDL_FILES),
LB_SETCURSEL, nItem, 0);
}
else
{
SendMessage(GetDlgItem(hDlg, IDL_FILES),
LB_SETCURSEL, 0, 0);
}
}
return 0;
case IDCANCEL:
SendMessage(hDlg,WM_DESTROY,0,0);
return 0;
}
return 0;
}
case WM_DESTROY:
PostQuitMessage (0) ;
return 0 ;
}
return DefDlgProc(hDlg,message,wParam,lParam);
}