알짜게시판

실행 중인 프로세스가 활성 창인지 확인하는 함수

IsVisible 함수는 프로세스 이름(ProcessName)으로 현재 활성창인지 확인합니다.

function IsVisible(ProcessName: string): Boolean;
var
 SnapShot: THandle;
 ProcEntry: TProcessEntry32;
 ProcList: TList<DWORD>;

 function EnumWindowsProc(hWnd: THandle; List: TList<DWORD>): BOOL; stdcall;
 var
   ProcessID: DWORD;
 begin
   Result := True;

   if IsWindowVisible(hWnd) then
   begin
     GetWindowThreadProcessId(hWnd, @ProcessID);
     List.Add(ProcessID);
   end;
 end;

begin
 Result := False;

 SnapShot := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
 ProcList := TList<DWORD>.Create;
 try
   EnumWindows(@EnumWindowsProc, LParam(ProcList));

   ProcEntry.dwSize := SizeOf(TProcessEntry32);
   if Process32First(SnapShot, ProcEntry) then
   begin
     repeat
       if SameText(ProcEntry.szExeFile, ProcessName) then
      begin
         if ProcList.Contains(ProcEntry.th32ProcessID) then
         begin
           Result := True;
           Exit;
         end;
      end;
     until not Process32Next(SnapShot, ProcEntry);
   end;
 finally
   ProcList.Free;
   CloseHandle(SnapShot);
 end;
end;

로그인 후 댓글내용을 입력해주세요

제목 글쓴이 조회 날짜
델파이 TDirectory.Delete 대신 CMD 으로 폴더 삭제 74,852 25-09-10
델파이 폼이 모니터 한 가운데 있는 경우 자연스럽게 왼쪽으로 이동시키기 134,414 25-05-26
델파이 TrayIcon 이 흐릿하게 보이는 버그? 수정 128,816 24-12-12
델파이 실행 중인 프로세스가 활성 창인지 확인하는 함수 146,154 24-11-02
델파이 메세지 다이어그램(Message Dialog) 에 체크박스(CheckBox) 추가 133,075 24-10-30
델파이 윈도우 알림센터에 메시지 출력하기 56,234 23-06-20
델파이 중복 실행 방지 59,620 22-09-21
델파이 파일 포맷 알아내기 52,005 22-09-08
델파이 권한상승 2,807 20-09-04
델파이 Glyph 에 사용할 이미지 생성하기 2,294 20-09-02
델파이 bsNone 인 폼에서 드래그 및 크기조절 3,850 20-07-11
목록
보안IT사주클럽개봉닷컴회생의길자기계발