title: Common controls are not properly painted when I resize window
body: <h2>INTRODUCTION:</h2>
  
  <p>I am creating tab control with child dialog boxes as pages. </p>
  
  <p>I have <code>Visual Styles</code> enabled via <code>#pragma</code> comment. I have also called <code>InitCommonControlsEx</code> and <code>#pragma comment( lib, "comctl32.lib" )</code> as well.</p>
  
  <p>Initially, when window loads, dialog and its common controls have proper background, please see image below:</p>
  
  <p><img src="https://i.stack.imgur.com/nB8RA.png" alt="enter image description here"> </p>
  
  <p>During resizing things are not so consistent -> background starts to mismatches visibly. I will provide screenshot below:</p>
  
  <p><img src="https://i.stack.imgur.com/3Fa3c.png" alt="enter image description here"></p>
  
  <p>You can clearly see that <code>checkbox</code> and <code>static control</code> have improper background, while it seems to me that <code>dialog box</code> ( created to act as a child control ) has proper background.</p>
  
  <p><strong>Edited on November 24th, 2014:</strong></p>
  
  <p>After enclosing controls into <code>group boxes</code> there seems to be no painting problems. My monitor is old CRT ( Samsung SyncMaster 753s ), and I have bad eyesight, but again, it seems that everything paints properly. The window still flickers horribly on resize, but <a href="https://stackoverflow.com/questions/27083387/my-application-slightly-flickers-on-resize-despite-applying-known-techniques-for">I have tried everything in my power</a> to fix it. </p>
  
  <h2>QUESTION:</h2>
  
  <p>How can I fix this?</p>
  
  <h2>MY EFFORTS TO SOLVE THIS:</h2>
  
  <p>I haven't found anything yet but I am still Goggling while typing this question...</p>
  
  <h2>RELEVANT INFORMATION:</h2>
  
  <p>Here are the instructions for creating demo that illustrates the problem:</p>
  
  <p>1.) Create empty <code>C++</code> project in <code>Visual Studio</code>;</p>
  
  <p>2.) add header file, name it <code>pomocne_funkcije.h</code> and copy/paste following:</p>
  
  <pre><code>#include &lt;windows.h&gt;
  #include &lt;windowsx.h&gt;
  #include &lt;comutil.h&gt;
  #include &lt;commctrl.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;vector&gt;
  #include &lt;ole2.h&gt;
  #include &lt;string&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;locale.h&gt;
  #include &lt;Uxtheme.h&gt;
  
  #pragma comment( linker, "/manifestdependency:\"type='win32' \
  name='Microsoft.Windows.Common-Controls' version='6.0.0.0' \
  processorArchitecture='*' publicKeyToken='6595b64144ccf1df' \
  language='*'\"")
  
  #pragma comment( lib, "comctl32.lib")
  #pragma comment( lib,"Msimg32.lib")
  #pragma comment( lib, "comsuppw.lib")
  #pragma comment( lib, "UxTheme.lib")
  </code></pre>
  
  <p>3.) Create dialog box in resource editor, add checkbox static control. </p>
  
  <p>Set the following for dialog box:</p>
  
  <ul>
  <li>Border : none</li>
  <li>Control : true</li>
  <li>Control parent : true</li>
  <li>Style : child</li>
  <li>System menu : false</li>
  </ul>
  
  <p>4.) Here is the code for <code>main.cpp</code> :</p>
  
  <pre><code>#include "pomocne_funkcije.h"
  
  static HINSTANCE hInst;
  
  // dialog procedure for firts tab
  INT_PTR CALLBACK Ugovori(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  {
      UNREFERENCED_PARAMETER(lParam);
      switch (message)
      {
      case WM_INITDIALOG:
          {
              EnableThemeDialogTexture( hDlg, ETDT_ENABLETAB );
          }
          return (INT_PTR)TRUE;
      }
      return (INT_PTR)FALSE;
  }
  
  // main window procedure
  LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
  {
      static HWND hDlgFirstTab;  // handle to the first page dialog box
      switch(msg)
      {
      case WM_CREATE:
          {
              RECT rcClient = {0};
              ::GetClientRect( hwnd, &amp;rcClient );
  
              HWND hwndTab = CreateWindowEx( 0, WC_TABCONTROL, 
                  L"Ugovori", WS_CHILD | WS_VISIBLE, 
                  10, 10, rcClient.right - rcClient.left - 20,
                  rcClient.bottom - rcClient.top - 63, 
                  hwnd, (HMENU)3000, 
                  ((LPCREATESTRUCT)lParam)-&gt;hInstance, 0 );
  
              TCITEM tci = {0};
  
              tci.mask = TCIF_TEXT;
              tci.pszText = L"Основни подаци";
              TabCtrl_InsertItem( hwndTab, 0, &amp;tci );
  
              // set font so cyrilic symbols can be properly displayed instead of ???
              SendMessage( hwnd, WM_SETFONT, 
                  (WPARAM)(HFONT)GetStockObject(DEFAULT_GUI_FONT),
                  (LPARAM)TRUE );
  
              SendMessage( hwndTab, WM_SETFONT, 
                  (WPARAM)(HFONT)GetStockObject(DEFAULT_GUI_FONT),
                  (LPARAM)TRUE );
  
              // create page ( dialog box )
              hDlgFirstTab = CreateDialog( ((LPCREATESTRUCT)lParam)-&gt;hInstance,
                  MAKEINTRESOURCE(IDD_DIALOG1), 
                  hwnd, 
                  (DLGPROC)Ugovori );  // dialog procedure 
  
              ShowWindow( hDlgFirstTab, SW_SHOW );
  
          }
          return 0L;
      case WM_MOVE:
      case WM_MOVING:
      case WM_SIZING:
      case WM_SIZE:
          {
              RECT rcClient = {0};
              GetClientRect( hwnd, &amp;rcClient );
  
              SetWindowPos( GetDlgItem( hwnd, 3000 ), NULL, 
                  rcClient.left + 10, // move it away from window edge by 10 pixels
                  rcClient.top + 10,  // move it away from window edge by 10 pixels
                  rcClient.right - rcClient.left - 20,  
                  // - 63 was the size of the button, 
                  // but I have deleted that button here to preserve space
                  rcClient.bottom - rcClient.top - 63, 
                  SWP_NOZORDER | SWP_NOCOPYBITS );
  
              // get tab control's client rectangle
              GetClientRect( GetDlgItem( hwnd, 3000 ), &amp;rcTab );
  
              //============= place dialog box into tab's client area
              MapWindowPoints( GetDlgItem( hwnd, 3000 ), hwnd, 
                  (LPPOINT)(&amp;rcTab), 2 );
              // get tab's display area
              TabCtrl_AdjustRect( GetDlgItem( hwnd, 3000 ), 
                  FALSE, &amp;rcTab );
              // move dialog box
              SetWindowPos(hDlgFirstTab, NULL, 
                  rcTab.left, rcTab.top,
                  rcTab.right - rcTab.left, 
                  rcTab.bottom - rcTab.top, 
                  SWP_NOZORDER);
  
              //========================= done
              // repaint window
              InvalidateRect( hwnd, NULL, FALSE );
          }
          return 0L;
      case WM_ERASEBKGND:
          return 1L;
      case WM_PAINT:
          {
              PAINTSTRUCT ps = {0};
              HDC hdc = BeginPaint( hwnd, &amp;ps );
              SendMessage( hwnd, WM_PRINTCLIENT, (WPARAM)hdc, 0 );
              EndPaint( hwnd, &amp;ps );
          }
          return 0L;
      case WM_PRINTCLIENT:
          {
              RECT rcClient = {0};
              GetClientRect( hwnd, &amp;rcClient );
  
              FillRect( (HDC)wParam, &amp;rcClient, 
                  (HBRUSH)GetStockObject(WHITE_BRUSH) );
          }
          return 0L;
      case WM_CLOSE:
          ::DestroyWindow(hwnd);
          return 0L;
      case WM_DESTROY:
          ::PostQuitMessage(0);
          return 0L;
      default:
          return ::DefWindowProc( hwnd, msg, wParam, lParam );
      }
      return 0;
  }
  
  // WinMain
  
  int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, 
                     int nCmdShow)
  {
      // store hInstance in global variable for later use
  
      hInst = hInstance;
  
      WNDCLASSEX wc;
      HWND hwnd;
      MSG Msg;
  
      // initialize common controls
  
      INITCOMMONCONTROLSEX iccex;
      iccex.dwSize = sizeof(INITCOMMONCONTROLSEX);
      iccex.dwICC = ICC_LISTVIEW_CLASSES | ICC_UPDOWN_CLASS | 
         ICC_STANDARD_CLASSES | ICC_TAB_CLASSES;
      InitCommonControlsEx(&amp;iccex);
  
      // register main window class
  
      wc.cbSize = sizeof(WNDCLASSEX);
      wc.style = 0;
      wc.lpfnWndProc = WndProc;
      wc.cbClsExtra = 0;
      wc.cbWndExtra = 0;
      wc.hInstance = hInst;
      wc.hIcon = LoadIcon( hInstance, IDI_APPLICATION );
      wc.hCursor = LoadCursor( NULL, IDC_ARROW );
      wc.hbrBackground = (HBRUSH)GetStockObject( WHITE_BRUSH );
      wc.lpszMenuName = NULL;
      wc.lpszClassName = L"Main_Window";
      wc.hIconSm = LoadIcon( hInstance, IDI_APPLICATION );
  
      if(!RegisterClassEx(&amp;wc))
      {
          MessageBox(NULL, 
              L"Window Registration Failed!", L"Error!", 
              MB_ICONEXCLAMATION | MB_OK);
  
          return 0;
      }
  
      // create main window
  
      hwnd = CreateWindowEx( 0, L"Main_Window", 
          L"Contract manager", 
          WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN, 
          CW_USEDEFAULT, 
          CW_USEDEFAULT, 
          CW_USEDEFAULT, 
          CW_USEDEFAULT, 
          NULL, NULL, hInstance, 0 );
  
      if(hwnd == NULL)
      {
          MessageBox(NULL, L"Nemogu da napravim prozor!", L"Greska!",
              MB_ICONEXCLAMATION | MB_OK);
  
          return 0; 
      }
  
      ShowWindow(hwnd, nCmdShow);
      UpdateWindow(hwnd);
  
      while(GetMessage(&amp;Msg, NULL, 0, 0) &gt; 0)
      {
          TranslateMessage(&amp;Msg);
          DispatchMessage(&amp;Msg);
      }
  
      return Msg.wParam;
  }
  </code></pre>
  
  <p>I am working in <code>Visual Studio 2008</code> on <code>Windows XP</code> using <code>C++</code> and <code>WinAPI</code>.</p>