Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Owner Draw Tab Controls?

424 views
Skip to first unread message

bohanson

unread,
Apr 29, 2009, 8:08:00 AM4/29/09
to
Hi There,

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


bohanson

unread,
Apr 29, 2009, 9:14:13 AM4/29/09
to

"bohanson" <justins...@msn.com> wrote in message
news:gt9fvd$q02$1...@aioe.org...


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.


Christian ASTOR

unread,
Apr 29, 2009, 10:21:51 AM4/29/09
to
On 29 avr, 15:14, "bohanson" <justinsatri...@msn.com> wrote:

> Is there anyway to change the actual control from standard gray to whatever?

e.g. by subclassing it (WM_PAINT + WM_PRINTCLIENT)

bohanson

unread,
Apr 30, 2009, 11:44:08 AM4/30/09
to

"Christian ASTOR" <cast...@club-internet.fr> wrote in message
news:10a4a27f-d23b-4c40...@b7g2000pre.googlegroups.com...

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


Seetharam

unread,
Apr 30, 2009, 12:22:06 PM4/30/09
to

bohanson

unread,
Apr 30, 2009, 12:33:47 PM4/30/09
to
Ok I looked into it abit more and I came up with this. It uses WM_ERASEBKGND
instead of WM_PAINT. When I tried using WM_PAINT, it then paints over the
buttons aswell,
that is why there is the hdc variables left in the subClassProc because I
was trying the paint method as stated.
With this curremnt method it just set the control to the main window color.
I noticed that I also had to set WM_ERASEBKGND and break.


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


Christian ASTOR

unread,
May 1, 2009, 5:03:25 AM5/1/09
to
bohanson wrote:
> Ok I looked into it abit more and I came up with this. It uses WM_ERASEBKGND
> instead of WM_PAINT. When I tried using WM_PAINT, it then paints over the
> buttons aswell,

Because you don't use WM_PRINTCLIENT to draw the control in
double-buffering.

bohanson

unread,
May 1, 2009, 7:57:38 AM5/1/09
to

"Christian ASTOR" <cast...@club-internet.fr> wrote in message
news:49fabad7$0$293$7a62...@news.club-internet.fr...

//**********************************

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.


0 new messages