Solved

How to use OnIdle()?

Posted on 1997-08-20
7
649 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
  • 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

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…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
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 goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

706 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now