Aaahhh!!! HELP!!! I pulled my hair out for a few days to be able to use the tab controls (CXTTabCtrl) nicely in 10.3.1. Now I have downloaded and installed 10.4 and my old fix doesn't work!!!
Some background on my solution. I needed to encapsulate each page of the control in it's own class (CXTResizePropertyPage derived currently.) Using the following code I added these pages:
m_page1->Create(&m_cWhenTabs);
m_page2->Create(&m_cWhenTabs);
m_page3->Create(&m_cWhenTabs);
m_page4->Create(&m_cWhenTabs);
m_cWhenTabs.AddControl(_T("1"), m_page1);
m_cWhenTabs.AddControl(_T("2"), m_page2);
m_cWhenTabs.AddControl(_T("3"), m_page3);
m_cWhenTabs.AddControl(_T("4"), m_page4);
m_cWhenTabs.SendInitialUpdate(TRUE);
m_cWhenTabs.SetAutoCondense(true); |
The trouble with this is that the tab control, as encapsulated by CXTTabCtrl, has a nice pretty gradient background, while the property pages have a nice ugly solid background. Place the one on top of the other and it is REALLY ugly. I needed to fix this so I divined the following solution:
BOOL CTransparentForm::OnEraseBkgnd(CDC* pDC)
{
if (((CXTTabCtrl*)GetParent())->IsWindowVisible())
{
CXTPClientRect rcClient(((CXTTabCtrl*)GetParent()));
(( CXTTabCtrl*)GetParent())->ClientToScreen(rcClient);
ScreenToClient(rcClient);
CXTPBufferDC memDC(*pDC, rcClient);
CRect r;
GetWindowRect(r);
(( CXTTabCtrl*)GetParent())->ScreenToClient(r);
(( CXTTabCtrl*)GetParent())->GetPaintManager()->DrawTabCtrl(&memDC, (CXTTabCtrl*)GetParent());
CRect rAll = rcClient;
rAll.MoveToXY(0,0);
// for some unknown reason, the ScrollDC function is leaving some stuff
// at the bottom as an artifact, however, the result is barely noticeable
// (only if you are looking for it) as long as we do the vertical and
// horizontal scrolls separately. If we do them together we get a nice
// vertical bar on the tab in the bottom left corner.
memDC.ScrollDC(0, -r.top, NULL, NULL, NULL, NULL);
memDC.ScrollDC(-r.left, 0, NULL, NULL, NULL, NULL);
}
return true;
} |
Basically, the code assumes that we are on top of a CXTTabCtrl, which is the parent. We grab the parent, ask it to paint itself on our device context (as our method of erasing the background) position everything properly, and return true (to indicate that the background was erased.)
In version 10.3.1 this solution worked, in the current version the net effect seems to be nothing.
I would of course be satisfied with just being able to see the tab control background again, however, ultimately, this solution is ugly. Is there any chance of getting a more solid solution in the future, perhaps a CXTTabControlPage that removes the burden from code on the user side?
I have a hard time imagining that I am the first person to have a problem with this. Using tab controls is an immense amount of work because of the gradient background. I had to override and paint Checkboxes, radio buttons, group boxes, static text, and there are some things I didn't get to because I didn't need to use them. Perhaps it wouldn't be a bad idea to have a set of classes to draw these "transparent" items in a truly transparent fashion. Without this, the tab controls are hard enough to use, it isn't even worth it anymore for the average program, however, I digress.
I have everything in place to be able to use the tab controls, but I can't because the stupid property page can't pretend to be transparent anymore. Can anybody suggest a solution?
John.
|