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
Solved

How to use OnIdle()?

Posted on 1997-08-20
7
660 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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 

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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

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 goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

856 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