Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5941319
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T16:05:35+00:00 2026-05-22T16:05:35+00:00

I need to create a SDI form with a formview that has two tabs,

  • 0

I need to create a SDI form with a formview that has two tabs, which encapsulate multiple dialogs as the tab content. But the form has to have a colored background.

And things like these makes me hate programming.

First, I tried CTabControl, via resource editor, tried different things, but the undocumented behavior and the quirks with no answers led me into a roadblock.

After many hours of searching, I found that there is a control called property sheet, which is actually what I need.

Some more searching later, I found that property sheet can even be actually embedded onto CFormView like so: http://www.codeguru.com/Cpp/controls/propertysheet/article.php/c591

And that the dialog classes derived from CPropertyPage can be directly added as pages via AddPage method of CPropertySheet.

Great! Not quite so… Some of the controls didn’t worked, and were not created, ran into weird asserts. Turns out the DS_CONTROL style was missing from the dialogs. Found it completely accidentaly on Link, no word about that on MSDN!!!! Property page must have: DS_3DLOOK | DS_CONTROL | WS_CHILD | WS_TABSTOP, and can have: DS_SHELLFONT | DS_LOCALEDIT | WS_CLIPCHILDREN styles! Not any other, which are created by default with resource editor. Sweet, super hidden information for software developers!

The quote in comments on that page: "OMG. That’s where that behavior came from…

It turns out that the PlaySound API relied on that behavior when playing sounds on 64bit machines." by Larry Osterman, who as I understand works for Microsoft for 20 years, got me laughing out loud.

Anyway, fixed that, the dialog-controls(CPropertyPages) are created as expected now, and that part looks something remotely promising, but the next part with color is dead end again!

Normally you override WM_CTLCOLOR, check for control ID or hwnd and supply the necessary brush to set the color you need. Not quite so with CPropertySheet, the whole top row stays gray! For CTabCtrl it somehow works, for CPropertySheet it doesn’t.

Why? Seems that the CPropertySheet is kinda embedded inside CTabControl or something, because if I override WM_ERASEBKGND, only the internal part changes the color.

Now it seems that there is a GetTabControl() method in the CPropertySheet, that returns the actual CTabCtrl* of the CPropertySheet. But since it’s constructed internally, I can’t find how to override it’s WM_CTLCOLOR message processing.

There seems to be a way to subclass the windowproc, but after multiple tries I can’t find any good source on how to do it. SubclassWindow doc on MSDN says: "The window must not already be attached to an MFC object when this function is called."?! What’s that?

I tried creating a custom CCustomTabCtrl class based on CTabCtrl via MFC wizard, created an instance of it, called SubclassWindow from one of the CCustomPropertySheet handlers to override the internal CTabCtrl, but nothing works, mystical crashes deep inside MFC.

Tried setting WindowLong with GCL_HBRBACKGROUND for the internal CTabCtrl, nothing changed.

And worst of all, I can’t find any sort of useful documentation or tutorials on the topic.

Most I can find is how to ownerdraw the tab control, but this is seriously wrong on so many ways, I want a standard control behavior minus background color, I don’t want to support different color schemes, windows versions, IAccesible interfaces and all this stuff, and none of the ownerdraw samples I’ve seen can get even 10% of all the standard control behavior right. I have no illusion that I will create something better, I wont with the resources at hand.

I stumbled upon this thread, and I can’t agree with the author more: http://arstechnica.com/civis/viewtopic.php?f=20&t=169886&sid=aad002424e80121e514548d428cf09c6 owner draw controls are undocumented PITA, that are impossible to do right, and there is NULL information on MSDN to help.

So is there anything I have missed or haven’t tried yet? How to change the top strip background color of the CPropertySheet? Anyone?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T16:05:36+00:00Added an answer on May 22, 2026 at 4:05 pm

    Your only option is to ownerdraw the tab control. It’s not that hard. Well, it is frustrating because MFC doesn’t tell you how to make the necessary Win32 calls.

    In your CPropertySheet-derived class, overwrite OnInitDialog() and add:

    GetTabControl()->ModifyStyle(0,TCS_OWNERDRAWFIXED);

    This puts your CPropertySheet-derived class in charge of drawing the tab control. Add a handler for WM_DRAWITEM (OnDrawItem) and change backgroundColor and textColor to match whatever colors you wanted. Code for OnDrawItem follows:

    void CPropSht::OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct)
    {
        if (ODT_TAB != lpDrawItemStruct->CtlType)
        {
            CPropertySheet::OnDrawItem(nIDCtl, lpDrawItemStruct);
            return;
        }
    
        // prepare to draw the tab control
        COLORREF backgroundColor = RGB(0,255,0);
        COLORREF textColor = RGB(0,0,255);
        CTabCtrl *c_Tab = GetTabControl();
    
        //  Get the current tab item text.
        TCHAR buffer[256] = {0};
        TC_ITEM tcItem;
        tcItem.pszText = buffer;
        tcItem.cchTextMax = 256;
        tcItem.mask = TCIF_TEXT;
    
        if (!c_Tab->GetItem(c_Tab->GetCurSel(), &tcItem )) return;
    
        // draw it
        CDC aDC;
        aDC.Attach(lpDrawItemStruct->hDC);
        int nSavedDC = aDC.SaveDC();
    
        CBrush newBrush;
        newBrush.CreateSolidBrush(backgroundColor);
        aDC.SelectObject(&newBrush);
        aDC.FillRect(&lpDrawItemStruct->rcItem, &newBrush);
        aDC.SetBkMode(TRANSPARENT); 
        aDC.SetTextColor(textColor);
        aDC.DrawText(tcItem.pszText, &lpDrawItemStruct->rcItem, DT_CENTER|DT_VCENTER|DT_SINGLELINE);
    
        aDC.RestoreDC(nSavedDC);
    
        aDC.Detach();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to create a form which has 2(Yes/NO) options and if the user
I need to create a <div> of height 200px that has some text at
Need to create a custom DNS name server using C which will check against
I need to create an XML schema that looks something like this: <xs:element name=wrapperElement>
I need to create an ASP page (classic, not ASP.NET) which runs remote shell
I need to create a backup of a SQL Server 2005 Database that's only
I need create a very big project, the project has a lot of tables
I need to create a list of files which are located on my hard
I need to create a script that will log into an authenticated page and
I need to create a program that will communicate with other programs on the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.