?
Solved

Visual Basic "DoEvents" C++ equivalent...

Posted on 2000-04-15
9
Medium Priority
?
2,568 Views
Last Modified: 2013-11-25
Hi...

In the Visual Basic, have the
"Doevents" command...

What the equivalent in C++ ?

thanks...
0
Comment
Question by:masvmasv
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 1

Expert Comment

by:Toad224
ID: 2719421
while(action)
{
}
0
 

Author Comment

by:masvmasv
ID: 2719472
Thanks man...

Looking my code:

   for x = 1 to 10
       doevents
   next

in Borland C++ Builder:

   for( int x = 1; x <= 10; x++ )
        Application->ProcessMessages();

and in C/C++ (Visual C++) ?

Thanks
0
 
LVL 7

Expert Comment

by:KangaRoo
ID: 2719486
There is no real equivalent to that in C++. There may be equivalents in specific frameworks, like masvmasv showed for BC Builder, or others for, lets say, MFC or OWL.
It would be usefull if you specified which frameworks you are using.
0
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

 

Author Comment

by:masvmasv
ID: 2719522
ok...

thanks

But if I have a infinit loop:

   while( true )
   {
   }

crash Windows ?
0
 

Expert Comment

by:nimrodh
ID: 2720178
if you are using multithreading, you can use the SleepEx function.
The SleepEx function causes the current thread to enter a wait state until one of the following occurs:
An I/O completion callback function is called.
An asynchronous procedure call (APC) is queued to the thread.
The time-out interval elapses.
0
 

Author Comment

by:masvmasv
ID: 2720450
Do you dont understand...

I need force Windows execute events, if I have a infinite loop...

thanks
0
 
LVL 32

Expert Comment

by:jhance
ID: 2720841
There is no equivalent to the VB DoEvents call in VC++.  So you need to do it some other way.

No window in your application will process any Windows messages while your application is busy processing in a long running or infinite loop.  The best course of action is to code you app so that there are no long procedures in the main app's thread.  Any long or "forever" loops should be coded in a separate thread.  That way, Windows messages will still be processed even though your function is running for a long time.

If you cannot do it this way, a possible work around is to interrupt your loop periodically, setup a timer to signal you to restart the loop, and save some status information to permit you to restart the loop where you left off.  Then you can return to Windows.  When the timer fires, you can pick up where you left off for a specified time interval.
0
 

Accepted Solution

by:
zealsoft earned 150 total points
ID: 2721276
Use following function.

BOOL DoEvents()
{
        MSG msg;
       
        while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)){
                if(msg.message==WM_QUIT)
                        return FALSE;
                TranslateMessage(&msg);
                DispatchMessage(&msg);
        }
        return TRUE;
}
0
 

Author Comment

by:masvmasv
ID: 2735521
Thanks...
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question