Creating a count down text in window

This is a discussion on Creating a count down text in window within the Windows Programming forums, part of the Platform Specific Boards category; Originally Posted by Yarin Last resort? Globals never cause confusion. What is your working expirience? 2 days? Do not make ...

  1. #16
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,471
    Quote Originally Posted by Yarin View Post
    Last resort? Globals never cause confusion.
    What is your working expirience? 2 days?
    Do not make statements based on the absence of real work expirience. Do not confuse others with your own errors...

    In real world support of the programs with Globals vars - is a hell of the programmer
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  2. #17
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,471
    Quote Originally Posted by Yarin View Post
    Further more, gotos can be freely used with no problems.
    As well as with a lot of problems.
    So DO NOT use them until you 200% sure you need it.
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  3. #18
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,856
    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

  4. #19
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,856
    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

  5. #20
    Registered User
    Join Date
    Jul 2007
    Posts
    53
    thanks for the help.

    I'll post my final code later

  6. #21
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,189
    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 = &#37;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.
    Until you can build a working general purpose reprogrammable computer out of basic components from radio shack, you are not fit to call yourself a programmer in my presence. This is cwhizard, signing off.

  7. #22
    Unregistered User Yarin's Avatar
    Join Date
    Jul 2007
    Posts
    1,597
    >> 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.
    A class that doesn't overload all operators just isn't finished yet. -- SmugCeePlusPlusWeenie
    A year spent in artificial intelligence is enough to make one believe in God. -- Alan J. Perlis

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. DirectX | Drawing text
    By gavra in forum Game Programming
    Replies: 4
    Last Post: 06-08-2009, 12:23 AM
  2. Profiler Valgrind
    By afflictedd2 in forum C++ Programming
    Replies: 4
    Last Post: 07-18-2008, 09:38 AM
  3. C or C++
    By AcerN30 in forum Game Programming
    Replies: 41
    Last Post: 05-30-2008, 06:57 PM
  4. Linking OpenGL in Dev-C++
    By linkofazeroth in forum Game Programming
    Replies: 4
    Last Post: 09-13-2005, 10:17 AM
  5. Grabbing Text from a Window
    By jimothygu in forum Windows Programming
    Replies: 4
    Last Post: 10-06-2003, 07:29 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21