#include <tlhelp32.h>
HWND FindWindowHandle;
BOOL CALLBACK EnumWindowsProc(HWND hwnd,LPARAM lParam);
void CFindHandleDlg::OnButton1()
{
// TODO: Add your control notification handler code here
UpdateData();
PROCESSENTRY32 pe[50];
HANDLE hSnapshot=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
if (!hSnapshot)
{
//printf("Unable to create snapshot!\n");
::MessageBoxA(NULL, "CreateToolhelp32Snapshot() : Fail!", NULL,NULL);
}
// prepare to enumerate the processes....
//PROCESSENTRY32 pe[50];
ULONG count=0;
// remember to init the structure...
pe[0].dwSize=sizeof(PROCESSENTRY32);
BOOL retval=Process32First(hSnapshot,&pe[0]);
while(retval)
{
// increment the process count
count++;
pe[count].dwSize=sizeof(PROCESSENTRY32);
// display the process name and ID
retval=Process32Next(hSnapshot,&pe[count]);
}
// since we are done, remember to close the snapshot handle
CloseHandle(hSnapshot);
for(int i=0; i<50; i++)
{
char sss[100];
//::wcstombs(sss, (const unsigned short *)pe[i].szExeFile, 100);
if(strcmp(pe[i].szExeFile, (LPSTR)(LPCTSTR)m_strProcessImageName)==0)
{
if(::EnumWindows(&EnumWindowsProc,(LPARAM)pe[i].th32ProcessID)==false)
{
sprintf(sss, "%x", FindWindowHandle);
AfxMessageBox(sss);
}
}
}
}
BOOL CALLBACK EnumWindowsProc(HWND hwnd,LPARAM lParam)
{
DWORD pid;
GetWindowThreadProcessId(hwnd,&pid);
if(lParam==pid && IsWindowVisible(hwnd))
{
#if defined(_DEBUG)
TCHAR name[255]={0,};
GetWindowText(hwnd,name,255);
TRACE("%s 0x%08x(%d) 0x%08x(%d)\n",name, hwnd,hwnd,pid,pid);
#endif
FindWindowHandle = hwnd;
return false;
}
return true;
}
'프로그래밍 팁 > etc' 카테고리의 다른 글
어플리케이션에서 자바스크립트 호출하기 (0) | 2010.08.12 |
---|---|
프로세스 이름으로 PID 찾기 (0) | 2010.08.12 |
유니코드 구분 예제 (1) | 2010.06.08 |
클립보드에 문자넣기 (2) | 2010.05.15 |
바로가기 아이콘 생성 (0) | 2010.05.14 |