CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 11 of 11
  1. #1
    Join Date
    Mar 2003
    Posts
    34

    DoEvents() in VC++?????

    How can I do a DoEvents() -like in VB- in VC++ / MFC?

    Thanks!

    Mainebound

  2. #2
    Join Date
    Feb 2002
    Posts
    3,788
    what DoEvents() does?

  3. #3
    Join Date
    Jun 2001
    Location
    Switzerland
    Posts
    4,443
    Basically like this:
    Code:
          MSG msg;
          while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
          {
             TranslateMessage(&msg);
             DispatchMessage(&msg);
          }
    Gabriel, CodeGuru moderator

    Forever trusting who we are
    And nothing else matters
    - Metallica

    Learn about the advantages of std::vector.

  4. #4
    Join Date
    Jan 2003
    Posts
    15

    It allows the OS to process the messages waiting in the messg queue

    I think there is no function or MFC for this in VC++ 6.0 (I suppose it is there in VC++ 7 as DoEvents())... You can use AfxBeginThread to do your work as a separate thread allowing the os to process other messages....

    Mahesh

  5. #5
    Join Date
    Sep 2002
    Location
    Singapore
    Posts
    673

    Re: DoEvents() in VC++?????

    Originally posted by mainebound
    How can I do a DoEvents() -like in VB- in VC++ / MFC?

    Thanks!

    Mainebound
    MFC or VC programs doesn't need to have DoEvents() as in VB. So there is no equivalent for VC.

  6. #6
    Join Date
    Jun 2001
    Location
    Switzerland
    Posts
    4,443
    You can place a message pump in lengthy operations to ensure the UI responsivity. That is what DoEvents() is for in VB. I gave a basic example in my previous post. An alternative is to start a worker thread.
    Gabriel, CodeGuru moderator

    Forever trusting who we are
    And nothing else matters
    - Metallica

    Learn about the advantages of std::vector.

  7. #7
    Join Date
    Mar 2003
    Posts
    34
    Thanks a lot.

  8. #8
    Join Date
    May 1999
    Location
    Southern California
    Posts
    12,266
    Probably you don't need a DoEvents equivalent; probably there is a better solution but wince you don't ask how to solve the problem you are trying to solve using DoEvents we can't provide a better answer. However the MFC documentation of idle-time processing has a sample loop that is an official version of the one that Gabriel provided. I think the link I have in my web site will get you there so see my Idle-time Processing.
    "Signature":
    My web site is Simple Samples.
    C# Corner Editor

  9. #9
    Join Date
    Mar 2003
    Posts
    34
    Yes, I understand what you mean?
    I guess using threads is what I really need.
    anyway I have a question:
    will

    Code:
     
    MSG msg;
    while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
          {
             TranslateMessage(&msg);
             DispatchMessage(&msg);
          }
    ensure UI responsivity, as Gabriel has pointed?

    I thank you all veru much.

    Mainebound

  10. #10
    Join Date
    Jun 2001
    Location
    Switzerland
    Posts
    4,443
    Open a new dialog based MFC project. Place a button on the dialog and code this as a handler:
    Code:
    void CYourDlg::OnButton1() 
    {
        for(int i=0; i<0x100; ++i){
            MSG msg;
            while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
                  {
                     TranslateMessage(&msg);
                     DispatchMessage(&msg);
                  }
            for(int j=0; j<10; ++j){
                Sleep(10);
            }
        }
        AfxMessageBox("Ready", MB_OK, 0);
    }
    Run the program and push the button. You will notice that you will be able to drag the dialog around, to push other buttons and so on. After about 16 seconds the message box "Ready" will appear.
    Gabriel, CodeGuru moderator

    Forever trusting who we are
    And nothing else matters
    - Metallica

    Learn about the advantages of std::vector.

  11. #11
    Join Date
    Mar 2003
    Posts
    34
    thanks, Gabriel!
    it is what I needed!


    Mainebound
    Last edited by mainebound; March 6th, 2003 at 07:45 AM.

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