[win32] - how can i avoid controls flickers?

This is a discussion on [win32] - how can i avoid controls flickers? within the Windows Programming forums, part of the Platform Specific Boards category; when i change the text, with STATIC class, i get flickers how can i avoid them? the WS_EX_COMPOSITED for parent ...

  1. #1
    Registered User
    Join Date
    Aug 2013
    Posts
    118

    [win32] - how can i avoid controls flickers?

    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

  2. #2
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,424
    I believe that, in XP and above, there is a style that enables double buffering. Don't remember exactly what it's called, though.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    Registered User
    Join Date
    Aug 2013
    Posts
    118
    Quote Originally Posted by Elysia View Post
    I believe that, in XP and above, there is a style that enables double buffering. Don't remember exactly what it's called, though.
    it's called WS_EX_COMPOSITED, but it mess up with mouse move message

  4. #4
    Registered User
    Join Date
    May 2010
    Posts
    2,693
    Also posted here.

    Jim

  5. #5
    Registered User
    Join Date
    Aug 2013
    Posts
    118
    Quote Originally Posted by jimblumberg View Post
    Also posted here.

    Jim
    yes... i'm registed in some forums... here i used Joaquim, there i used Cambalinho.
    Joaquim is my real name and the Cambalinho is 1 nice story from english prof
    i hope theres no problem on that

  6. #6
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,409
    Moved to Windows programming forum.

    Quote Originally Posted by joaquim
    yes... i'm registed in some forums... here i used Joaquim, there i used Cambalinho.
    Joaquim is my real name and the Cambalinho is 1 nice story from english prof
    i hope theres no problem on that
    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.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

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

  8. #8
    Registered User
    Join Date
    Aug 2013
    Posts
    118
    Quote Originally Posted by laserlight View Post
    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.
    thanks for that. i was trying find these subfurom, but isn't easy... thanks for move it.. thanks

  9. #9
    Registered User
    Join Date
    Aug 2013
    Posts
    118
    Quote Originally Posted by novacain View Post
    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:
    Code:
    SetWindowPos(hwnd, 0, 0, 0, 0, 0,
                SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|
                SWP_DRAWFRAME | SWP_FRAMECHANGED|SWP_NOCOPYBITS);
    the InvalidateRect() can redraw the control, but if the control is transparent:
    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;
    (inst is the class\instance pointer)
    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?
    Last edited by joaquim; 01-31-2014 at 05:25 AM.

  10. #10
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,424
    Quote Originally Posted by joaquim View Post
    thanks for that. i was trying find these subfurom, but isn't easy... thanks for move it.. thanks
    Why is it difficult to find? If you go to the board index and scroll down, it's there.
    I can understand it's difficult to understand where to put something the first time you visit a new board, but now you know how to find it next time!
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  11. #11
    Registered User
    Join Date
    Aug 2013
    Posts
    118
    Quote Originally Posted by Elysia View Post
    Why is it difficult to find? If you go to the board index and scroll down, it's there.
    I can understand it's difficult to understand where to put something the first time you visit a new board, but now you know how to find it next time!
    yes i know... thanks

  12. #12
    Registered User
    Join Date
    Aug 2013
    Posts
    118
    can i use the SetWindowsPos() without doing a flicker?

  13. #13
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,856
    can i use the SetWindowsPos() without doing a flicker?
    Yes, but you cannot call it too often.
    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.
    "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

  14. #14
    Registered User
    Join Date
    Aug 2013
    Posts
    118
    Quote Originally Posted by novacain View Post
    Yes, but you cannot call it too often.
    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:
    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 can share the entire class, but, like Elysia said before, it's to many lines for see
    i have another question: when the control is transparent:
    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);
        }
    and in window procedure:
    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;
    the text isn't showed clean, but the new text is showed above the older
    can you advice me?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Dynamic button controls [WIN32 API/c++/VS 2010]
    By William Putnam in forum Windows Programming
    Replies: 3
    Last Post: 09-10-2013, 09:13 PM
  2. WIN32 API Controls used with Resource
    By parad0x13 in forum C++ Programming
    Replies: 0
    Last Post: 07-19-2008, 02:05 PM
  3. Win32 Common Controls in C++, how do i make and use them?
    By C+noob in forum Windows Programming
    Replies: 6
    Last Post: 01-09-2006, 10:53 AM
  4. c Win32 Programming Controls
    By konvoy_dev_team in forum Windows Programming
    Replies: 1
    Last Post: 03-08-2003, 08:08 PM
  5. spin controls in Win32
    By loobian in forum Windows Programming
    Replies: 4
    Last Post: 10-21-2001, 07:49 PM

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