winapirichedit

RichEdit control doesn't show horizontal scrollbar when switching tabs


I have a tab control with some RichEdit controls. Whenever the active tab changes, I hide the RichEdit control belonging to the old page and show the RichEdit control belonging to the new page. This works except that the horizontal scrollbar of the RichEdit control doesn't show. When switching tabs, it looks like this:

screenshot 1

As soon as I change the cursor position, however, the horizontal scrollbar suddenly appears and it looks like this then:

screenshot 2

I've debugged what's going on and found out that the following code is responsible for making the scrollbar appear:

RedrawWindow(hRichEditWnd, NULL, NULL, RDW_FRAME|RDW_INVALIDATE|RDW_UPDATENOW); 

The call to RedrawWindow is made by the code that implements syntax highlighting. This code is executed when changing the cursor position.

So I tried to simply call RedrawWindow like above when changing tabs but it does not work. The horizontal scrollbar still does not appear. However, when RedrawWindow is called later, e.g. in response to the user changing the cursor position, the horizontal scrollbar suddenly appears.

Any idea on how to fix this so that the scrollbar appears right when changing tabs?


Solution

  • After trying several things I've found out that calling ShowWindow before repositioning the dock windows and the RichEdit control solved the issue. Previously, I was doing something like this when switching tabs:

    BeginDeferWindowPos();
    ...reposition and resize all dock windows and the RichEdit control ...
    EndDeferWindowPos();
    ShowWindow(hRichEditWnd, SW_SHOW);
    

    When I call ShowWindow before BeginDeferWindowPos the issue is gone, i.e.:

    ShowWindow(hRichEditWnd, SW_SHOW);
    BeginDeferWindowPos();
    ...reposition and resize all dock windows and the RichEdit control ...
    EndDeferWindowPos();
    

    Don't ask me why this solves the issue, but it does.