1

I have a WIN32 application. Its main window is hwndMain, one of its child is hwndView. There is one tab control hwndTab on hwndView.

When I resize hwndMain, hwndView is resized and so is hwndTab. It flicker a little, but not much.

I have tried to use WS_EX_COMPOSITED style ( for hwndView or hwndTab), but it just gave me blank window. I tried to use WS_EX_TRANSPARENT and it solves flicker, but when the windows is resized to be larger, the childs are updated very slow, e.g I see black region for one second, then the region is updated.

I have successfully sloved the flicker issue for TreeView by using WS_CHIPCHILDREN style. (See remark below). But using WS_CHIPCHILDREN stlye for hwndView doesn't fix the flicker issue for tab control.

I have paid attention to WM_ERASEBKGND and Not set hbrBackground also.

I want to use double buffer for tab control, but I can't find a tutorial for this purpose. All the tutorial I found is: In WM_PAINT, after creating CompatibleDC and CompatibleBitmap, draw what you want in memdc and.....; But I don't want to do any custom drawing in WM_PAINT for hwndTab. I just want to leave the tab control do this job, but shows the final result only.

Could someone show me a small example how to double buffer a tab control (if you think this will fix the flicker issue of tab control), in the language c + winapi, since I don't have the knowledge of C#, Net,..etc.


Remark: For my TreeView, it is a child of a window hwndContainer. It is created as:

win->hwndContainer = CreateWindowEx(
    WS_CLIPCHILDREN,
    _T("SUMATRA_PDF_TOCBOX"), NULL,
    WS_CHILD,
    0, 0, gGlobalPrefs.sidebarDx, 0,
    win->hwndPanel, NULL,
    ghinst, NULL);

Using WS_CLIPCHILDREN fix the flicker, even if I don't use double buffer. But it is strange to put WS_CLIPCHILDREN in the first parameter position. If I put it after WS_CHILD, i.e

win->hwndContainer = CreateWindowEx(
    NULL,
    _T("SUMATRA_PDF_TOCBOX"), NULL,
    WS_CHILD | WS_CLIPCHILDREN,
    0, 0, gGlobalPrefs.sidebarDx, 0,
    win->hwndPanel, NULL,
    ghinst, NULL);

,then the flicker still occurs.

So I also tried to use the first way when I created hwndView, but it just gave blank white window. I am really confused with these stuff.

Here is the blank window picture when I used WS_EX_COMPOSITED for hwndView. There is no such problem when I used it for hwndContainer.

hwndView in fact has two child: a Tab Control hwndTab and a child which has its own double buffer and drawing. I am not sure if this cause the problem for using WS_EX_COMPOSITED.

enter image description here

user565739
  • 1,302
  • 4
  • 23
  • 46

1 Answers1

2

You are using the WS_EX_COMPOSITED style. When you pass WS_CLIPCHIDREN as the first argument to the CreateWindowEx, it's interpreting the value of WS_CLIPCHILDREN as an extended window style. Since the value of WS_CLIPCHILDREN is 0x02000000L, the same as WS_EX_COMPOSITED, you've just created a composited window.

And a composited window, according to the documentation, has all of its descendants painted in a bottom-to-top painting order using double-buffering.

I'm not sure what you mean when you say:

I have tried to use WS_EX_COMPOSITED style ( for hwndView or hwndTab), but it just gave me blank window.

You'll have to post code the reproduces this problem. But your second-to-last code snippet is producing a composited window.

Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
  • No, I didn't combine `WS_EX_COMPOSITED` with `WS_CLIPCHIDREN`. I first tried (for hwndView) `WS_EX_COMPOSITED` alone, but it gave me white blank window. Then I tried `WS_CLIPCHILDREN` in the third parameter, i.e `WS_CHILD | WS_CLIPCHILDREN`, no problem but doesn't fix the flicker issue. – user565739 Aug 06 '12 at 07:31
  • But with you explanation, I know why it works for TreeView when I put `WS_CLIPCHILDREN` in the first parameter. – user565739 Aug 06 '12 at 07:33