|
MoboTech wrote: But what's the difference between endl and \n?
endl writes a '\n' to the stream AND flushes the stream.
You could do cout.flush(); after you've written the lines of text.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
MoboTech wrote: But what's the difference between endl and \n?
In a word...caching.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
void cout (char* szMsg)
{
cout << szMsg << endl;
}
cout("abc");
|
|
|
|
|
// Lyrics.cpp : Displaying Lyrics.
// Steve Baker
#include "stdafx.h"
char* stuff[]= {
{"'Gone Crazy'"},
{"by Alan Jackson"},
{""},
{"Here I am all alone again tonight"},
{"In this old empty house"},
{"It's hard to learn what you don't think you need"},
{"You can't live without"},
{"Never leave the sound of the telephone"},
{"But ever since you left"},
{"I've been gone"},
{"Gone carzy, goin' out of my mind"},
{"I've asked myself the reasons,"},
{"at least least thousand times,"},
{""}
};
char otherStuff[]={
"\
'Gone Crazy'\n\
by Alan Jackson\n\
\n\
Here I am all alone again tonight\n\
In this old empty house\n\
It's hard to learn what you don't think you need\n\
You can't live without\n\
Never leave the sound of the telephone\n\
But ever since you left\n\
I've been gone\n\
Gone carzy, goin' out of my mind\n\
I've asked myself the reasons,\n\
at least least thousand times,\n\
\n"
};
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
int nCount=(sizeof(stuff)/sizeof(char*));
// One way...
for (int i=0;i<nCount;++i) {
cout << stuff[i] << endl;
}
// Another way...
cout << otherStuff << endl;
cout << "Press the Enter key to continue...";
cin.ignore(99,'\n');
return 0;
}
|
|
|
|
|
I am writing an application that runs as a Windows Service to measure user inactivity - for the purpose of timing out applications. How best to do it?
None
|
|
|
|
|
Oops: My bad. I just noticed a similar thread below.
But coming to think of it, I am not particularly interesting in using Mouse/Keyboard hooks since they may affect over-all computer response. Is there a way to tell MS Windows to wake up a certain CALLBACK if the user doesn't input for a certain period of time?
None
|
|
|
|
|
look CWinApp::OnIdle (MFC)
Russell
|
|
|
|
|
Wrong. Did you read the docs to find out what OnIdle() does?
Nobody can give you wiser advice than yourself. - Cicero
.·´¯`·->ßRÅhmmÃ<-·´¯`·.
|
|
|
|
|
brahmma wrote: Wrong
brahmma wrote: Did you read the docs to find out what OnIdle() does?
Did you?
Russell
|
|
|
|
|
I don't care you voting me 1 for that, but at least try to realize that you are providing wrong guidance to a person seeking help. That is plainly unacceptable.
Russell` wrote: Did you?
Of course I do read the docs and I've provided him the correct solution.
Nobody can give you wiser advice than yourself. - Cicero
.·´¯`·->ßRÅhmmÃ<-·´¯`·.
|
|
|
|
|
Sorry,...I haven't seen that him was talking to windows-inactivity and not his app-inactivity.
Next time I'll read the question better.
Thank you
...and sorry to the OP
Russell
|
|
|
|
|
concoran wrote: I am not particularly interesting in using Mouse/Keyboard hooks since they may affect over-all computer response. Is there a way to tell MS Windows to wake up a certain CALLBACK if the user doesn't input for a certain period of time?
If you run Windows 2000 or above, you can use GetLastInputInfo() API.
See here[^].
Nobody can give you wiser advice than yourself. - Cicero
.·´¯`·->ßRÅhmmÃ<-·´¯`·.
|
|
|
|
|
I am looking for some help on terminating an application after a certain period of inactivity.
I need to terminate the application if the user does not perform any actviity for certain amount of time.
Any help or direction will be appreciated.
Thanks
Sri Rama
|
|
|
|
|
1) For mouse/keyboard messages pretranslate might do or setup message hooks, whatever works. If other devices are used to interact with the program you have to account for them as well.
2) Upon any of those messages you cancel the previous duration timer and set a new one.
3) If the timer ever expires you exit the application.
|
|
|
|
|
Can you use a timer in your application class - likes of the of fashioned watch dog timer? Than all you have to do is reset it on any user activity or let it timeout and exit the app.
|
|
|
|
|
Sriramak wrote: Any help or direction will be appreciated.
See here.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Nice but ... does it defeat the windows very basics?
Would you have to put this API in some kinda of wait loop?
Just wondering.
Vaclav
|
|
|
|
|
Vaclav_Sal wrote: does it defeat the windows very basics?
Not sure what you mean by this.
Vaclav_Sal wrote: Would you have to put this API in some kinda of wait loop?
Most likely using WM_TIMER .
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
I tought you would have to have this GetLastInputInfo()API in a loop to monitor the inactivity.
IMHO that defeats the very essence of an event driven OS unless you "plug it in" into windows message loop of course.
Is't the timer (CTimer) already in this OS loop since it is a "windows" resource ?
|
|
|
|
|
Vaclav_Sal wrote: I tought you would have to have this GetLastInputInfo()API in a loop to monitor the inactivity.
You can call SetTimer(1000) , and then respond to the WM_TIMER message.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
My app shows the dialog box in a modal (topmost) window.
The purpose of the app is to give feedback to the user about the button pressed on the keyboard, however, whenever I press the ESC or Space keys, the IDCANCEL or IDOK buttons are "pressed".
Is it possible to prevent this behavior ?
(I want those buttons only to be used by the user via mouse click to exit the app. The "Default Button" property for the buttons is set to False)
thankyou !
|
|
|
|
|
you need to add a PreTranslateMsg handler and eat the Escape & Space keys.
|
|
|
|
|
I am studying this now. Found a good example here http://www.codeguru.com/forum/archive/index.php/t-203713.html
thanks !!
|
|
|
|
|
abiemann wrote: Is it possible to prevent this behavior ?
Yes. See here.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
I've added BN_CLICKED handlers:
S2000_CP_DLG::OnExitOK()
S2000_CP_DLG::OnExitCANCEL()
and for good measure I've stubbed-out the base functions: (probably unnecessary)
S2000_CP_DLG::OnOK()
S2000_CP_DLG::OnCancel()
so what happens now is that when I press [Esc] the OnExitCANCEL() is called.
When I press [Enter] or [Space] the OnExitOK() is called.
but since the app has to run through some code when OK and CANCEL are clicked I can't just leave the handlers empty.
Hence, within the handlers I think I need to detect if the keyboard was used to click the button. If no, then proceed with processing and close the dialog. If yes, then exit the handler.
I just don't know how to detect if the keyboard was used to enter OnExitOK and OnExitCANCEL.
|
|
|
|