Click here to Skip to main content
15,895,256 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: class instantiation Pin
Cedric Moonen19-Aug-09 22:45
Cedric Moonen19-Aug-09 22:45 
GeneralRe: class instantiation Pin
paolosh20-Aug-09 3:07
paolosh20-Aug-09 3:07 
GeneralRe: class instantiation Pin
CPallini19-Aug-09 23:07
mveCPallini19-Aug-09 23:07 
GeneralRe: class instantiation Pin
paolosh19-Aug-09 22:36
paolosh19-Aug-09 22:36 
GeneralRe: class instantiation Pin
Cedric Moonen19-Aug-09 22:42
Cedric Moonen19-Aug-09 22:42 
AnswerRe: class instantiation Pin
Maximilien20-Aug-09 1:50
Maximilien20-Aug-09 1:50 
GeneralRe: class instantiation Pin
paolosh20-Aug-09 3:04
paolosh20-Aug-09 3:04 
QuestionTimer without CWnd Pin
Kiriko19-Aug-09 21:58
Kiriko19-Aug-09 21:58 
Hi

I need a timer that doesn't rely on windows.

I need something like:

StartTimer()
CallBack MyJob()
StopTimer()

where MyJob() keeps running every few seconds as controlled by the timer but stops if something calls StopTimer().

I tried using CWnd::SetTimer() (and CWnd::KillTimer()):

int j = 1;<br />
<br />
void CMyClass::StartTimer()<br />
{<br />
  CWnd::SetTimer(NULL, 0, 1000, (TIMERPROC) MyFunc);<br />
  while(j)<br />
  {<br />
    MSG msg;<br />
    GetMessage(&msg, NULL, 0, 0);<br />
    DisplatchMessage(&msg);<br />
  }<br />
}<br />
<br />
void CALLBACK CMyClass:MyFunc(HWND hwnd, UINT uMsg, UINT idEvent, DWORD dwTime)<br />
{<br />
  DoJob();<br />
  --j;<br />
}<br />
<br />
void CMyClass:DoJob()<br />
{<br />
  int iN = 0;<br />
}<br />
<br />
void CMyClass::StopTimer()<br />
{<br />
  CWnd::KillTimer(NULL, 0);<br />
}<br />


but this means DoJob() only runs once, as the CallBack stops the while loop that dispatches the message. If I don't change j, the program gets stuck runngin DoJob forever, obviously, and the client never gets a chance to call StopTimer().

How do I solve this problem?

Thanks in advance.
AnswerRe: Timer without CWnd Pin
Adam Roderick J19-Aug-09 22:02
Adam Roderick J19-Aug-09 22:02 
AnswerRe: Timer without CWnd Pin
Randor 19-Aug-09 22:16
professional Randor 19-Aug-09 22:16 
AnswerRe: Timer without CWnd Pin
Nishad S19-Aug-09 22:21
Nishad S19-Aug-09 22:21 
AnswerRe: Timer without CWnd Pin
Ahmed Charfeddine19-Aug-09 22:27
Ahmed Charfeddine19-Aug-09 22:27 
AnswerRe: Timer without CWnd Pin
KarstenK19-Aug-09 22:46
mveKarstenK19-Aug-09 22:46 
QuestionMFC Dialog-based Document with multiple forms using VC++6 Pin
Raymond Cowin19-Aug-09 21:39
Raymond Cowin19-Aug-09 21:39 
AnswerRe: MFC Dialog-based Document with multiple forms using VC++6 [modified] Pin
Adam Roderick J19-Aug-09 21:59
Adam Roderick J19-Aug-09 21:59 
GeneralRe: MFC Dialog-based Document with multiple forms using VC++6 Pin
Raymond Cowin20-Aug-09 2:32
Raymond Cowin20-Aug-09 2:32 
AnswerRe: MFC Dialog-based Document with multiple forms using VC++6 Pin
Cedric Moonen19-Aug-09 22:02
Cedric Moonen19-Aug-09 22:02 
GeneralRe: MFC Dialog-based Document with multiple forms using VC++6 Pin
Raymond Cowin20-Aug-09 2:28
Raymond Cowin20-Aug-09 2:28 
GeneralRe: MFC Dialog-based Document with multiple forms using VC++6 Pin
Cedric Moonen20-Aug-09 2:32
Cedric Moonen20-Aug-09 2:32 
GeneralRe: MFC Dialog-based Document with multiple forms using VC++6 Pin
Raymond Cowin20-Aug-09 2:36
Raymond Cowin20-Aug-09 2:36 
GeneralRe: MFC Dialog-based Document with multiple forms using VC++6 Pin
Raymond Cowin20-Aug-09 3:14
Raymond Cowin20-Aug-09 3:14 
QuestionConfiguration Dependent String Table? [modified] Pin
Kyudos19-Aug-09 17:09
Kyudos19-Aug-09 17:09 
AnswerRe: Configuration Dependent String Table? Pin
KarstenK19-Aug-09 22:52
mveKarstenK19-Aug-09 22:52 
GeneralRe: Configuration Dependent String Table? Pin
Kyudos20-Aug-09 13:08
Kyudos20-Aug-09 13:08 
GeneralRe: Configuration Dependent String Table? Pin
KarstenK20-Aug-09 20:32
mveKarstenK20-Aug-09 20:32 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.