Process?

This is a discussion on Process? within the Windows Programming forums, part of the Platform Specific Boards category; Every windows' application has a loop in it, right?! but this loop only runs when i move the mouse over ...

  1. #1
    * Death to Visual Basic * Devil Panther's Avatar
    Join Date
    Aug 2001
    Posts
    768

    Process?

    Every windows' application has a loop in it, right?!
    but this loop only runs when i move the mouse over the app's window... but I want to create something which will run even if i minumized the app's window...

    Do I need to create a process to do that? Is that what a process is?


    Thanks a million.
    Last edited by Devil Panther; 06-20-2003 at 05:07 AM.

  2. #2
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    The main loop is running constantly, regardless of whether the window has focus.
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  3. #3
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    >>> Every windows' application has a loop in it, right?!

    Mmmmm, that is not strictly true, however, I think for the kind of applications you are thinking about, let's say, yes.

    >>> but this loop only runs when i move the mouse over the app's window...

    No, that is not true. GetMessage() returns whenever there is a message there to get, the window does not need to be visible for this to happen. A process need never show a window, and yet happily perform regular tasks in response to a WM_TIMER message. Think of something like Outlook, it checks to see if you have any mail every so often regardless of it's window state.

    >>> but I want to create something which will run even if i minumized the app's window...

    So do so, no problem there.

    >>> Do I need to create a process to do that?

    All running programs are processes. You can have your program create more processes, but you don't need to to acheive what you want.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  4. #4
    * Death to Visual Basic * Devil Panther's Avatar
    Join Date
    Aug 2001
    Posts
    768
    I thought so too... that the loop is always running, but I tried to make my program work like that... I noticed that the loop is only running, when a message is been sent to the window, or the mouse is moving over it, so the window is been redrawen...

    Other wise, the loop does not run!!!

    So... can I use make a "side" process inside the program, so it will always run a specific code, even when the app's main loop does not run?



    OR: should i use WM_TIMER, to run the FUNCTION I need every 0.5sec or so?
    If so, where can I learn more about WM_TIMER (except iat msdn )


    Thanks.
    Last edited by Devil Panther; 06-20-2003 at 05:51 AM.
    "I don't suffer from insanity but enjoy every minute of it" - Edgar Allen Poe

    http://www.Bloodware.net - Developing free software for the community.

  5. #5
    id id
    Guest
    Hi.

    One Way:
    http://www.mvps.org/directx/articles..._game_loop.htm

    http://www.google.com.au/search?q=game+message+loop

    OR: should i use WM_TIMER, to run the FUNCTION I need every 0.5sec or so?
    If so, where can I learn more about WM_TIMER (except iat msdn )
    Yes.
    Pretty basic:
    Code:
    BOOL bSuccess = SetTimer(hWnd,   /* window handle */
    		1,          /* UINT_PTR nIDEvent - ID of this timer */
    		500,      /* Interval in milliseconds */
    		NULL);  /* TIMERPROC lpTimerFunc if required */
    if ( !bSuccess ) error;
    
    //When you're finished
    KillTimer(hWnd /* window handle */, 1 /*Timer ID */) ;
    And handle the WM_TIMER message in your window procedure.
    The wParam specifies the timer Id and it should return zero.

  6. #6
    Registered /usr
    Join Date
    Aug 2001
    Location
    Newport, South Wales, UK
    Posts
    1,261
    If you think about it, via the GetMessage/PeekMessage function, your program becomes part of a much larger system-wide loop that goes through all pending messages and distirbutes them to the windows that need them. So really your loop is always running, it is just not always iterating.

    WM_TIMER messages allow your program's loop to do things every time a given period (In milliseconds) elapses. To start a timer, use:-
    Code:
    SetTimer(hwnd, uEventID, uElapse, TimerProc);
    Where hwnd is the handle to your window, uEventID is a unique indentifier for the timer (So you can have multiple timers and do different things based on what this value is), uElapse is the time to elapse before sending the message (In milliseconds), and TimerProc is an optional procedure triggered by the message (In most cases this should be NULL).

    Note that you must destroy timers when you are finished with them, using:-
    Code:
    KillTimer(hwnd, uIDEvent);
    Note that WM_TIMER messages are not always sent accurately relative to the time elapsed, due to the fact that it is sent through the system message queue and there may be other time-consuming messages before it or a program that is not responding will block the queue until it continues or is closed. Another way of accurately performing tasks relative to time is via the Sleep() function.

  7. #7
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    >>> Other wise, the loop does not run!!!

    As several of has said now, yes it is running, if you have no messages going to it, it won't do anything though. GetMessage() is a "blocking call", in that, if there are no messages there, it sits inside GetMessage() waiting for a message, it does not go round the loop over and over again waiting for something to happen - think about it, if it did, it would be using CPU time to basically do nothing!
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  8. #8
    * Death to Visual Basic * Devil Panther's Avatar
    Join Date
    Aug 2001
    Posts
    768
    I understand now guys... thanks.

    Just one more question... When you say blocking, the blocking is basicly an endless loop, until it's BREAK, no?

    Thanks again.
    "I don't suffer from insanity but enjoy every minute of it" - Edgar Allen Poe

    http://www.Bloodware.net - Developing free software for the community.

  9. #9
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    A "blocking" function is anything that when you call it, it stays there until what you have asked for happens.

    >>> is basicly an endless loop, until it's BREAK, no?

    No. There are other, more sophisticated ways of waiting. An interupt for example. Don't worry about it, when you call GetMessage() it will return imediately if there is a message inyour message queue. If there is'nt one, it will wait until there is.

    If you want to see if there is a message there but not necessarily process it now, use PeekMessage() instead.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. init adopts zombie process?
    By password636 in forum Linux Programming
    Replies: 4
    Last Post: 07-01-2009, 10:05 AM
  2. create a child process that creates a child process
    By cus in forum Linux Programming
    Replies: 9
    Last Post: 01-13-2009, 01:14 PM
  3. Replies: 3
    Last Post: 10-15-2008, 09:24 AM
  4. Problem with forking a process
    By Unitedroad in forum C Programming
    Replies: 10
    Last Post: 10-04-2007, 01:43 AM
  5. process programming
    By St0rM-MaN in forum Linux Programming
    Replies: 2
    Last Post: 09-15-2007, 07:53 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21