when i change the text, with STATIC class, i get flickers :(
how can i avoid them?
the WS_EX_COMPOSITED for parent is give me problems with WM_MOUSEMOVE message. someone told me about double buffering controls, but i realy don't know what is that :(
Printable View
when i change the text, with STATIC class, i get flickers :(
how can i avoid them?
the WS_EX_COMPOSITED for parent is give me problems with WM_MOUSEMOVE message. someone told me about double buffering controls, but i realy don't know what is that :(
I believe that, in XP and above, there is a style that enables double buffering. Don't remember exactly what it's called, though.
Also posted here.
Jim
Moved to Windows programming forum.
There's no problem being a member of multiple forum communities and being active on all of them, but if you want to pose a technical question, then pose it to just one forum community, i.e., the one you deem to be most appropriate for the question. Only if you do not receive any satistory answers from that community after some time should you seek for answers in another forum community, and when you do so, note that you have already asked elsewhere, giving a link if feasible.Quote:
Originally Posted by joaquim
Looking at the code on the other forum...
Return TRUE to WM_ERASEBACKGRND
Set the last param of your InvalidateRect() to FALSE (look at MSDN to see why)
DO NOT load an image from file in the WM_PAINT handler
Use UpdateWindow() when calling for a paint.
you have right... thanks
these function do the flicker:
the InvalidateRect() can redraw the control, but if the control is transparent:Code:SetWindowPos(hwnd, 0, 0, 0, 0, 0,
SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|
SWP_DRAWFRAME | SWP_FRAMECHANGED|SWP_NOCOPYBITS);
(inst is the class\instance pointer)Code:case WM_CTLCOLORSTATIC:
{
if ( inst->blnTransparent == true)
{
SetTextColor((HDC)wParam, inst->clrTextColor);
SetBkMode( (HDC)wParam, TRANSPARENT);
return (LRESULT) GetStockObject(HOLLOW_BRUSH);
}
else
{
DeleteObject(g_hbrBackground);
SetTextColor((HDC)wParam, inst->clrTextColor);
SetBkColor((HDC)wParam,inst->clrBackColor);
SetBkMode((HDC)wParam, TRANSPARENT);
g_hbrBackground = CreateSolidBrush(inst->clrBackColor);
return (LONG)g_hbrBackground;
}
}
break;
the text isn't clean, but it's shows 1 above other(i mean 2 text's or more).
i avoid the flicker knowing these, but can i fix that for show a clean text when it's transparent?
can i use the SetWindowsPos() without doing a flicker?
Yes, but you cannot call it too often.Quote:
can i use the SetWindowsPos() without doing a flicker?
Put a counter into that call and see how often you are calling it.
BTW It does nothing but redraw the background, which could be done quicker with a WM_PAINT (as I have already suggested a couple of times....)
I you want more help then you MUST post a screen shot of what is happening now, and describe what is wrong.
I have done this type of UI and not had flicker but I suspect your design is flawed and will never work.
these code isn't ficker so many times, but it's better:
i can share the entire class, but, like Elysia said before, it's to many lines for see ;)Code:void setAutoSize(bool autosize)
{
blnAutoSize=autosize;
if (autosize==true)
{
//Getting the DC Font amd select it
HDC hdc = GetDC(hwnd);
HFONT hFont = (HFONT)SendMessage(hwnd, WM_GETFONT, 0, 0);
HFONT hOldFont = (HFONT)SelectObject(hdc, hFont);
//Getting the
RECT c = { 0, 0, 0, 0 };
//Getting the text rectangle from actual caption
char a[256];
GetWindowText(this->hwnd,a,256);
DrawText(hdc, a, strlen(a), &c, DT_CALCRECT | DT_EXPANDTABS);
//add 2 to the size
TEXTMETRIC v;
GetTextMetrics (hdc,&v);
c.right=c.right+(v.tmAveCharWidth / 2);
c.bottom=c.bottom+(v.tmAveCharWidth / 2);
//Clean the Font DC
ReleaseDC(hwnd,hdc);
//Getting the actual styles
LONG s=GetWindowLongPtr(hwnd,GWL_EXSTYLE);
LONG g=GetWindowLongPtr(hwnd,GWL_STYLE);
//change the rectangle size for borders
AdjustWindowRectEx (&c,g,FALSE,s );
//Update the control
SetWindowPos(hwnd, 0, 0, 0, c.right, c.bottom,
SWP_NOZORDER|SWP_NOMOVE|SWP_NOACTIVATE);
RECT b;
b.left=getLeft();
b.top=getTop();
b.right=getLeft()+getWidth();
b.bottom=getTop()+getHeight();
InvalidateRect(hwnd,&b,false);
}
}
void setText(string text)
{
char* chrText = (char*)text.c_str();
strCaption=text;
SetWindowText(hwnd, chrText);
if (blnAutoSize==true)
{
setAutoSize(true);
}
else
{
RECT b;
b.left=getLeft();
b.top=getTop();
b.right=getLeft()+getWidth();
b.bottom=getTop()+getHeight();
InvalidateRect(hwnd,&b,false);
}
}
i have another question: when the control is transparent:
and in window procedure:Code:void setTransparent(bool transparent)
{
blnTransparent = transparent;
SetWindowPos(hwnd, 0, 0, 0, 0, 0,
SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|
SWP_DRAWFRAME | SWP_FRAMECHANGED|SWP_NOCOPYBITS);
}
the text isn't showed clean, but the new text is showed above the older :(Code:case WM_CTLCOLORSTATIC:
{
if ( inst->blnTransparent == true)
{
SetTextColor((HDC)wParam, inst->clrTextColor);
SetBkMode( (HDC)wParam, TRANSPARENT);
return (LRESULT) GetStockObject(HOLLOW_BRUSH);
}
else
{
DeleteObject(g_hbrBackground);
SetTextColor((HDC)wParam, inst->clrTextColor);
SetBkColor((HDC)wParam,inst->clrBackColor);
SetBkMode((HDC)wParam, TRANSPARENT);
g_hbrBackground = CreateSolidBrush(inst->clrBackColor);
return (LONG)g_hbrBackground;
}
inst->setText(inst->strCaption);
}
break;
can you advice me?