Solved

timeout function?

Posted on 1998-11-11
8
352 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
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

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

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…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
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.

739 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