Solved

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

Posted on 2000-04-15
9
2,376 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
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
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 

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 50 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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

831 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