Unit1.cpp
上传用户:gyjjlc
上传日期:2013-03-29
资源大小:2124k
文件大小:3k
源码类别:

多显示器编程

开发平台:

C++ Builder

  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include "Unit1.h"
  5. #include "Unit3.h"
  6. //---------------------------------------------------------------------------
  7. #pragma package(smart_init)
  8. #pragma link "PBFolderDialog"
  9. #pragma link "PBFolderDialog"
  10. #pragma resource "*.dfm"
  11. TForm1 *Form1;
  12. //---------------------------------------------------------------------------
  13. __fastcall TForm1::TForm1(TComponent* Owner)
  14.     : TForm(Owner)
  15. {
  16. }
  17. //---------------------------------------------------------------------------
  18. void __fastcall TForm1::Button1Click(TObject *Sender)
  19. {
  20.     //打开文件夹选择对话框
  21.     if(PBFolderDialog1->Execute())
  22.     {
  23.         //在文件夹选择对话框选中的子文件夹放入文本框
  24.         Edit1->Text=PBFolderDialog1->Folder;
  25.     }
  26. }
  27. //---------------------------------------------------------------------------
  28. //启动文件搜索
  29. void __fastcall TForm1::Button2Click(TObject *Sender)
  30. {
  31.     //存放匹配文件名的列表框
  32.     ListBox1->Items->Clear();
  33.     //取掉包含文本部分最后的回车、换行符
  34.     AnsiString str=Memo1->Text.SubString(1,Memo1->Text.Length()-2);
  35.     //包含文本部分为空时,不再继续动作
  36.     if(str.IsEmpty())return;
  37.     //调用线程构造函数创建线程,用搜索文件的诸参数初始化现成的成员变量
  38.     pThread=new TSearchFileThread(false,Edit1->Text,ComboBox1->Text,str,CheckBox1->Checked);
  39.     //防止搜索期间线程重复载入,禁止“搜索”按钮使能
  40.     Button2->Enabled=false;
  41. }
  42. //---------------------------------------------------------------------------
  43. //停止搜索
  44. void __fastcall TForm1::Button3Click(TObject *Sender)
  45. {
  46.     //发出线程终止的指令
  47.     pThread->Terminate();
  48. }
  49. //---------------------------------------------------------------------------
  50. //线程终止事件响应函数
  51. void __fastcall TForm1::ThreadOnEnd(TObject *Sender)
  52. {
  53.     //线程终止事件发生,允许线程再次启动
  54.     Button2->Enabled=true;
  55. }
  56. //---------------------------------------------------------------------------
  57. //文件列表框中鼠标双击事件响应函数
  58. void __fastcall TForm1::ListBox1DblClick(TObject *Sender)
  59. {
  60.     AnsiString CmdLine;
  61. char lpBuffer[64];
  62.     //取当前选中列表项的索引号
  63.     int mIdx=ListBox1->ItemIndex;
  64.     //当前选中列表项有效时...
  65.     if(mIdx!=-1)
  66.     {
  67.         //取选中的文件名
  68.         AnsiString strFile = ListBox1->Items->Strings[mIdx];
  69.         //取当前文件名的扩展名,转为大写方式
  70.         CmdLine=ExtractFileExt(strFile).UpperCase();
  71.         //当前文件名的扩展名为.htm或.html时...
  72.         if((CmdLine==".HTM")||(CmdLine==".HTML"))
  73.         {
  74.             //取Windows目录的全路径名
  75.             GetWindowsDirectory(lpBuffer,sizeof(lpBuffer));
  76.             //建立命令行
  77.             CmdLine=lpBuffer;
  78.          CmdLine+="\EXPLORER.EXE /n,/e,"+strFile;
  79.             //创建进程,即调用网页浏览器
  80.             WinExec(CmdLine.c_str(),SW_SHOW);
  81.         }
  82.         else
  83.         {
  84.             //将选中的文件装入表单Form3的Memo1
  85.             Form3->Memo1->Lines->LoadFromFile(strFile);
  86.             //以无模式方式打开窗口(表单Form3)
  87.             Form3->Show();
  88.         }
  89.     }
  90. }
  91. //---------------------------------------------------------------------------