1

I am working on an MFC dialog based program with CTabCtrl (VS2017, W10). Everything works as expected, apart from the way tabs look (convoluted story, don't ask).

I need them to look like on the right, but when I created a new project with a CDialogEx based class and added tabs to the dialog (just the standard VS/MFC stuff, nothing fancy yet) they looked like the ones on the left. What I found after some testing and comparing with older projects is that if I switch in project defaults Character Set from Unicode to Multi-Byte Character Set I get the look I want (yes, sounds completely unrelated, but checked and rechecked several times). But that's ridiculously inconvenient, program needs to work with different languages and uses Unicode libraries for managing the data.

No idea if the problem is really MFC related, could be some deeper Windows thing.

Any idea what can be done to get the right look (pun intended), other than implementing my own OwnerDraw() or adding an additional layer of code to translate between data in Unicode and MBCS? Both approaches sound pretty off.

Borek
  • 91
  • 6
  • 2
    [Turning Off Visual Styles](https://learn.microsoft.com/en-us/windows/win32/controls/cookbook-overview#turning-off-visual-styles). – IInspectable Dec 07 '22 at 13:47
  • 1
    Please edit your images and show also how the push buttons appear for both cases. – Jabberwocky Dec 08 '22 at 10:04
  • Don't use MBCS. Changing character set between Unicode and MBCS has nothing to do with this. It looks like Visual Styles is not set in your project. Have a look at this https://stackoverflow.com/a/32729776/4603670 try adding the `#pragma` line in the link posted. – Barmak Shemirani Dec 08 '22 at 20:32
  • @Jabberwocky it is definitely problem with visual styles, buttons look "modern" as well, but I don't care too much about them (as I wrote: it is a convoluted story) – Borek Dec 10 '22 at 22:11
  • @BarmakShemirani I can agree with you that it should NOT have anything to do with switching between MBCS and Unicode, but it is the only thing I am changing in the project properties and it is perfectly enough to make the controls look differently. No idea if it is a feature or a bug, but that's the way it works. And yes, modifying visual styles changes the situation. – Borek Dec 10 '22 at 22:14
  • 1
    See if there is a call to `SetWindowTheme`. Otherwise we can't see those buttons so this is a guessing game. – Barmak Shemirani Dec 11 '22 at 02:11
  • `CMFCTabCtrl` is more modern and allows more customization of styles. Perhaps there is one closer to the one you want. And it saves you a lot of work, of the controls' show/hide logic when switchin among tabs. When I discovered it, I never went back to `CTabCtrl`. The first has some examples in the samples directory of Visual Studio. – sergiol Mar 19 '23 at 20:08

1 Answers1

1

Just if someone gets here looking for an answer: turned out it was a problem with different default windows themes being used depending on the character set selected. In the end adding

CWnd *ctl;
ctl = GetWindow(GW_CHILD);
while (ctl)
{
    SetWindowTheme(ctl->m_hWnd, L" ", L" ");
    ctl = ctl->GetNextWindow();
}

to OnInitDialog() made all the controls in the dialog look like I wanted to, even after switching to Unicode.

Borek
  • 91
  • 6