본문 바로가기
Programming/Win_API

실행 중인 Class, Caption, Process 이름 구하기

by bbolmin 2014. 1. 8.



EnumWindows


-> [ GetClassName, GetWindowText ]




CreateToolhelp32Snapshot

Process32First

Process32Next


-> [ PROCESSENTRY32구조체의 szExeFile ]



#include "Windows.h"
#include "tlhelp32.h"
#include "tchar.h"
#include "stdio.h"


BOOL CALLBACK EnumWindowProc(HWND hwnd, LPARAM lParam)
{
	TCHAR classname[100] = {0};
	TCHAR titlename[100] = {0};

	GetClassName (hwnd, (LPTSTR)&classname, 100);
	GetWindowText(hwnd, (LPTSTR)&titlename, 256);


	if(_tcslen(titlename) != 0 )
		_tprintf(_T("%-45s || %s \n"), titlename, classname);

	return true;
}

BOOL ProcessList()
{
	HANDLE   hProcess = NULL;
	PROCESSENTRY32 ppe = {0};

	hProcess = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 );
	ppe.dwSize = sizeof( PROCESSENTRY32 );

	if( Process32First( hProcess, &ppe ) )
	{
		do 
		{
			_tprintf(_T("%-30s (%d) \n"), ppe.szExeFile, ppe.th32ProcessID);

		} while ( Process32Next( hProcess, &ppe ) );
	}

	CloseHandle (hProcess);

	return TRUE;

}


void main()
{
	_tprintf(_T("===== [ TITLE || ClassName ] ===== \n"));
	EnumWindows(EnumWindowProc, 0);

	_tprintf(_T("\n\n===== [ ProcessName (PID) ] ===== \n"));
	ProcessList();

}





Pname.exe