-
Loop when inactive ?
Hi, I'm trying to create a program which checks to see if another program is running and if it is, shut it down.
It's working as long as I keep the program in focus, but when it loses focus the loop holds I guess.
Code:
while(GetMessage(&Msg, hWnd, 0, 0) > 0)
{
static HWND hIexplore;
TranslateMessage(&Msg);
DispatchMessage(&Msg);
hIexplore = FindWindow("IEFrame", "Session control window - Microsoft Internet Explorer");
if(hIexplore != NULL)
{
SendMessage(hIexplore, WM_DESTROY, 0, 0);
SendMessage(hIexplore, WM_NCDESTROY, 0, 0);
}
}
Is there a way to make the loop run while minimized ?
Or am I doing it the wrong way ?
-
That's because you window has to recieve messages so your code will run.
Don't do the work inside your message loop. Create a timer and handle the WM_TIMER message in your window proc.
This article will help as well.
gg
-
Everything working as intended now, thank you :)
-
Or use PeekMessage()
This checks to see if there is a message for your app. If not it returns allowing you to poll for the other app.
GetMessage() will not return from the OS until there is a message for your app.
CPU useage will be near 100% though unless you check the rate (ie limit frame rate)