0

I have to restyle our SysTabControl32, so I'm trying to use TCS_OWNERDRAWFIXED and WM_DRAWITEM. Everything works well BUT it seems that the Tabs are still overpainted by the system.

Unfortunately the code is in Visual Objects which makes things more complicated. I already tried a lot of things during the last hours and for the time being I'm clueless. Maybe some of you guys can help or give ma a hint.

Here are some Pictures:

"Naked" Tabcontrol with TCS_OWNERDRAWFIXED. No code at WM_DRAWITEM.

You will notice that the tabs are not filled, but the 3D-Style is painted. And this is my main problem, because as long as I know this shouldn't happen.

image

Ownerdrawn Tabs with Text and Background Color (ugly but useful in order to see the Problem)

image

The same TabControl but with TCS_FLATBUTTONS and TCS_EX_FLATSEPARATORS set. Still the problem with the grey background.

image

As you know WM_DRAWITEM will be catched in the parent window. I also tried to overwrite or ignore WM_PAINT in the TabControl itself. But it don't help.

Also I played with WM_ERASEBKGND, but I'm stuck at this point.

At all pages starting from codeplex to codeguru or even vbAccelerator it should work. Should :) Don't know if it's visual objects, but API are API and this is still a standard control.

WM_DRAWITEM contains this code, which seems okay. item is DRAWITEMSTRUCT.

hdc := item.hdc
tabIndex := item.itemID
lSelected := (item.itemState == ODS_SELECTED)

wBrush := CreateSolidBrush(RGB(128,128,255))
FillRect(hdc, @item.rcItem, wBrush)
DeleteObject(wBrush)

SetBkMode(hdc,TRANSPARENT)
tTI := MemAlloc(_SizeOf(_winTC_ITEM))
tTI.cchTextMax := 255
tTI.pszText := String2Psz(Buffer(255))
tTI.mask := TCIF_TEXT
lr := SendMessage(item.hwndItem, TCM_GETITEM, item.itemID, LONG(_CAST, tTI))
if (lr != 0)
     if (lSelected)
         SetTextColor(hdc,RGB(255,0,0))
     ELSE
         SetTextColor(hdc,RGB(0,0,255))
     ENDIF
     DrawText(hdc,tTI.pszText,-1,@item.rcItem, _OR(DT_SINGLELINE, DT_VCENTER, DT_CENTER))
ENDIF
MemFree(tTI)
Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
Jay
  • 1
  • Pretty hard to tell from this small extract. There are plenty of code samples around that do this kind of thing. BTW, allocate fixed size structs on the stack for simpler code. – David Heffernan Apr 25 '19 at 18:13
  • Hi Jay, can you show a picture of comparing the problematic tab and your expected tab for more clear demonstrating the issue? BTW, TCS_FLATBUTTONS style with [TCS_EX_FLATSEPARATORS](https://learn.microsoft.com/en-us/windows/desktop/controls/tab-control-extended-styles) style set, no need to set it additionally. – Rita Han Apr 29 '19 at 08:33

1 Answers1

1

This is my trick to custom draw SysTabControl32

RECT defaultRect = lpDrawItemStruct->rcItem;
//
// Begin of WM_DRAWITEM, we clear the clip rect
SelectClipRgn(lpDrawItemStruct->hDC, NULL);
..
..
..
// End of WM_DRAWITEM, we create a clip rect to disable default system border
ExcludeClipRect(lpDrawItemStruct->hDC, 
        defaultRect.left - 3,
        defaultRect.top - 2,
        defaultRect.right + 3,
        defaultRect.bottom + 2);

Reference: https://github.com/pladaria/emule/blob/master/srchybrid/ClosableTabCtrl.cpp

Hong Duc
  • 11
  • 2