In the project, the foreground interface uses Flash, and the background uses the MFC dialog box for network communication. Close the Background dialog box while Flash is turned off.
In the timer, call Detectflashstate ().
The specific implementation methods are as follows:
void Cxxxxdlg::D etectflashstate ()
{
CString m_exefilename = "XxxFlash.exe";
LPCTSTR installname= (LPCTSTR) m_exefilename;
DWORD processid=1;
Processid=getprocessidfromname (Installname);
if (ProcessID = 0)
{
PostMessage (WM_CLOSE);
}
}
DWORD cxxxxdlg::getprocessidfromname (lpctstr name)
{
processentry32 pe;
dword id=0;
handle Hsnapshot=createtoolhelp32snapshot (th32cs_snapprocess,0);
pe.dwsize=sizeof (PROCESSENTRY32);
if (! Process32First (HSNAPSHOT,&PE))
return 0;
while (1)
{
pe.dwsize=sizeof ( PROCESSENTRY32);
if (Process32Next (HSNAPSHOT,&PE) ==false)
break;
If strcmp (Pe.szexefile, Name) ==0
{
id=pe.th32processid
break
}
CloseHandle (hSnapShot);
return ID;
}