CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: a problem

  1. #1
    Join Date
    Oct 2002
    Location
    lahore
    Posts
    3

    a problem

    hello

    is it possible in c++ after a certain time the input is over
    i,e when user does not any thing for specified time the massage be displayed "Time is over"

  2. #2
    Join Date
    Feb 2002
    Posts
    5,757
    Yes. Your problem is a related to design, not implementation.

    As for implementation, I recommend a timer queue if the application runs in NT and newer versions of Windows. Otherwise, implement a worker thread to do the counting.

    Kuphryn

  3. #3
    Join Date
    Sep 2002
    Posts
    28

    A way in Windows using GetTickCount

    In Windows:

    // Application symbol TimeOut is 60 seconds
    #define TimeOut 60000

    // Application global data
    DWORD LastTime;

    In the main function you set first a value to LastTime:

    LastTime = GetTickCount();

    Each time your program receives user input updates LastTime:

    LastTime = GetTickCount();

    A second thread have a loop that compares:

    if ((GetTickCount() - LastTime) >= TimeOut)
    {
    // make something to notify or display a message
    // you can break the loop and end the thread
    // or you can set LastTime = GetTickCount() again
    // and continue the loop
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured