0

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?

Andreas
  • 9,245
  • 9
  • 49
  • 97
  • Try calling `UpdateWindow` right after `ShowWindow`. Although it seems that you are using a custom window implementation. Without knowing what that is, it's difficult to understand what's going wrong and how to fix it. – IInspectable Mar 07 '21 at 14:43
  • @IInspectable: Unfortunately, that didn't help. The scrollbar still doesn't show. I'm using the DockWnd library from here: https://www.codeproject.com/Articles/10224/Docking-Toolbars-in-Plain-C When switching tabs, the library seems to use `BeginDeferWindowPos` to set the sizes and positions of multiple windows, including the RichEdit control. However, my call to `ShowWindow` and `UpdateWindow` is after the `DeferWindowPos` stuff... – Andreas Mar 07 '21 at 16:58
  • I created a sample and tested it, and the horizontal scroll bar did not disappear when I switched tabs.Could you please show [a minimal, reproducible sample](https://stackoverflow.com/help/minimal-reproducible-example) without private information? – Zeus Mar 08 '21 at 08:40
  • Thanks for your help, but I've solved it now myself, see below. – Andreas Mar 08 '21 at 17:24

1 Answers1

0

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.

Andreas
  • 9,245
  • 9
  • 49
  • 97