Unit1.cpp
上传用户:lhxd_sz
上传日期:2014-10-02
资源大小:38814k
文件大小:1k
源码类别:

VC书籍

开发平台:

C++ Builder

  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include "Unit1.h"
  5. //---------------------------------------------------------------------------
  6. #pragma package(smart_init)
  7. #pragma resource "*.dfm"
  8. TForm1 *Form1;
  9. //---------------------------------------------------------------------------
  10. __fastcall TForm1::TForm1(TComponent* Owner)
  11.         : TForm(Owner)
  12. {
  13. }
  14. //---------------------------------------------------------------------------
  15. void __fastcall TForm1::Button1Click(TObject *Sender)
  16. {
  17.   HWND hw;
  18.   char ss[300];
  19.   ListBox1->Clear();
  20.   hw=GetWindow(Handle,GW_HWNDFIRST);
  21.   while(hw!=0)
  22.   {
  23.     if(GetWindowText(hw,ss,255)>0)
  24.     {
  25.       ListBox1->Items->Add(ss);
  26.     }
  27.     hw=GetWindow(hw,GW_HWNDNEXT);
  28.   }
  29. }
  30. //---------------------------------------------------------------------------
  31. void __fastcall TForm1::Button2Click(TObject *Sender)
  32. {
  33.   HWND hw;
  34.   char ss[300];
  35.   int idx;
  36.   AnsiString ass,ass1;
  37.   idx=ListBox1->ItemIndex;
  38.   if(idx<0)return;
  39.   ass=ListBox1->Items->Strings[idx];
  40.   hw=GetWindow(Handle,GW_HWNDFIRST);
  41.   while(hw!=0)
  42.   {
  43.     if(GetWindowText(hw,ss,255)>0)
  44.     {
  45.       ass1=ss;
  46.       if(ass==ass1)
  47.         SendMessage(hw,WM_CLOSE,0,0);
  48.     }
  49.     hw=GetWindow(hw,GW_HWNDNEXT);
  50.   }
  51. }
  52. //---------------------------------------------------------------------------