C++Builder Programming Forum
C++Builder  |  Delphi  |  FireMonkey  |  C/C++  |  Free Pascal  |  Firebird
볼랜드포럼 BorlandForum
 경고! 게시물 작성자의 사전 허락없는 메일주소 추출행위 절대 금지
C++빌더 포럼
Q & A
FAQ
팁&트릭
강좌/문서
자료실
컴포넌트/라이브러리
메신저 프로젝트
볼랜드포럼 홈
헤드라인 뉴스
IT 뉴스
공지사항
자유게시판
해피 브레이크
공동 프로젝트
구인/구직
회원 장터
건의사항
운영진 게시판
회원 메뉴
북마크
볼랜드포럼 광고 모집

C++빌더 Q&A
C++Builder Programming Q&A
[39676] 델파이 볼줄 아시는분! (빌더도 볼줄 아셔야 할듯 ㅎ) 빌더 소스로 바꿔주세요 ㅠ
이성제 [14dia] 968 읽음    2005-03-28 23:36
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls,
Forms, Dialogs, StdCtrls, TlHelp32;

type
TForm1 = class(TForm)
   ListBox1: TListBox;
   B_Search: TButton;
   B_Terminate: TButton;
   procedure B_SearchClick(Sender: TObject);
   procedure B_TerminateClick(Sender: TObject);
private
   { Private declarations }
public
   { Public declarations }
end;

var
Form1: TForm1;

implementation
{$R *.DFM}

// kernel32.dll을 사용하여 현재 떠있는 process를 읽어온다
procedure Process32List(Slist: TStrings);
var
    Process32: TProcessEntry32;
    SHandle:    THandle;   // the handle of the Windows object
    Next:         BOOL;
begin
    Process32.dwSize := SizeOf(TProcessEntry32);
    SHandle               := CreateToolHelp32Snapshot(TH32CS_SNAPPROCESS, 0);
    
    if Process32First(SHandle, Process32) then
        begin
        // 실행화일명과 process object 저장
        Slist.AddObject(Process32.szExeFile, TObject(Process32.th32ProcessID));
        repeat
            Next := Process32Next(SHandle, Process32);
            if Next then
                Slist.AddObject(Process32.szExeFile, TObject(Process32.th32ProcessID));
        until not Next;
        end;
    CloseHandle(SHandle);   // closes an open object handle
end;

procedure TForm1.B_SearchClick(Sender: TObject);
begin
    // 현재 실행중인 process를 검색
    ListBox1.Items.Clear;
    Process32List(ListBox1.Items);
end;

procedure TForm1.B_TerminateClick(Sender: TObject);
var
    hProcess: THandle;
    ProcId:    DWORD;
    TermSucc: BOOL;
begin
    // 현재 실행중인 process를 kill
    if ListBox1.ItemIndex < 0 then System.Exit;
    ProcId    := DWORD(ListBox1.Items.Objects[ListBox1.ItemIndex]);
    // 존재하는 process object의 handle을 return한다
    hProcess := OpenProcess(PROCESS_ALL_ACCESS, TRUE, ProcId);
    if hProcess = NULL then
        ShowMessage('OpenProcess error !');
    // 명시한 process를 강제 종료시킨다
    TermSucc := TerminateProcess(hProcess, 0);
    if TermSucc = FALSE then
        ShowMessage('TerminateProcess error !')
    else
        ShowMessage(Format('Process# %x terminated successfully !', [ProcId]));
end;

end.


이거 빌더 소스로좀 ㅠ

+ -

관련 글 리스트
39676 델파이 볼줄 아시는분! (빌더도 볼줄 아셔야 할듯 ㅎ) 빌더 소스로 바꿔주세요 ㅠ 이성제 968 2005/03/28
Google
Copyright © 1999-2015, borlandforum.com. All right reserved.