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

- 11-02
- 144,923 회
- 0 건
IsVisible 함수는 프로세스 이름(ProcessName)으로 현재 활성창인지 확인합니다.
[code] 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; [/code]
로그인 후 댓글내용을 입력해주세요