SHFILEOPSTRUCT
SHFILEOPSTRUCT SHFileOperation (, , ).
typedef struct SHFILEOPSTRUCT {
HWND hwnd;
UINT wFunc;
PCZZTSTR pFrom;
PCZZTSTR pTo;
FILEOP_FLAGS fFlags;
BOOL fAnyOperationsAborted;
LPVOID hNameMappings;
PCTSTR lpszProgressTitle;
}
wFunc F_COPY.
:
) BOOL IsDriveReady(char DriveLetter);
) void flash_copy(char n);
) void main().
) void main() , . , . . . , . , . .
) BOOL IsDriveReady(char DriveLetter) . . 3, .. . usb true, false.
) void flash_copy(char n) . , . ShFileOperation ShFileOpStruct. , , , , FO_COPY FOF_NOCONFIRMATION.
#include "objbase.h"
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <locale.h>
#include<winbase.h>
#include<windows.h>
#include <shellapi.h>
#include <iostream>
#include <fstream>
#include <windows.h>
#include <dbt.h>
BOOL IsDriveReady(char DriveLetter)
{
WORD OldErrorMode;
TCHAR OldDirectory[255];
TCHAR NewDirectory[3];
OldErrorMode = SetErrorMode(SEM_FAILCRITICALERRORS);
GetCurrentDirectory(255,(LPTSTR)OldDirectory);
NewDirectory[0] = DriveLetter;
NewDirectory[1] = ':';
NewDirectory[2] = '\\';
SetCurrentDirectory((LPTSTR)NewDirectory);
if (GetLastError() == 3) //3 - " "
|
|
{
SetCurrentDirectory((LPTSTR)OldDirectory);
SetErrorMode(OldErrorMode);
return FALSE;
}else
{
SetCurrentDirectory((LPTSTR)OldDirectory);
SetErrorMode(OldErrorMode);
return TRUE;
}
}
void flash_copy(char n)
{
SHFILEOPSTRUCT fa;
ZeroMemory(&fa, sizeof(fa));
switch(n)
{
case 'f':
fa.pFrom = L"f:\\";
break;
case 'g':
fa.pFrom = L"g:\\";
break;
case 'h':
fa.pFrom = L"h:\\";
break;
case 'i':
fa.pFrom = L"i:\\";
break;
}
fa.fFlags =FOF_NOCONFIRMATION;
fa.hwnd = 0;
//fa.pFrom = L"f:\\";
fa.pTo = L"c:\\111\\";
fa.wFunc = FO_COPY;
int nRes =::SHFileOperation(&fa);//
}
void main()
{
int q=1, a=1;
printf("Waiting...\n");
do{
while(q==1)
{
if(IsDriveReady('f'))
{
flash_copy('f');
printf("f to copy\n");
q=0;
}
if(IsDriveReady('g'))
{
flash_copy('g');
printf("g to copy\n");
q=0;
}
if(IsDriveReady('h'))
{
flash_copy('h');
printf("h to copy\n");
q=0;
}
if(IsDriveReady('i'))
{
flash_copy('i');
printf("i to copy\n");
q=0;
}
}
q=1;
printf("Again? 1/0\n");
scanf("%d",&a);
}while(a==1);
}
5 SCREENSHOTS
. 1
. 2 f
. 3
. 4 f
. 5 f
. 6
. 7 ( )
. ++.
C++ .
Microsoft Developer Network [ ]. . : http://msdn.microsoft.com/
Wikipedia [ ]. . : http://ru.wikipedia.org/