Hey all,
I am trying to check if a .exe file is open, if it is open bring it to foreground, if it is not open open .exe file and bring to foreground. The code I have written doesnt seem to recognise if the program is open or not as it always opens the .exe file even if the .exe file is already open. I am using MSVC 6 MFC and the code I am using is:
if (!"\EvolveTraffic.exe")
{
HWND hWnd = ::FindWindow(NULL,"EvolveTraffic.exe");
:: SetForegroundWindow(hWnd);
}else
{
ShellExecute(this->m_hWnd,"open",
"\EvolveTraffic.exe","","", SW_SHOW );hEvent = CreateEvent(NULL,FALSE,FALSE,"EvolveTraffic");
WaitForSingleObject(hEvent,50);
keybd_event(VK_RETURN,0x1c,0 , 0); // Press Enter
keybd_event(VK_RETURN,0x9c,KEYEVENTF_KEYUP,0); // Release Enter
}
I know there is a:
ifstream("\EvolveTraffic.exe");
if (!"\EvolveTraffic.exe".is_open())
method, but as the file is a .exe file can I use "ifstream". Also if I use ".is_open()" I get a compile error of:
"error C2228: left of '.is_open' must have class/struct/union type"
Does anyone have any ideas,thanks for your help.
Colm