Solved

timeout function?

Posted on 1998-11-11
8
355 Views
Last Modified: 2010-04-02
In JavaScript you can use the timeout function to perform an action every 10 seconds or whatever # you want. Is there a similiar way to do this in C++ with Win 3.1?
0
Comment
Question by:goldseal
[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
  • 4
  • 4
8 Comments
 
LVL 2

Accepted Solution

by:
harrys earned 20 total points
ID: 1177645
Use SetTimer() to create the timer. You can setup a callback function every time the timeout is reached or you can just process the WM_TIMER message which is generated
when the timeout is reached.
See the WinAPI reference for more details
0
 

Author Comment

by:goldseal
ID: 1177646
I guess I should have been a little more clearer. The answer is great, but I am just learning C++ so don't know quite how to do this. I have some background with Java and objects, but could you provide a small example that will do function x() after 2 seconds?

thanks
0
 
LVL 2

Expert Comment

by:harrys
ID: 1177647
no problem,
with the plain Windowsapi you would do something like this..

// inside main
   if( !SetTimer( hwnd, 0, 2000, TimerProc ) )
        return (0);

// somewhere
long FAR PASCAL WindowProc( HWND hWnd, UINT message,
                            WPARAM wParam, LPARAM lParam )
{
    switch( message )    {
    case WM_TIMER:
        x();
        break;
    }
}

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:goldseal
ID: 1177648
Thanks a bunch. A little clarification:

what is TimerProc here?
if( !SetTimer( hwnd, 0, 2000, TimerProc

And, is this just a function for the API?
long FAR PASCAL WindowProc( HWND hWnd, UINT message,
                            WPARAM wParam, LPARAM lParam )

I haven't learned that yet. Just cout with DOS. Do I need that?

thanks a bunch
0
 
LVL 2

Expert Comment

by:harrys
ID: 1177649
The Function Called WindowProc should be called TimerProc instead, it was an error I made, it should be

long FAR PASCAL TimerProc( HWND hWnd, UINT message,
                                   WPARAM wParam, LPARAM lParam )


0
 

Author Comment

by:goldseal
ID: 1177650
Thanks, but what does

long FAR PASCAL TimerProc( HWND hWnd, UINT message,
                                   WPARAM wParam, LPARAM lParam)

all of this mean? All of these parameters and stuff?

thanks again
0
 
LVL 2

Expert Comment

by:harrys
ID: 1177651
Its a Windows API callback function, the adress of the function is passed to windows, when the timer is created in SetTimer(), the declaration is like every standard Windows
callbackfunction, you only need to process the parameter wParam which holds the
ID of the Timer which generated the WM_TIMER message.
The parameter hWnd holds the windowhandle you passed via SetTimer, message is the
typ of message, WM_TIMER in this case.
FAR means that the function is stored in a FAR pointer ,with segment and offset to make shure that the function could be called from outside your code segment.
PASCAL mean that the function uses PASCAL calling conventions, which affects the way
how the compiler generates the code.
This is documented in the Windows API documentation which every windowscompiler
should have "onboard", you might take a look there.
0
 

Author Comment

by:goldseal
ID: 1177652
thanks a bunch
0

Featured Post

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
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.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

717 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