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
[68619] Re:Re:Re:[C++Builder 2010] 특정 프로그램차단 오류...헬프미
송신영 [palindrome] 2247 읽음    2012-11-20 10:25
첨부한 소스코드 참고하세요.

C++ Builder 2010으로 작성된 코드입니다.





void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
    static int nCount = 0;
    Panel1->Caption = nCount++;

    if(CheckBox1->Checked) {
        AnsiString sClassName = Edit1->Text;

        HWND wnd = FindWindow(sClassName.c_str(), NULL);

        if (wnd)
        {
            PostMessage(wnd, WM_SYSCOMMAND, SC_CLOSE, 0); // <===== 윈도우 Close 시킴. 
            AnsiString sMessage;
            sMessage.printf("%s 윈도우를 종료시켰습니다.", sClassName.c_str());
            Memo1->Lines->Add(sMessage);
        }
    }

    if(CheckBox2->Checked) {
        AnsiString sProcessName = Edit2->Text;

        HANDLE hProcessSnap;
        HANDLE hProcess;
        PROCESSENTRY32 pe32;
        DWORD dwPriorityClass;

        // Take a snapshot of all processes in the system.
        hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
        if (hProcessSnap == INVALID_HANDLE_VALUE)
        {
            return;
        }

        // Set the size of the structure before using it.
        pe32.dwSize = sizeof(PROCESSENTRY32);

        // Retrieve information about the first process,
        // and exit if unsuccessful
        if (!Process32First(hProcessSnap, &pe32))
        {
            CloseHandle(hProcessSnap); // Must clean up the snapshot object!
            return;
        }

        // Now walk the snapshot of processes, and
        // display information about each process in turn
        do
        {


            // Retrieve the priority class.
            dwPriorityClass = 0;
            hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pe32.th32ProcessID);

            if(strcmp(sProcessName.c_str(), pe32.szExeFile) == 0) {
                TerminateProcess(hProcess,PROCESS_TERMINATE); // <===== 프로세스 종료 시킴.

                AnsiString sMessage;
                sMessage.printf("%s 프로세스를 종료시켰습니다.", pe32.szExeFile);
                Memo1->Lines->Add(sMessage);
            }
        }
        while (Process32Next(hProcessSnap, &pe32));

        CloseHandle(hProcessSnap);
    }
}


Scytale 님이 쓰신 글 :
: 네 그건알죠 ㅠㅠ
: 소스가 어떻게되요 그럼 ㅠㅠ?
: 제가초보라 아예몰라요 ㅠㅠㅠㅠㅠ

+ -

관련 글 리스트
68576 [C++Builder 2010] 특정 프로그램차단 오류...헬프미 Scytale 1579 2012/11/19
68578     Re:[C++Builder 2010] 특정 프로그램차단 오류...헬프미 Intotheblue 1649 2012/11/19
68619             Re:Re:Re:[C++Builder 2010] 특정 프로그램차단 오류...헬프미 송신영 2247 2012/11/20
68620                 Re:Re:Re:Re:[C++Builder 2010] 특정 프로그램차단 오류...헬프미 Scytale 1522 2012/11/20
Google
Copyright © 1999-2015, borlandforum.com. All right reserved.