home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 9 / CDACTUAL9.iso / progs / CB / DATA.Z / PROC.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1996-08-05  |  6.3 KB  |  216 lines

  1. //---------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4.  
  5. #include "proc.h"
  6. #include "another.h"
  7. //---------------------------------------------------------------------
  8. #pragma resource "*.dfm"
  9. TForm1 *Form1;
  10. //---------------------------------------------------------------------
  11. static int stat=1;
  12. int i=0;
  13. //---------------------------------------------------------------------
  14. __fastcall TForm1::TForm1(TComponent *Owner)
  15.   : TForm(Owner)
  16. {
  17. }
  18. //---------------------------------------------------------------------
  19. bool __stdcall EnumProc(/*HWND*/void * hWnd,/*LPARAM*/long/*lp*/)
  20. {
  21.    unsigned long* pPid;   //LPDWORD
  22.    unsigned long result;      //DWORD
  23.    void *hg;                  //HGLOBAL
  24.    unsigned long id;
  25.  
  26.    if(hWnd==NULL)
  27.       return false;
  28.  
  29.    (int)hg = GlobalAlloc(GMEM_SHARE,sizeof(unsigned long));
  30.    pPid = (unsigned long *)GlobalLock((int)hg);
  31.  
  32.    result = GetWindowThreadProcessId((int)hWnd,pPid);
  33.  
  34.    if(result){
  35.       char title[110];
  36.       char className[95];
  37.       char totalStr[256];
  38.       GetClassName((int)hWnd,className,95);
  39.       GetWindowText((int)hWnd,title,110);
  40.       id=*pPid;
  41.       itoa(id,totalStr,10);
  42.       strcat(totalStr,"\t");
  43.       if(title){
  44.          strcat(totalStr,title);
  45.          strcat(totalStr,"\t");
  46.       }
  47.       strcat(totalStr,className);
  48.       Form1->ListBox1->Items->Add((String)totalStr);
  49.    }
  50.    else{
  51.       GlobalUnlock((int)hg);
  52.       GlobalFree((int)hg);
  53.       return false;
  54.    }
  55.    GlobalUnlock((int)hg);
  56.    GlobalFree((int)hg);
  57.    return true;
  58. }
  59.  
  60. //---------------------------------------------------------------------
  61. void __fastcall TForm1::RadioButton3Click(TObject* /*Sender*/)
  62. {
  63.  
  64. }
  65. //----------------------------------------------------------------------------
  66. void __fastcall TForm1::Exit1Click(TObject* /*Sender*/)
  67. {
  68.    PostQuitMessage(0);
  69. }
  70. //----------------------------------------------------------------------------
  71. void __fastcall TForm1::About1Click(TObject* /*Sender*/)
  72. {
  73.    Form2->ShowModal();
  74. }
  75. //----------------------------------------------------------------------------
  76. void __fastcall TForm1::SpeedButton1Click(TObject* /*Sender*/)
  77. {
  78.    Exit1Click(0);
  79. }
  80. //----------------------------------------------------------------------------
  81. void __fastcall TForm1::SpeedButton2Click(TObject* /*Sender*/)
  82. {
  83.    About1Click(0);
  84. }
  85. //----------------------------------------------------------------------------
  86.  void __fastcall TForm1::SpeedButton4Click(TObject* /*Sender*/)
  87. {
  88.    long lp=0;
  89.    ListBox1->Enabled=true;
  90.    ListBox1->Clear();
  91.    EnumWindows(EnumProc,lp);
  92.    Button2->Enabled=true;
  93.    SpeedButton3->Enabled=true;
  94. }
  95. //----------------------------------------------------------------------------
  96. void __fastcall TForm1::RadioButton1Click(TObject* Sender)
  97. {
  98.    TRadioButton *rbp =(TRadioButton*) Sender;
  99.    ListBox1->Font->Color=rbp->Font->Color;
  100. }
  101. //----------------------------------------------------------------------------
  102.  void __fastcall TForm1::Button2Click(TObject* /*Sender*/)
  103. {
  104.    SpeedButton4Click(0);
  105.    Button1->Enabled=false;
  106. }
  107. //----------------------------------------------------------------------------
  108.  void __fastcall TForm1::Button1Click(TObject* /*Sender*/)
  109. {
  110.    String str;
  111.    char *tmp;
  112.    int i;
  113.    i= ListBox1->ItemIndex;
  114.    if( i != -1){
  115.       String s;
  116.       tmp = new char[100];
  117.       s=ListBox1->Items->Strings[i];
  118.       strcpy(tmp,(char*)s.c_str());
  119.       tmp=strtok(tmp,"\t");
  120.    }
  121.    int id=atoi(tmp);
  122.    delete[] tmp;
  123.    unsigned int ps = OpenProcess(1,false,id);
  124.    if(ps){
  125.       if(!TerminateProcess(ps,-9)){
  126.          ShowMessage((String)"Could not end process specified!");
  127.       }
  128.       else{
  129.          ShowMessage((String)"Process successfully terminated!");
  130.       }
  131.    }
  132.    else{
  133.       ShowMessage((String)"Could not open process requested!");
  134.    }
  135. }
  136. //----------------------------------------------------------------------------
  137.  void __fastcall TForm1::New1Click(TObject* /*Sender*/)
  138. {
  139.    SpeedButton4Click(0);
  140. }
  141. //----------------------------------------------------------------------------
  142.  void __fastcall TForm1::Refresh1Click(TObject* /*Sender*/)
  143. {
  144.       SpeedButton4Click(0);
  145. }
  146. //----------------------------------------------------------------------------
  147.  void __fastcall TForm1::GroupBox1Click(TObject* /*Sender*/)
  148. {
  149.  
  150. }
  151. //----------------------------------------------------------------------------
  152.  void __fastcall TForm1::FormCreate(TObject* /*Sender*/)
  153. {
  154.    SpeedButton3->Glyph->LoadFromResourceName(0,(String)"IDB_ERASE");
  155. }
  156. //----------------------------------------------------------------------------
  157.  void __fastcall TForm1::SpeedButton3Click(TObject* /*Sender*/)
  158. {
  159.       ListBox1->Clear();
  160.       SpeedButton3->Enabled=false;
  161.       Button1->Enabled=false;
  162. }
  163. //----------------------------------------------------------------------------
  164.  void __fastcall TForm1::ListBox1Click(TObject* /*Sender*/)
  165. {
  166.    Button1->Enabled=true;
  167.    StatusBar1->SimpleText="Select 'Kill Selected PID' to terminate the process";
  168. }
  169. //----------------------------------------------------------------------------
  170.  
  171.  
  172. void __fastcall TForm1::FormShow(TObject */*Sender*/)
  173. {
  174.    if(stat){
  175.       stat= 0;
  176.       ListBox1->Items->Add((String)"Click on 'pid' Tool button above");
  177.    }
  178. }
  179. //---------------------------------------------------------------------
  180. void __fastcall TForm1::Timer1Timer(TObject */*Sender*/)
  181. {
  182.    switch(i){
  183.       case 0:{
  184.          Image1->Picture->Bitmap->LoadFromResourceName(0,(String)"BITMAP_5");
  185.          Image1->Refresh();
  186.          i=1;
  187.          return;
  188.       }
  189.       case 1:{
  190.          Image1->Picture->Bitmap->LoadFromResourceName(0,(String)"BITMAP_2");
  191.          Image1->Refresh();
  192.          i=2;
  193.          return;
  194.       }
  195.       case 2:{
  196.          Image1->Picture->Bitmap->LoadFromResourceName(0,(String)"BITMAP_3");
  197.          Image1->Refresh();
  198.          i=3;
  199.          return;
  200.       }
  201.       case 3:{
  202.          Image1->Picture->Bitmap->LoadFromResourceName(0,(String)"BITMAP_4");
  203.          Image1->Refresh();
  204.          i=4;
  205.          return;
  206.       }
  207.       case 4:{
  208.          Image1->Picture->Bitmap->LoadFromResourceName(0,(String)"BITMAP_1");
  209.          Image1->Refresh();
  210.          i=0;
  211.          return;
  212.       }
  213.    }//end switch
  214. }
  215.  
  216.