線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:2093
推到 Plurk!
推到 Facebook!

怎麼關閉視窗?

尚未結案
unimax
一般會員


發表:2
回覆:1
積分:0
註冊:2005-06-17

發送簡訊給我
#1 引用回覆 回覆 發表時間:2005-06-17 13:14:02 IP:61.224.xxx.xxx 未訂閱
請問如何讓BCB程式 能夠在目前已開啟的程式中 關閉其中的某個程式?
cashyy
高階會員


發表:117
回覆:322
積分:212
註冊:2004-04-30

發送簡訊給我
#2 引用回覆 回覆 發表時間:2005-06-17 14:05:37 IP:211.74.xxx.xxx 未訂閱
您好! 小弟是用關閉執行緒的方式,不知是否為您要的!
//---------------------------------------------------------------------------    #include 
#pragma hdrstop    /* 執行緒 */
#include 
DWORD WinHandle[255];
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------    void __fastcall TForm1::Button1Click(TObject *Sender)
{
  PROCESSENTRY32 *ProcessEntry32=new PROCESSENTRY32;
  HANDLE AHandle;
  LPWSTR APath;
  bool isFound;
  int i;
  String p,h;
  i=0;
  ListBox1->Items->Clear();
  AHandle = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
  isFound = true;
  try
  {
    ProcessEntry32->dwSize = sizeof(PROCESSENTRY32);
    isFound = Process32First(AHandle, ProcessEntry32);
    while(isFound)
    {
      OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ,
                                false, ProcessEntry32->th32ProcessID);
      WinHandle[i  ] = ProcessEntry32->th32ProcessID;
      p = ProcessEntry32->szExeFile;
      ListBox1->Items->Add(p);
      isFound = Process32Next(AHandle, ProcessEntry32);
    }
  }
  catch ( ... )
  {
  }
}
//---------------------------------------------------------------------------    void __fastcall TForm1::Button2Click(TObject *Sender)
{
  HANDLE AhProcess;
  DWORD test;
  test=WinHandle[ListBox1->ItemIndex];
  AhProcess = OpenProcess(PROCESS_ALL_ACCESS, true, test);
  TerminateProcess(AhProcess, 0);
  ListBox1->Refresh();
}
//---------------------------------------------------------------------------
andychang1690
資深會員


發表:20
回覆:694
積分:442
註冊:2003-03-14

發送簡訊給我
#3 引用回覆 回覆 發表時間:2005-06-17 18:40:40 IP:221.169.xxx.xxx 未訂閱
unimax:方法很多種,下例是最簡單的一種之一:
  AnsiString S="連環新接龍";
  HWND hMsgWnd;
  hMsgWnd = FindWindow(NULL, S.c_str());
  if (  hMsgWnd )
    SendMessage(hMsgWnd, WM_CLOSE, 0, 0);
請參考!    
Andy Chang
------
Andy Chang
系統時間:2024-05-04 6:58:57
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!