Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7632565
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T06:39:32+00:00 2026-05-31T06:39:32+00:00

I scroll the parent window by invalidating and redrawing all the content inside WM_PAINT

  • 0

I scroll the parent window by invalidating and redrawing all the content inside WM_PAINT according to current nPos value from scrollbar. I want to scroll without flickering so I handle WM_ERASEBKGND to avoid redrawing the background. I also do simple double buffering for my TextOut calls and for some bitmaps that are displayed. It works good except my child controls. They flicker badly especially when nPos == 0 and app handles SB_LINEUP or nPos == nMax and app handles SB_LINEDOWN or when dragging and dropping the scrollbar. I move them with MoveWindow(). I also have tried DeferWindowPos(). I’ve googled it for a solution for flickering but it doesn’t work or I’m not using it correctly. How to eliminate flickering of child controls?

P.S. When I use WS_CLIPCHILDREN style for main window the controls aren’t flickering but when scrolling some parts of my window get messed up, especially my static control on which I’m drawing some things by handling WM_DRAWITEM.

EDIT: (simplified code)
I double buffer inside WM_PAINT like this:

case WM_PAINT: {
    hDC = BeginPaint( hwnd, &PS );
    hDCMem = CreateCompatibleDC( hDC );
    hBMMem = CreateCompatibleBitmap( hDC, wnd_x, wnd_y );
    SelectObject( hDCMem, hBMMem );

    Font = CreateFont( 130, 50, 0, 0, FW_SEMIBOLD, FALSE, FALSE, FALSE, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, FF_MODERN, "Arial" );
    SelectObject( hDCMem, Font );
    SetTextColor( hDCMem, RGB( 30, 144, 255 ) );
    SetBkColor( hDCMem, RGB( 192, 192, 192 ) );
    TextOut( hDCMem, 650, 69 - scr_pos, "ABC", 3 );

    MoveWindow( GetDlgItem( hwnd, ID_BUTT_START ), 720, 500 - scr_pos, 160, 150, TRUE );

    BitBlt( hDC, 0, 0, wnd_x, wnd_y, hDCMem, 0, 0, SRCCOPY );
    DeleteObject( hBMMem );
    DeleteDC( hDCMem );
    EndPaint( hwnd, &PS );
}

scr_pos is current nPos value taken from scrollbar.

case WM_ERASEBKGND:
    return 1;
break;

case WM_VSCROLL: {
    SCROLLINFO sinfo;
    ZeroMemory( &sinfo, sizeof( SCROLLINFO ) );
    sinfo.cbSize = sizeof( SCROLLINFO );
    sinfo.fMask = SIF_POS | SIF_PAGE | SIF_TRACKPOS;
    GetScrollInfo( hwnd, SB_VERT, &sinfo );
    scr_pos = sinfo.nPos;
    switch( LOWORD( wParam ) ) {
        case SB_TOP:
            scr_pos = 0;
        break;
        case SB_BOTTOM:
            scr_pos = 4000;
        break;
        case SB_LINEUP: {
            scr_pos -= 200;
            if ( scr_pos < 0 ) {
                scr_pos = 0;
            }
        }
        break;
        case SB_LINEDOWN: {
            scr_pos += 200;
            if ( scr_pos > 4000 ) {
                scr_pos = 4000;
            }
        }
        break;
        case SB_PAGEUP: {
            scr_pos -= si.nPage;
            if( scr_pos < 0 ) {
                scr_pos = 0;
            }
        }
        break;
        case SB_PAGEDOWN: {
            scr_pos += si.nPage;
            if( scr_pos > 4000 ) {
                scr_pos = 4000;
            }
        }
        break;
        case SB_THUMBPOSITION:
            scr_pos = HIWORD(wParam);
        break;
        case SB_THUMBTRACK:
            scr_pos = HIWORD(wParam);
        break;
    }    
    RedrawWindow( hwnd, NULL, NULL, RDW_INVALIDATE | RDW_INTERNALPAINT );
//  InvalidateRect ( hwnd, NULL, true );
//  UpdateWindow( hwnd );
    ZeroMemory( & sinfo, sizeof( SCROLLINFO ) );
    sinfo.cbSize = sizeof( SCROLLINFO );
    sinfo.fMask = SIF_POS;
    snfo.nPos = scr_pos;
    SetScrollInfo( hwnd, SB_VERT, & sinfo, TRUE );
    }
}
break;

Nothing flickers except child controls…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T06:39:33+00:00Added an answer on May 31, 2026 at 6:39 am

    WS_CLIPCHILDREN is indeed the solution. Go ahead and activate that, you’ll have to track down the cause of “parts of my window get messed up”, but you haven’t provided sufficient detail about that.

    You might also look into ScrollWindowEx. That documentation specifically describes how to correctly reposition child windows during scrolling.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to scroll the iframe window from the parent window using keys
How do I maintain the scroll position of the parent page when I open
I'm using the $(window).scroll(function() to set classes on the navigation of a site. When
I have the following structure, typedef struct _MainWin { GtkWindow parent; GtkWidget* scroll; GtkWidget*
I have problem to release div in parent window. I need to do this:
I have a scrollbar on my parent UserControl in a Silverlight 4 Business application
The child lost its parent!! I have a parent window, when somebody clicks on
I have a very long iframe inside my parent page. When you reload or
Is there a way to create a ScrollViewer which only allows content to scroll
I want: <div style=height:100%> <div style=height:70px;>header</div> <div style=overflow-y:scroll;>main</div> <div style=height:60px;>footer, alw. at bottom parent-div</div>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.