Thread: SetTimer().. WM_TIMER window flickers

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Apr 2008
    Posts
    610
    Quote Originally Posted by matsp View Post
    1000 milliseconds is 1 second, which is quite often. I suggested a value of about 20-50 (50-20 Hz, which happens to be roughly the range where things stop flickering and start being smooth - perhaps 35 is a good value -> ~28Hz update frequency ?)

    --
    Mats
    lost you now... 35ms or 35s (35000)

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    35 milliseconds. 35 seconds would definitely make the updates "jump" (unless the user got bored and looked away before the screen got updated).

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User
    Join Date
    Apr 2008
    Posts
    610
    Quote Originally Posted by matsp View Post
    35 milliseconds. 35 seconds would definitely make the updates "jump" (unless the user got bored and looked away before the screen got updated).

    --
    Mats
    Anything less than 500 doesn't look good. In fact since i'm displaying a lot of text with different font levels, after a little while with the flickering suddenly the font changes all text to bold, and removes any italics existing on text.. Some stages aligns text incorrectly!

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    I suspect you are entering your WM_PAINT twice within a single draw.

    So if less than 500 is not good, then you probably better stick with the jerky 1000 - not much difference if it's jerky twice as often.

    Another thought would of course be to not update as much of the screen each time - perhaps you can draw just parts of it?

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  5. #5
    Registered User
    Join Date
    Apr 2008
    Posts
    610
    Quote Originally Posted by matsp View Post
    I suspect you are entering your WM_PAINT twice within a single draw.

    So if less than 500 is not good, then you probably better stick with the jerky 1000 - not much difference if it's jerky twice as often.

    Another thought would of course be to not update as much of the screen each time - perhaps you can draw just parts of it?

    --
    Mats
    This is my messages switch statement

    Code:
    	switch (uMsg)
    	{
    	case WM_CREATE:
    		{
    			/* Create timer to refresh screen */ 
    			SetTimer(hwnd, IDT_REFRESH, REFRESHTIME,(TIMERPROC) NULL); 
    
    			/* Create edit controls */
    			EditBoxes(hwnd, cs);
    
    			/* Create radio buttons */
    			RadioButtons(hwnd, cs);
    		}
    		return 0;
    
    	case WM_PAINT:
    		{
    			hdc=BeginPaint(hwnd, &pntS);
    
    			/* *** User Interface *** */
    			DrawArea(hwnd, hdc, colors);
    			RadioButtonsText(hwnd, hdc, polarLbl, stdFont);
    			TargetText(hwnd, targetLbl, sqm, mtrs, hdc, stdFont);
    			GenParams(hwnd, genPara, fareRng, dpRng, hdc, stdFont);
    			RadaAntennaText(hwnd, rdrAntenaLbl, deg, db, halfMin, mtrs, hdc, stdFont);
    			DisplayResultsBox(hwnd, hdc, rdrTrans_recv, targetLbl, rsltFont);
    			RadarReceiverText(hwnd, rdrTrans_recv, hz, mhz, mtrs, kw, usec, db, wvlnthFig, hdc, stdFont);
    			
    			// Calculate & show results
    			output = ProcessData(hwnd);
    			DisplayResults(hwnd, hdc, &output, rsltFont);
    
    			EndPaint(hwnd, &pntS);
    		}
    		return 0;
    
    	case WM_COMMAND:
    		{
    			// Listen to the input commands
    			switch( LOWORD(wParam) )
    			{
    			case ID_FILE_EXIT:
    				{
    					PostMessage(hwnd, WM_CLOSE, 0, 0);
    					break;
    				}
    
    			case ID_EDIT_CLEAR01:
    				{
    					ClearEditControls(hwnd, indata);
    					break;
    				}
    			case ID_FILE_OPEN01:
    				{
    					// Load data from file to edit controls
    					DoFileOpen(hwnd);
    					SetValues(hwnd, &indata);
    					break;
    				}
    			case ID_FILE_SAVEAS:
    				{
    					// Save data on edit controls to file
     					DoFileSaveAs(hwnd);
    					break;
    				}
    			case ID_FILE_SAVE01:
    				{
    					// Save data on edit controls to file
    					WriteToFile(hwnd, "RFSDataFile.dat");
    					break;
    				}
    			}
    		}
    		return 0;
    
    	case WM_GETDLGCODE:
    		{
    			break;
    		}
    	case WM_TIMER: 
    		{
    			// Refresh screen
    			InvalidateRect (hwnd, NULL, TRUE);
    			UpdateWindow(hwnd);
    		}
    		break;
    
    	case WM_DESTROY:
    		KillTimer(hwnd, IDT_REFRESH);
    		PostQuitMessage(0);    
    		return 0;
    	default:
    		//let system deal with msg
    		return DefWindowProc(hwnd,uMsg,wParam,lParam);  
    	}

  6. #6
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    That's not much help - I'm just asking if you need to redraw everything. I can't say from that what actually happens in your functions that do the actual drawing.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  7. #7
    Registered User
    Join Date
    Apr 2008
    Posts
    610
    Quote Originally Posted by matsp View Post
    That's not much help - I'm just asking if you need to redraw everything. I can't say from that what actually happens in your functions that do the actual drawing.

    --
    Mats
    Actually i need to redraw a portion of the window. I have five rectangles (4 have edit boxes, 1 has results table) in one window. Really i only need to update the results (the Fifth rectangle) every time thew user changes the values on the other 4 rectangles... Any suggestions on how to do this?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. WM_CAPTION causing CreateWindowEx() to fail.
    By Necrofear in forum Windows Programming
    Replies: 8
    Last Post: 04-06-2007, 08:23 AM
  2. 6 measly errors
    By beene in forum Game Programming
    Replies: 11
    Last Post: 11-14-2006, 11:06 AM
  3. Linking OpenGL in Dev-C++
    By linkofazeroth in forum Game Programming
    Replies: 4
    Last Post: 09-13-2005, 10:17 AM
  4. Pong is completed!!!
    By Shamino in forum Game Programming
    Replies: 11
    Last Post: 05-26-2005, 10:50 AM
  5. OpenGL Window
    By Morgul in forum Game Programming
    Replies: 1
    Last Post: 05-15-2005, 12:34 PM