I have a tab control but when a tab is selected the tab title is not the sam color as the form on the tab.
How can I make the tab title the same color as the main form?
thanx
bert
It is not as easy as you might think. You need to use the %TCS_OWNERDRAWFIXED style for the tab control and then respond to the %WM_DRAWITEM message and manually paint the tab and draw the caption text.
I am working on an example for you and I hope to post it this afternoon.
OK, try the following code. It seems to work... Place it in the CUSTOM message handler of your FORM (not the Tab Control). Also, you will probably have to change some of the hwnd/IDC variables to match yours. I haven't had time to optimize the code or make it look good. :)
'------------------------------------------------------------------------------------------------------------------------
Function FRMMAINFORM_CUSTOM ( _
hWndForm As Dword, _ ' handle of Form
wMsg As Long, _ ' type of message
wParam As Dword, _ ' first message parameter
lParam As Long _ ' second message parameter
) As Long
Local lPnmh As NMHDR Ptr
Local lRet As Long
Local lDBU As Long
Local lTCI As TC_ITEM
Local lDISPtr As DRAWITEMSTRUCT Ptr
Local lZStr As Asciiz * %MAX_PATH
Local hFont As Dword
Local rc As Rect
Local lRect As Rect
Local TCITEM As TC_ITEM
Select Case wMsg
Case %WM_DRAWITEM
lDisPtr = lParam
lZStr = FF_TabControl_GetText (HWND_FRMMAINFORM_TABCONTROL1, @lDisPtr.ItemId)
TabCtrl_GetItemRect HWND_FRMMAINFORM_TABCONTROL1, @lDisPtr.ItemId, lRect
If @lDisPtr.ItemState = %ODS_SELECTED Then
rc = lRect
rc.nBottom = rc.nBottom + 4
' Set the background colors of the caption to print to the same as the child
' form that is being displayed.
TCITEM.Mask = %TCIF_PARAM
TabCtrl_GetItem HWND_FRMMAINFORM_TABCONTROL1, @lDisPtr.ItemId, TCITEM
FillRect @lDisPtr.hDC, rc, GetClassLong( TCITEM.lParam, %GCL_HBRBACKGROUND)
SetBkMode @lDisPtr.hDC, %TRANSPARENT
'*Use a bold font if selected
hFont = CreateFont(-8,0,0,0,%FW_BOLD,0,0,0,0,0,0,0,0,"MS Sans Serif")
Else
'*Or a normal one if not selected
hFont = CreateFont(-8,0,0,0,%FW_NORMAL,0,0,0,0,0,0,0,0,"MS Sans Serif")
End If
hFont = SelectObject(@lDisPtr.hDC, hFont)
SetTextColor @lDisPtr.hDc, %Black
TextOut @lDisptr.hDc, lRect.nLeft + 5, lRect.nTop + 3, lZStr, Len (lZStr)
DeleteObject SelectObject( @lDisPtr.hDC, hFont )
End Select
End Function
Your the greatest !!
I was lost trying to figure out where to put the code I had assembled from PB's site. It either errored out or did nothing that I could see.
thanx again
bert
Sorry to bug you again but the %wm_drawitem does not fire up. I have put in the main form where the tab control is located and in the child form but still does not fire.
Bert
Did you modify the WindowStyles of the TabControl to check the TCS_OWNERDRAWFIXED style ???? That style needs to be checked in order for the owner drawn messages to be triggered.
You could always disable XP Themes for the app too...sounds like that was the issue to begin with and custom drawing it takes the themes away anyway...
Sorry I didn't get back to you earlier. I did sent a reply before Paul sent his about the TCS_OWNERDRAWFIXED flag. This was the problem. I had it working on a test program and didn't work on the real one. so when I started checking it was that flag that wasn't set
Thanx everybody
Bert