CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    May 2004
    Location
    Singapore
    Posts
    14

    Question Get message when excute a infinite loop

    hi, guys

    Is there any functions in Visual C++ which have the same function like DoEvents in VB or doEvents in Java?

    I have to make the program get response to a windows message when it is running in a infinite loop.

    Is there any fuction can achieve this?

    thank u very much in advance!

  2. #2
    Join Date
    Jan 2004
    Location
    Punjab, India
    Posts
    113
    Hi there were 96 results, i found by searching these forum for keyword 'DoEvents'. Check it Out here

  3. #3
    Join Date
    Feb 2002
    Posts
    3,788

    Re: Get message when excute a infinite loop

    Originally posted by jfk_lili
    hi, guys

    Is there any functions in Visual C++ which have the same function like DoEvents in VB or doEvents in Java?

    I have to make the program get response to a windows message when it is running in a infinite loop.

    Is there any fuction can achieve this?

    thank u very much in advance!
    Code:
    void CDlg::DoEvents()
    {
    	MSG msg;
    	while (PeekMessage (&msg, NULL, 0, 0, PM_REMOVE ))
    	{
    		TranslateMessage(&msg);		
    		DispatchMessage(&msg);
    	}
    }

  4. #4
    Join Date
    May 2004
    Location
    Singapore
    Posts
    14
    Amit and Alin thank u guys very much. Now it works fine.

    and Alin, i hv tried to delete the TranslateMessage, and make it like this:
    while (PeekMessage (&msg, NULL, 0, 0, PM_REMOVE ))
    {
    DispatchMessage(&msg);
    }

    and in my program, it works also fine. I hv read MSDN abt TranslateMessage, but i m still not sure about the function of it.

    Could u please give me more detail abt it? or is there any article abt it? better wiz an example

    Thank u very much in advance!!!

  5. #5
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396
    Hi, jfk_lili !
    I have to make the program get response to a windows message when it is running in a infinite loop
    In multithreaded system you should use a worker thread to perform a "infinite loop", having your main (GUI) thread still responsible.
    Take a look at this J.Newcomer's article:
    Using Worker Threads

  6. #6
    Join Date
    May 2004
    Location
    Singapore
    Posts
    14
    Thanks very much VictorN!

    so what have been suggested above just can work under a single thread environment? for multi-thread it cannot work?

  7. #7
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396
    for multi-thread it cannot work?
    I wrote you: "... you should...", not "you MUST" use a worker thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured