I am currently trying to implement an owner draw tab control.
I thought that it might be similar to the owner draw menus but I have been
unable to get things started. I was wandering if anybody might be able to
give me
a push in the right direction to creating an owner draw tab control. I
obviously know
how to create a tab control and I saw that you can add the
TCS_OWNERDRAWFIXED to
create the owner draw tab.
Any suggestion would be most helpful.
Kind regards
Hi again,
I Kept working at it and this is what I have coem up with. It seems to be
working fine.
//-----------------------
case WM_DRAWITEM:
lpdis = (LPDRAWITEMSTRUCT) lParam; // item drawing information
if (hTab == lpdis->hwndItem) // is this the tab control?
{
// which tab? first, second...fifth
switch (lpdis->itemID)
{
case 0:
tie.mask = TCIF_TEXT;
tie.pszText = "Mon";
SetBkColor(lpdis->hDC, RGB(0, 0, 255));
SetTextColor(lpdis->hDC, RGB(255, 255, 255));
break;
case 1:
tie.mask = TCIF_TEXT;
tie.pszText = "Tue";
SetBkColor(lpdis->hDC, RGB(255, 0, 0));
SetTextColor(lpdis->hDC, RGB(255, 255, 255));
break;
}
//memset(szTabText, NULL, sizeof(szTabText));
//tie.cchTextMax = strlen("Mon");
TabCtrl_GetItem(hTab, lpdis->itemID, &tie);
ExtTextOut(lpdis->hDC,
lpdis->rcItem.left,
lpdis->rcItem.top,
ETO_OPAQUE,
&lpdis->rcItem,
tie.pszText,
lstrlen(tie.pszText),
NULL);
}
break;
.
Is there anyway to change the actual control from standard gray to whatever?
Kind regards.
> Is there anyway to change the actual control from standard gray to whatever?
e.g. by subclassing it (WM_PAINT + WM_PRINTCLIENT)
Hi Christian,
Do you know of any examples, I had a look in MSDN but can't see any.
I noticed also with the tab control, you can't create your own buttons. I
am right in
guessing that if you want something different you would be better of making
the tab control from owner draw buttons? Basically a custom control.
Kind regards
http://www.codeguru.com/cpp/controls/controls/tabcontrols/article.php/c2237
http://www.codeproject.com/KB/tabs/customtab.aspx?display=PrintAll&fid=3216&df=90&mpp=25&noise=3&sort=Position&view=Quick&fr=26
Didn't you find these useful?
-SM
Here is what I have so far . . . . . .
****************************************
// Global Variable
WNDPROC colorProc = NULL;
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
int tabWindow;
static HWND hEdit1, hEdit2, hwndClose;
static TCITEM tie;
static INITCOMMONCONTROLSEX icex;
static LPDRAWITEMSTRUCT lpdis;
switch(msg)
{
case WM_CREATE:
icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
icex.dwICC = ICC_TAB_CLASSES;
InitCommonControlsEx(&icex);
hTab = CreateWindow(WC_TABCONTROL, "Tab Control",
WS_CHILD | WS_VISIBLE | TCS_FLATBUTTONS | TCS_BUTTONS | TCS_FOCUSNEVER,
0, 0, 200, 150, hwnd,(HMENU) ID_TABCTRL, g_hinst, NULL);
colorProc = (WNDPROC) SetWindowLong(hTab, GWL_WNDPROC, (LONG)
SubClassProc);
hEdit1 = CreateWindow("edit",NULL,WS_CHILD | WS_VISIBLE | WS_BORDER,
4, 40, 100, 25, hwnd, (HMENU) EDIT_ONE, g_hinst, NULL);
hEdit2 = CreateWindow("edit",NULL,WS_CHILD | WS_VISIBLE | WS_BORDER,
4, 40, 100, 25, hwnd, (HMENU) EDIT_TWO, g_hinst, NULL);
tie.mask = TCIF_TEXT;
tie.pszText = "Mon";
TabCtrl_InsertItem(hTab, 0, &tie);
tie.mask = TCIF_TEXT;
tie.pszText = "Tue";
TabCtrl_InsertItem(hTab, 1, &tie);
return 0;
case WM_NOTIFY:
switch (((LPNMHDR)lParam)->code)
{
case TCN_SELCHANGE:
tabWindow = TabCtrl_GetCurSel(hTab);
switch(tabWindow)
{
case 0:
SetFocus(hEdit1);
ShowWindow(hEdit1, SW_SHOW);
ShowWindow(hEdit2, SW_HIDE);
return 0;
case 1:
SetFocus(hEdit2);
ShowWindow(hEdit2, SW_SHOW);
ShowWindow(hEdit1, SW_HIDE);
return 0;
}
}
return 0;
case WM_DRAWITEM:
lpdis = (LPDRAWITEMSTRUCT) lParam; // item drawing information
return 0;
case WM_ERASEBKGND:
break;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd, msg, wParam, lParam);
}
LRESULT CALLBACK SubClassProc(HWND hwnd, UINT nMsg, WPARAM wParam, LPARAM
lParam)
{
HBRUSH hBrush;
HDC hdc;
PAINTSTRUCT ps;
RECT rc;
switch (nMsg)
{
case WM_ERASEBKGND:
hdc = BeginPaint(hwnd, &ps);
GetClientRect (hwnd, &rc);
hBrush = CreateSolidBrush (RGB(255, 0,0));
FillRect(hdc, &rc, hBrush);
EndPaint(hwnd, &ps);
DeleteObject(hBrush);
return 0 ;
}
return CallWindowProc(colorProc, hwnd, nMsg, wParam, lParam);
}
******************************************
So how would one set a desired color without painting over the buttons?
Also you can see this is not perfect. Any Ideas?
kind regards
Because you don't use WM_PRINTCLIENT to draw the control in
double-buffering.
//**********************************
Hello,
I know how to do double buffering but I am confused to where WM_PRINTCLIENT
is supposed to be
called.
If I change my code in SubClassProc from WM_ERASEBKGND to WM_PAINT, then
where do I call
WM_PRINTCLIENT? Also do I have to replace this call. . . .
"colorProc = (WNDPROC) SetWindowLong(hTab, GWL_WNDPROC, (LONG)
SubClassProc);"
. . . . in the main WndProc?
I did find a work around with the WM_ERASEBKGND method. This just involved
putting the
"Tab Control" in a child window, with it own WNDCLASS. Then I just set the
back ground color . . .
"wnclass.hbrBackground(HBRUSH)GetStockObject(BLACK_BRUSH)" or whatever color
you like.
This worked.
Kind regards.