Firstly, thanks to you all who had in the time past guided me in my win32 programming.
right now, l need a help on owner drawn tab control.
l did the following code after creating the tab control with CreateWindowEx
Code. However, it worked fine when l didn't use the owner draw style but l don't like the default. l want to customize it.
NOTE: subject1 through subject6 are the indices of dropdown list combobox.
What l want to do is to first check if a user has made a selection. if yes, get the index, add a tab and set the tab title to the subject selected. but if no, do nothing - don't create tab.
case WM_DRAWITEM:
lpdis=(LPDRAWITEMSTRUCT) lParam;
TCITEM tie={0};
if(SubjectTabs==lpdis->hwndItem){//get handle of the tab control
if(SubjectTabs==NULL){
MessageBox(hWnd,L"Tab can not be created.",szTitle,0);
MessageBox(hWnd,L"Application closes",szTitle,0);
SendMessage(hWnd,WM_CLOSE,0,0);
break;
}
if(subject1){//if English is not selected, do the inner loop
MessageBox(hWnd,L"Problem with English Subject.",szTitle,0);
MessageBox(hWnd,L"Application closes",szTitle,0);
SendMessage(hWnd,WM_CLOSE,0,0);
break;
}
else{//
tie.mask = TCIF_TEXT;
tie.cchTextMax = 100;
tie.pszText=subject1tab;//sets tab name
SendMessage(SubjectTabs,TCM_INSERTITEM,(WPARAM)0,(LPARAM)&tie);//send message to add tab
FillRect(lpdis->hDC,&lpdis->rcItem,(HBRUSH)GetStockObject(WHITE_BRUSH));
SetBkColor(lpdis->hDC,RGB(255,255,255));
}
if(subject2<=0){//if subject 2 is not selected, do nothing
//do nothing and tab will not be added
}
else{
tie.mask = TCIF_TEXT;
tie.cchTextMax = 100;
tie.pszText=subject2tab;//sets tab name
SendMessage(SubjectTabs,TCM_INSERTITEM,(WPARAM)1,(LPARAM)&tie);//send message to add tab
FillRect(lpdis->hDC,&lpdis->rcItem,(HBRUSH)GetStockObject(WHITE_BRUSH));
SetBkColor(lpdis->hDC,RGB(255,255,255));
}
if(subject3<=0){//if subject 3 is not selected, do nothing
//do nothing and tab will not be added
}
else{
tie.mask = TCIF_TEXT;
tie.cchTextMax = 100;
tie.pszText=subject3tab;////
SendMessage(SubjectTabs,TCM_INSERTITEM,(WPARAM)2,(LPARAM)&tie);//send message to add tab
FillRect(lpdis->hDC,&lpdis->rcItem,(HBRUSH)GetStockObject(WHITE_BRUSH));
SetBkColor(lpdis->hDC,RGB(255,255,255));
}
if(subject4<=0){//if subject 4 is not selected, do nothing
//do nothing and tab will not be added
}
else{
tie.mask = TCIF_TEXT;
tie.cchTextMax = 100;
tie.pszText=subject4tab;////
SendMessage(SubjectTabs,TCM_INSERTITEM,(WPARAM)3,(LPARAM)&tie);//send message to add tab
FillRect(lpdis->hDC,&lpdis->rcItem,(HBRUSH)GetStockObject(WHITE_BRUSH));
SetBkColor(lpdis->hDC,RGB(255,255,255));
}
if(subject5<=0){//if subject 5 is not selected, do nothing
//do nothing and tab will not be added
}
else{
tie.mask = TCIF_TEXT;
tie.cchTextMax = 100;
tie.pszText=subject5tab;
SendMessage(SubjectTabs,TCM_INSERTITEM,(WPARAM)4,(LPARAM)&tie);//send message to add tab
FillRect(lpdis->hDC,&lpdis->rcItem,(HBRUSH)GetStockObject(WHITE_BRUSH));
SetBkColor(lpdis->hDC,RGB(255,255,255));
}
if(subject6<=0){//if subject 6 is not selected, do nothing
//do nothing and tab will not be added
}
else{
tie.mask = TCIF_TEXT;
tie.cchTextMax = 100;
tie.pszText=subject6tab;////
SendMessage(SubjectTabs,TCM_INSERTITEM,(WPARAM)5,(LPARAM)&tie);//send message to add tab
FillRect(lpdis->hDC,&lpdis->rcItem,(HBRUSH)GetStockObject(WHITE_BRUSH));
SetBkColor(lpdis->hDC,RGB(255,255,255));
}
}
break;
but l got the following error;
1>c:\users\chibu\documents\visual studio 2010\projects\unical ptume\unical ptume\unical ptume.cpp(349): error C2360: initialization of 'tie' is skipped by 'case' label
1> c:\users\chibu\documents\visual studio 2010\projects\unical ptume\unical ptume\unical ptume.cpp(261) : see declaration of 'tie'
1>c:\users\chibu\documents\visual studio 2010\projects\unical ptume\unical ptume\unical ptume.cpp(355): error C2361: initialization of 'tie' is skipped by 'default' label
1> c:\users\chibu\documents\visual studio 2010\projects\unical ptume\unical ptume\unical ptume.cpp(261) : see declaration of 'tie'
@Jaybobb6: It work - compiled. Thanks. Humm, but the tab control was not created. May be l didn't code it well. but any more light on it will be appreciated as there are no much tut on the subject on the net for me to refer to. l didn't much understand that of microsoft. https://support.microsoft.com/en-us/kb/179909
where SubjectTabs is a HWND type.
However, it now works cos l followed the tut on https://support.microsoft.com/en-us/kb/179909 but it doesn't look fine. The whole tab is the color l set and nothing to differentiate between tabs. l want it to be in a way, the tab(the title area where the user clicks to toggle between tabs) will have a blue colour while the display area will be white and again, the titles l set doesn't show but shows when l don't use the custom style. Please l need more help tut on it.
Thanks in advance.
PS: never mine the x,y,cy,cy coordinate, cos l used movewindow in wm_size to size them.
@thomas1965: Thanks alot - it worked. However, only the top part(the part where user clicks to toggle between tab) changed color. Is there a way to also change the color of the tab client area?
I still don't know what you want to do.
You mentioned book name/title, but what are they?
Maybe you can upload the project and the complete task and send me a PM.