?
Solved

timeout function?

Posted on 1998-11-11
8
Medium Priority
?
360 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 60 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
Industry Leaders: 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

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…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

741 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