Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to use OnIdle()?

Posted on 1997-08-20
7
Medium Priority
?
670 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 100 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
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 viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

715 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