如何做一个程序
让它点了一项复制功能后可以做到
1。把U盘插如电脑 然后就把文件直接复制U盘中 然后自动把U盘弹出
2。弹出一个窗口问是否继续执行改功能。
3。执行的话就再执行1的功能 不执行了就结束改功能

解决方案 »

  1.   

    unit main;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls,ShellApi;type
      TForm1 = class(TForm)
        Button1: TButton;
        procedure Button1Click(Sender: TObject);
        procedure FormCreate(Sender: TObject);
      private
        { Private declarations }
      public
        procedure WMDeviceChange( var Msg:Tmessage);message WM_DEVICECHANGE ;
      end;
    const
       BDT_DEVICEARRIVAL=$8000;   //U盘插上时的消息
    type
      TU_drive=array[1..24] of integer;// 保存 U盘的数字符号
    var
      Form1: TForm1;
      U_cnt: integer;  //U 盘个数;
      U_drive:TU_drive;implementation{$R *.dfm}
    {---------文件复制函数----------}
      procedure Xcopy(ToDir,FromDir:String);
      var
        OpStruc:TSHFileOpStruct;  //声明一个TSHFileOpStruct 类型, 在ShellApi.pas 里
        FromBuf,ToBuf: Array[0..128] of char;
      begin
          FillChar(FromBuf,sizeof(FromBuf),0);
          FillChar(ToBuf,sizeof(ToBuf),0);
          StrPCopy(FromBuf,FromDir+'*.txt');     //
          StrPCopy(ToBuf,ToDir);
          with  OpStruc do
          begin
             Wnd:=form1.Handle ;
             wFunc:=FO_COPY; //执行拷贝操作
             pFrom:=@FromBuf;
             pTo:=@ToBuf;  //FOF_SILENT or FOF_NOCONFIRMMKDIR or
             fFlags:= FOF_SILENT or FOF_NOCONFIRMMKDIR or FOF_NOCONFIRMATION or FOF_RENAMEONCOLLISION ;
                   //不带进度条     直接建立文件夹       一切询问以 YES 回答
             fAnyOperationsAborted:=False;
             hNameMappings:=Nil;
             lpszProgressTitle:=Nil;
          end;
          ShFileOperation(OpStruc);// 调用API函数,完成操作
          showmessage('copying');
      end;
    {----------- 初始话 ------------}
      procedure  init();
      var
        i:integer;
      begin
        U_cnt:=0;
        for i:=1 to 24 do
          U_drive[i]:=0;
      end;{---------- ↓判断是否为U盘 ↓--------}  function isudriver( num:integer): boolean;
      var
        Drive:string;
        DriveType: WORD;
      begin
        Drive:= char(ord('A') + num) + ':\';
        DriveType:=GetDriveType(Pchar(Drive));
        if DriveType=DRIVE_REMOVABLE then
          result:=true
        else
          result:=false;
      end;{----------↓本地盘扫描 ↓------------}
    procedure scan();
     var
       i:integer;
     begin
        init(); //初始化,避免重复记数
        for i:=3 to 25 do      //从D 盘开始扫描
          begin
             if isudriver(i) then
               begin
                 U_cnt:=U_cnt + 1;
                 U_drive[U_cnt]:=i;   //将盘符的数字代号保存
               end;
          end;
     end;{-------------  test  -----------------}
    procedure TForm1.Button1Click(Sender: TObject);
    var
      i:integer;
      str:string;
    begin
      scan();
      i:=U_drive[1];
      form1.Caption:=inttostr(U_cnt) + ' 个盘,该盘为' + char(i + ord('A') );
      str:=char(i+ord('A'));
      Xcopy('c:\temp', pchar(str+ ':\'));
    end;
     {-----------↓ 初始化 ↓-----------}
    procedure TForm1.FormCreate(Sender: TObject);
    begin
       init();
    end;
    {----------↓ U盘插入事件 ↓ ----------}
      procedure TForm1.WMDeviceChange(var Msg:Tmessage);
      var
        i:integer;
        str:string;
      begin
        inherited; //什么意思?
        case Msg.WParam of
            BDT_DEVICEARRIVAL:       // U 盘插上事件
               begin
                 form1.Tag:=form1.Tag+1;
                 form1.Caption:=inttostr(form1.tag);
                 if form1.tag mod 3=0 then
                   begin
                     scan();
                     if U_cnt>0 then
                       for i:=1 to U_cnt do
                         begin
                         str:=char(U_drive[i]+ ord('A'));  //取盘符
                         showmessage('begin copy '+ str);
                         Xcopy('c:\temp', pchar(str+ ':\'));
                         showmessage('end of copy!');
                         end;
                   end;
               end;
        end;  // end of case
     end;end.
      

  2.   

    自己改一下,如果你想要EXE文件的话,请到CSDN外包竞拍。http://prj.csdn.net/^^
      

  3.   

    WMDevice  是你自己下的组件吗?
      

  4.   

    BDT_DEVICEARRIVAL=$8000;  是一个自定义消息常量马?
    自定义消息常量不是取值上限为:$7FFF的吗?
      

  5.   

    现在有关于 USB的控件么就是好像 ARPO和SPCOMM一样的控件对USB一直很关注 谁有关于USB视频采集的资料贡献下~