Flickering on Win7 Progress Control Text
I am using Win32 API (no MFC) and am handling the WM_PAINT message to draw text over a progress control for windows 7, problem is I get a flicker every time that little light burst effect thing runs across the progress bar, anyone have an idea on how to solve this?
//my code...
//case WM_ERASEBKGND: //tried this, problem still not solved
//case WM_NCPAINT: //tried this, problem still not solved
case WM_PAINT:
{
//OnPaint(); //tried pre-painting, does not work
//Let the control paint its own elements
LRESULT nOriginalReturn = CallWindowProc(m_OrgWinProc,hwnd,msg,wParam,lParam);
//Draw my text on top of the control
if(OnPaint())
{return 0;}else{return nOriginalReturn;}
break;
}
BOOL ProgressEx::OnPaint()
{
try
{
HDC hdc = ::GetWindowDC(m_hWnd);
RECT rc;
::GetWindowRect(m_hWnd,&rc);
//change window rect cordinates to client cordinates
rc.bottom -= rc.top;
rc.right -= rc.left;
rc.left = 0;
rc.top = 0;
HFONT oldfont = (HFONT)SelectObject(hdc,m_font);
SetBkMode(hdc,TRANSPARENT);
SetTextColor(hdc,0x000000);//black text
DrawText(hdc,"Hello",-1,&rc,DT_CENTER|DT_VCENTER|DT_SINGLELINE|DT_NOCLIP);
SelectObject(hdc,oldfont);//reselect the old font
ReleaseDC(m_hWnd,hdc);
return TRUE;
}
catch(...){}
return FALSE;
}
Re: Flickering on Win7 Progress Control Text
Just a little aside question: which exceptions do you expect to catch in the code below?
Quote:
Originally Posted by
12oclocker
Code:
try
{
// ... some Win32 API (no MFC) calls.
}
catch(...){}
Re: Flickering on Win7 Progress Control Text
lol, none, I removed that...
I had another idea, I would like to load the image that MS uses for the progress bar, and draw it
myself using the image, similar to how...
DrawThemeBackground(hTheme, hdc, PP_CHUNK, 0, &rcChunk, NULL);
would draw it... except I cannot use DrawThemeBackground, because that only works if the control has theme's enabled on it, but I decided to disable theme's on that control to prevent the light effect from causing constant redraws, and flickering my overlay text (even a memDC on the text didnt solve the flicker)
So I need to make my own implementation of DrawThemeBackground, to force a draw on a non-themed control, and use the PP_CHUNK image.
Re: Flickering on Win7 Progress Control Text
I just disabled themes for that control, and now am drawing the entire control myself, I did notice the progress control is 2 pixels smaller in height and width on windows XP than in Windows 7, I have removed the borders and it still like that, anyone have any ideas why?
GetClientRect returns a rect that is 1px smaller all around the control with WinXP
Maybe I could take a look at WM_NCCALCSIZE and figure out a way to force the sizes to be the same?
...but then again I would need to figure where this change is happening. uhhh!
Re: Flickering on Win7 Progress Control Text
ok, I figured it out, winXP must be specifying a 1px boarder of non-client area, and downsizing the client area of the control, so I did this to override that and make win7 and winxp both have the same client area size in the progress control...
case WM_NCCALCSIZE:
{
if(wParam){return 0;}//force winXP to not have a 1px non-client area
break;
}
//process org winproc