All problems in computer science can be solved by another level of indirection,
except for the problem of too many layers of indirection.
– David J. Wheeler
You are yet to give a reason why a global is better than a static local, in this case.
I have justified my choice with a (IMO good) reason.
I suggest the OP look at our posts and join dates (and post counts) and decide for themselves whom to trust.
"Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
Friedrich Nietzsche
"I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
George Best
"If you are going through hell....keep going."
Winston Churchill
To the OP...
As I derailed oyur thread, here is some code illustrating what I mean.
Code://in resource.h or header #define IDT_COUNTDOWN 40001 //past the numbers used by the IDE //in callback static UINT uiTimer=0; static int iCountDown=5; case WM_CREATE: case WM_INITDIALOG: //create a timer uiTimer=SetTimer(hWnd,IDT_COUNTDOWN,1000,NULL); //TODO set return value break; case WM_TIMER: if(wParam==uiTimer)//is it the count down timer? { iCountDown--; if(iCountDown<0)//if the count down is ended, kill the timer. KillTimer(hWnd,uiTimer); InvalidateRect(hWnd,NULL,false);//redraw whole window UpdateWindow(hWnd);//post directly to the callback, not to the msg queues } //TODO set return value break; case WM_PAINT: PAINTSTRUCT PS; BeginPaint(hWnd,&PS); //draw text char szBuf[MAX_PATH]={0};//init string empty if(iCountDown>=0)//choose what to display _snprintf(szBuf,MAX_PATH-1,"Count is %d.",iCountDown); else _snprintf(szBuf,MAX_PATH-1,"Countdown has ended.");//tell user countdown is over TextOut(PS.hdc,20,20,szBuf,lstrlen(szBuf)); EndPaint(hWnd,&PS); //TODO set return value break;
"Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
Friedrich Nietzsche
"I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
George Best
"If you are going through hell....keep going."
Winston Churchill
thanks for the help.
I'll post my final code later
use sprintf() to put your text into a string, then use DrawText() to print it.
Never use Sleep() in the message loop, ever, ever, no not even then. If you need to trigger the update in the message loop, use a timer.
Code:akshar += sprintf((char*)&szString[akshar] , " Count = %d\n" , Count ); DrawText(hdc , (char*)&szString[0] , -1 , &Rect , DT_TOP | DT_LEFT );
Last edited by abachler; 10-09-2007 at 05:16 PM.
>> You are yet to give a reason why a global is better than a static local, in this case.
>> I have justified my choice with a (IMO good) reason.
Okay, I see your point.
>> I suggest the OP look at our posts and join dates (and post counts) and decide for themselves whom to trust.
That makes no difference; It's not like we both joined the board when we first started programming.