|
well, actually your point is of great help to me. If it can store 49 days at max then I'll buy that as I only need it max for 24 hours which is considerably lesser.
Thanks a ton!
Cage
|
|
|
|
|
|
Iain Clarke wrote: And 2^32 can only hold 49.7 days
Actually is the half , see [^].
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Still works for me hope it doesn't shrink
|
|
|
|
|
Well, my sums are accurate!
If you're going to cheat and read the docs and find that SetTimer can only do 2^31-1, then shame on you!
In my defense I was thinking of GetTickCount and wraparound. There are lots of ways of skinning his particular cat.
I certainly wouldn't do a 24hr SetTimer - what if people chage the clock? Twice a year that gets done for you, etc...
Iain.
Plz sir... CPallini CPallini abuz drugz, plz plz help urgent.
|
|
|
|
|
Iain Clarke wrote: If you're going to cheat and read the docs and find that SetTimer can only do 2^31-1, then shame on you!
Shame on me!
Iain Clarke wrote: I certainly wouldn't do a 24hr SetTimer - what if people chage the clock? Twice a year that gets done for you, etc...
Do you think the timer would be affected (I really have no clue about but i suppose it shouldn't: it's a timer, not a clock!)?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
CPallini wrote: Do you think the timer would be affected
I also doubt the timer would be affected - but its usefulness would depend on what the OP is trying to do.
If it's "do something approximately a day later", then SetTimer would be fine, or checking GetTickCount on a more rapid timer.
If it's "do something at the same time tomorrow, and the user will look at their clock and be puzzled why they started the program at 1pm and it's midday now..." then you need to do it a different way.
It really depends on what (s)he's trying to do.
Iain.
Plz sir... CPallini CPallini abuz drugz, plz plz help urgent.
|
|
|
|
|
Well, timers and alarms are pretty different things, I suppose the OP knows about. But this is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
And here as well.
|
|
|
|
|
Oh, don't bother too much. Sometimes I'm a bad guy really deserving downvoting.
BTW Thank you friend.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
|
for the xtra '0' - Looks like I am already sleepy
|
|
|
|
|
Have put the timers now before leaving for weekend, hope eveything works good when I come back on Monday
|
|
|
|
|
Well, since the Elapse argument of the SetTimer can take a maximum of USER_TIMER_MAXIMUM (i.e. on my system, 0x7FFFFFFF milliseconds, that is about 25 days) I'm happy with it.
Moreover it isn't such a difficult task to make longer intervals using shorter ones.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
I hear you. I can make small timers, kill them and do 'settimer' repeatedly, but then being a lazy programmer - was thinking of skipping them and just have a one-shot timer
-Amit
|
|
|
|
|
cagespear wrote: I can make small timers, kill them and do 'settimer' repeatedly
Counting isn't an option for you, is it?
cagespear wrote: but then being a lazy programmer
No. It isn't an option.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
You can store datetime when application starts. Set some timer interval and read cureent time each time when receive WM_TIMER message. If the difference between application starting time and current time matches your requirement, take desired action.
|
|
|
|
|
With this small class you can create a timer up to 1193 Hours
#pragma once<br />
<br />
#include <string><br />
<br />
typedef void (*TIMER_PROC)(UINT idEvent, void* obj);<br />
<br />
class CTimer <br />
{<br />
public:<br />
enum eTIME_TYPE<br />
{<br />
eONE_SHOT,<br />
ePERIOIDIC<br />
};<br />
<br />
public:<br />
CTimer(eTIME_TYPE _eType, DWORD _dWaitPeriod, TIMER_PROC _pFunct, LPVOID _pSegment);<br />
virtual ~CTimer();<br />
<br />
public:<br />
inline const char* GetErrorMessage(){ return m_szError.c_str(); }<br />
UINT Start();<br />
void Stop();<br />
bool SetPeriod(DWORD _dwVal);<br />
eTIME_TYPE TimerType() { return m_eTimerType; }<br />
UINT GetTimerID();<br />
<br />
protected:<br />
TIMER_PROC m_pCALLBACKFUN;<br />
void* m_pSegm;<br />
eTIME_TYPE m_eTimerType;<br />
DWORD m_WaitPeriod;<br />
DWORD m_ThreadID;<br />
HANDLE m_hQuitEvent;<br />
HANDLE m_hThread;<br />
HANDLE m_hAdvisorThread;<br />
HANDLE m_hAdvise;<br />
HANDLE m_hQuitAdvisor;<br />
std::string m_szError;<br />
<br />
private:<br />
static void TimerThread(void* _pParam);<br />
static void AdvisorThread(void* _pParam);<br />
};
The implementation
#include <windows.h> <br />
#include "Timer.h"<br />
<br />
<br />
<br />
CTimer::CTimer(eTIME_TYPE _eType, DWORD _dWaitPeriod, TIMER_PROC _pFunct, LPVOID _pSegment)<br />
{<br />
m_pCALLBACKFUN = NULL;<br />
m_pSegm = NULL;<br />
m_eTimerType = _eType;<br />
m_WaitPeriod = _dWaitPeriod;<br />
if( m_WaitPeriod == 0 )<br />
m_WaitPeriod = 1;<br />
m_hThread = m_hAdvisorThread = NULL;<br />
m_ThreadID=0;<br />
m_pCALLBACKFUN = _pFunct;<br />
m_pSegm = _pSegment;<br />
m_hQuitEvent = ::CreateEvent(NULL, TRUE, FALSE, NULL);<br />
m_hQuitAdvisor = ::CreateEvent(NULL, TRUE, FALSE, NULL);<br />
m_hAdvise = ::CreateEvent(NULL, FALSE, FALSE, NULL);<br />
m_hAdvisorThread = ::CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)AdvisorThread, this, 0, 0);<br />
}<br />
<br />
<br />
<br />
CTimer::~CTimer()<br />
{<br />
try<br />
{<br />
Stop();<br />
::SetEvent(m_hQuitAdvisor);<br />
if( m_hAdvisorThread )<br />
{<br />
switch( ::WaitForSingleObject(m_hAdvisorThread, 200) )<br />
{<br />
case WAIT_TIMEOUT:<br />
::TerminateThread(m_hAdvisorThread, 0);<br />
::CloseHandle(m_hAdvisorThread);<br />
m_hAdvisorThread = NULL;<br />
break;<br />
}<br />
}<br />
if( m_hQuitAdvisor != INVALID_HANDLE_VALUE )<br />
::CloseHandle(m_hQuitAdvisor);<br />
}<br />
catch(...)<br />
{}<br />
}<br />
<br />
<br />
<br />
<br />
<br />
void CTimer::AdvisorThread(void* _pParam)<br />
{<br />
CTimer* me = (CTimer*)_pParam;<br />
bool bContinue = true;<br />
HANDLE hEvent[2];<br />
hEvent[0] = me->m_hQuitAdvisor;<br />
hEvent[1] = me->m_hAdvise;<br />
<br />
while( bContinue )<br />
{<br />
DWORD dw = ::WaitForMultipleObjects(2, hEvent, FALSE, INFINITE);<br />
switch(dw)<br />
{<br />
case WAIT_OBJECT_0 + 0:<br />
bContinue =false;<br />
break;<br />
case WAIT_OBJECT_0 + 1:<br />
if( me->m_pCALLBACKFUN )<br />
me->m_pCALLBACKFUN(me->m_ThreadID, me->m_pSegm);<br />
break;<br />
}<br />
}<br />
::CloseHandle(me->m_hAdvisorThread);<br />
me->m_hAdvisorThread = NULL;<br />
}<br />
<br />
<br />
<br />
void CTimer::TimerThread(void* _pParam)<br />
{<br />
CTimer* me = (CTimer*)_pParam;<br />
bool bContinue = true;<br />
<br />
while( bContinue )<br />
{<br />
switch ( ::WaitForSingleObject(me->m_hQuitEvent, me->m_WaitPeriod))<br />
{<br />
case WAIT_OBJECT_0:<br />
bContinue = false;<br />
break;<br />
case WAIT_TIMEOUT:<br />
if( me->m_eTimerType == eONE_SHOT )<br />
::SetEvent(me->m_hQuitEvent);<br />
::SetEvent(me->m_hAdvise);<br />
break;<br />
}
}
::CloseHandle(me->m_hThread);<br />
me->m_hThread = NULL;<br />
}<br />
<br />
<br />
<br />
<br />
<br />
<br />
UINT CTimer::Start()<br />
{<br />
if( m_hThread == NULL )<br />
{<br />
::ResetEvent(m_hQuitEvent);<br />
m_hThread = ::CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)TimerThread, this,<br />
0, &m_ThreadID);<br />
}<br />
return m_ThreadID;<br />
}<br />
<br />
<br />
<br />
void CTimer::Stop()<br />
{<br />
::SetEvent(m_hQuitEvent);<br />
DWORD dWaitMax = m_WaitPeriod * 2;<br />
if( dWaitMax == 0 )<br />
dWaitMax = 500;<br />
<br />
if( m_hThread )<br />
{<br />
switch( ::WaitForSingleObject(m_hThread, dWaitMax) )<br />
{<br />
case WAIT_TIMEOUT:<br />
::TerminateThread(m_hThread, 0);<br />
::CloseHandle(m_hThread);<br />
m_hThread = NULL;<br />
break;<br />
}<br />
}<br />
m_ThreadID =0;<br />
}<br />
<br />
<br />
<br />
bool CTimer::SetPeriod(DWORD _dwVal)<br />
{<br />
if( m_hThread )<br />
{<br />
m_szError = "Thread is working..could not set.";<br />
return false;<br />
}<br />
m_WaitPeriod = _dwVal;<br />
return true;<br />
}<br />
<br />
<br />
UINT CTimer::GetTimerID()<br />
{<br />
return m_ThreadID;<br />
}<br />
|
|
|
|
|
cagespear wrote: ...I need to take some action at lets say - 24 hours after the app has opened.
What if you created a scheduled task?
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
I have a dialog based application.In this I have a button which takes the value in a textbox and adds it to a combobox.I have to enter values in three textboxes.All these values have to be written into a file.
I have writen the code as follows:
GetDlgItemText(IDC_EDIT1,str1);<br />
GetDlgItemText(IDC_EDIT1,str2);<br />
GetDlgItemText(IDC_EDIT1,str3);<br />
fstream f;<br />
f.open("myfile.txt",ios::in|ios::out);<br />
f.write(str1,str1.length());
When i open the file to view the contents,its not written properly.Also I want to append the details each time I enter values in the textboxes.
|
|
|
|
|
How str1, str2, str3 are declared.
What values were assigned to such variables?
What is written inside the file, insted?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
All of str1,str2 and str3 are CString variables.the str3 im using is the name of a camera.appending is not done properly.file contents are not written properly...
|
|
|
|
|
How can we help you if you are so reluctant to provide meaningful info?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
You wrote only the first string. What isnt properly?
Read the docs to fstream. This is really beginners stuff.
Greetings from Germany
|
|
|
|
|
try this
change the fopen as
f.open(myfile.txt",ios::in|ios::out|ios::app);
vineesh
|
|
|
|