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:
As soon as I change the cursor position, however, the horizontal scrollbar suddenly appears and it looks like this then:
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?
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.