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

📄 unit1.cpp

📁 《Visual C++编程技巧典型案例解析:基础与应用篇(下)(含1CD-ROM)——编程技巧典型案例集锦系列》源码
💻 CPP
字号:
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
#define WordForNT
#include "GetWord.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
ABuffer myABuf;
WBuffer myWBuf;
char abuf[512];
HINSTANCE myDll;
HANDLE  killProcessHandle;
unsigned long CurrentProcessID;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
  CurrentProcessID=GetCurrentProcessId();
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button1Click(TObject *Sender)
{
  myDll=LoadLibrary("wordsys.dll");
  FreeLibrary(myDll);
  (FARPROC)GetWord=GetProcAddress(myDll,"GetWord");
  if(GetWord==NULL)
    {
      ShowMessage("没有加载wordsys.dll");
      return;
    }
  Button1->Enabled=false;
  Button2->Enabled=true;
  Timer1->Enabled=true;
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button3Click(TObject *Sender)
{
  if(Edit1->Text!="")
    {
      ListBox1->Items->Add(Edit1->Text);
      Edit1->Text="";
    }
  else
    ShowMessage("下面的输入框图不能为空");
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
char *found;
GetWord(&myWBuf,&myABuf);
for(int i=0;i<ABufCount;i++)
  {
    if(myABuf.Wp[i].Pos==0)
      continue;
    myABuf.Sp[i].Buffer[myABuf.Wp[i].Pos]=0;
    if (CurrentProcessID!=myABuf.Wp[i].ProcessIdORHandle)
    for(int j=0;j<ListBox1->Items->Count;j++)
      {
        found=strstr(myABuf.Sp[i].Buffer,ListBox1->Items->Strings[j].c_str());
        if(found!=NULL)
          {
            killProcessHandle=OpenProcess(PROCESS_TERMINATE,true,myABuf.Wp[i].ProcessIdORHandle);
            if(killProcessHandle!=NULL)
              {
                TerminateProcess(killProcessHandle,0);
                break;
              }
          }
      }
  }

for(int i=0;i<WBufCount;i++)
  {
    if(myWBuf.Wp[i].Pos==0)
      continue;
    WideCharToMultiByte (CP_ACP	,WC_COMPOSITECHECK,(wchar_t*)myWBuf.Sp[i].Buffer,myWBuf.Wp[i].Pos,abuf,2000,NULL,NULL);
    abuf[myWBuf.Wp[i].Pos]=0;
    if(CurrentProcessID!=myWBuf.Wp[i].ProcessIdORHandle)
      {
        for(int j=0;j<ListBox1->Items->Count;j++)
          {
            found=strstr(abuf,ListBox1->Items->Strings[j].c_str());
            if(found!=NULL)
              {
                killProcessHandle=OpenProcess(PROCESS_TERMINATE,true,myWBuf.Wp[i].ProcessIdORHandle);
                if(killProcessHandle!=NULL)
                  {
                    TerminateProcess(killProcessHandle,0);
                    break;
                  }
              }
          }
      }
  }
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
  Timer1->Enabled=false;
  Button2->Enabled=false;
  Button1->Enabled=true;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button4Click(TObject *Sender)
{
  ListBox1->Items->Clear();
}
//---------------------------------------------------------------------------

⌨️ 快捷键说明

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