Thread: Loop when inactive ?

  1. #1
    Registered User
    Join Date
    Nov 2002

    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.

    while(GetMessage(&Msg, hWnd, 0, 0) > 0)
    		static HWND hIexplore;
    		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 ?

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    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.


  3. #3
    Registered User
    Join Date
    Nov 2002
    Everything working as intended now, thank you

  4. #4
    train spotter
    Join Date
    Aug 2001
    near a computer
    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)
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. My loop within loop won't work
    By Ayreon in forum C Programming
    Replies: 3
    Last Post: 03-18-2009, 10:44 AM
  2. While loop misbehaving (or misunderstanding)
    By mattAU in forum C Programming
    Replies: 2
    Last Post: 08-28-2006, 02:14 AM
  3. Personal Program that is making me go wtf?
    By Submeg in forum C Programming
    Replies: 20
    Last Post: 06-27-2006, 12:13 AM
  4. loop issues
    By kristy in forum C Programming
    Replies: 3
    Last Post: 03-05-2005, 08:14 AM
  5. when a while loop will stop ?
    By blue_gene in forum C Programming
    Replies: 13
    Last Post: 04-20-2004, 03:45 PM