Solved

How to use OnIdle()?

Posted on 1997-08-20
7
662 Views
Last Modified: 2012-05-04
How to use OnIdle() of CWinApp()? I have tried it but it doesn't work.
I'm now trying to write a server that would close the connection of a client if the client has idled for a long time. So, the server has to be able to time the idle time.
How can I archieve this?
I know that there is one more function called settimer()but how to use it?
Thanks a lot.
0
Comment
Question by:syyung6
[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
  • 2
7 Comments
 

Accepted Solution

by:
fRouxSerret earned 50 total points
ID: 1167837
For the function to be called, it has to be declared in the message map of the corresponding window (ON_WM_IDLE, or somthing like this...)
The timer function has to be declared too (ON_WM_TIMER). Then, you call the SetTimer() on your window, with a given time in milliseconds, and after this time, your window's OnTimer() (I'm not sure of the name of the function) function is called. If you want to be called again, you have to call again SetTimer() at the end of the OnTimer() function.

If neither of these things work, then try this:

Edit your window's callback function, and add a 'case' statement for each message you want to process. write some code (break for example), and add a breakPoint on this line. If the breakPoint is never reached, then Windows uses a different callBack function: You just have to find it, or to find a way to redirect it (Look at your window class definition, and at the window opening code).

Hope it helps !!

0
 
LVL 4

Expert Comment

by:md041797
ID: 1167838
" If you want to be called again, you have to call again SetTimer() at the end of the OnTimer() function."

Windows timers are free running.  Don't reset after each timeout.  They will continue timing out until you call KillTimer.  If you SetTimer after each time event, you will soon run out of resources, because a new timer is created each call.


0
 

Expert Comment

by:fRouxSerret
ID: 1167839
It seems that md doesn't like me !!!!! ;-)

However he's right and wrong: I checked in the docs:

YES : I appologize, SetTimer doesn't need to be called again after each event ! It sends events until KillTimer is called.

NO: you won't run out of resource if you use 'SetTimer' again, because with the same timer ID, it will either use the memory of the previously allocated Timer, or return an error code, without wasting some memory.

Thank you for correcting me !
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!

 

Expert Comment

by:fRouxSerret
ID: 1167840
It seems that md doesn't like me !!!!! ;-)

However he's right and wrong: I checked in the docs:

YES : I appologize, SetTimer doesn't need to be called again after each event ! It sends events until KillTimer is called.

NO: you won't run out of resource if you use 'SetTimer' again, because with the same timer ID, it will either use the memory of the previously allocated Timer, or return an error code, without wasting some memory.

Thank you for correcting me !
0
 

Expert Comment

by:fRouxSerret
ID: 1167841
Oooooops !
0
 
LVL 4

Expert Comment

by:md041797
ID: 1167842
No, I'm just being a butt-head.
0
 

Author Comment

by:syyung6
ID: 1167843
Thank you very much for helping me.
Actually, I've solved the problem by using OnTimer(), ON_WM_TIMER, and SetTimer().
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
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 how to clear a vector as well as how to detect empty vectors in C++.

726 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