WM_DRAWITEM does not process for tab control
-
I am using a tab control. I want to change the background colour of the tab control. I selected the ownerdrawfixed in the properties of the tab control. but still the execution does not come to OnDrawItem function S.Yamini
-
I am using a tab control. I want to change the background colour of the tab control. I selected the ownerdrawfixed in the properties of the tab control. but still the execution does not come to OnDrawItem function S.Yamini
What are you trying to do it?
Greetings. -------- M.D.V. ;) If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about? Help me to understand what I'm saying, and I'll explain it better to you “The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson
-
I am using a tab control. I want to change the background colour of the tab control. I selected the ownerdrawfixed in the properties of the tab control. but still the execution does not come to OnDrawItem function S.Yamini
Where are you handling WM_DRAWITEM? What about overriding CTabCtrl::DrawItem() in your tab control class? Mark
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
What are you trying to do it?
Greetings. -------- M.D.V. ;) If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about? Help me to understand what I'm saying, and I'll explain it better to you “The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson
I am trying to change the background colour of the tab control. I will be able to it in drawitem method but the execution does not come to draw item method even if i select ownerdrawfixed in the properties of the tab control.
-
Where are you handling WM_DRAWITEM? What about overriding CTabCtrl::DrawItem() in your tab control class? Mark
Mark Salsbery Microsoft MVP - Visual C++ :java:
The execution does not come to drawitem method. Why
-
The execution does not come to drawitem method. Why
The following code works for me... Note you have to have a tab control subclassed by an object of your CTabCtrl-derived class, otherwise DrawItem() will never get called...
class CMyTabCtrl : public CTabCtrl
{
public:
CMyTabCtrl() : CTabCtrl() {}virtual void DrawItem(LPDRAWITEMSTRUCT /\*lpDrawItemStruct\*/);
};
void CMyTabCtrl::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
CDC dc;
dc.Attach(lpDrawItemStruct->hDC);// Note: My test tab control has two tabs inserted :) if (0 == lpDrawItemStruct->itemID) dc.DrawText(\_T("Tab 1"), &lpDrawItemStruct->rcItem, DT\_CENTER); else dc.DrawText(\_T("Tab 2"), &lpDrawItemStruct->rcItem, DT\_CENTER); dc.Detach();
}
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
The following code works for me... Note you have to have a tab control subclassed by an object of your CTabCtrl-derived class, otherwise DrawItem() will never get called...
class CMyTabCtrl : public CTabCtrl
{
public:
CMyTabCtrl() : CTabCtrl() {}virtual void DrawItem(LPDRAWITEMSTRUCT /\*lpDrawItemStruct\*/);
};
void CMyTabCtrl::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
CDC dc;
dc.Attach(lpDrawItemStruct->hDC);// Note: My test tab control has two tabs inserted :) if (0 == lpDrawItemStruct->itemID) dc.DrawText(\_T("Tab 1"), &lpDrawItemStruct->rcItem, DT\_CENTER); else dc.DrawText(\_T("Tab 2"), &lpDrawItemStruct->rcItem, DT\_CENTER); dc.Detach();
}
Mark Salsbery Microsoft MVP - Visual C++ :java:
Thanks for ur help I created a dialog based application. I selected a tab control and moved to my dialog . I have created an MFC class named CMyTabCtrl derived from CTabCtrl. I added ur code to it. I created a member variable in the dialog class for the tab control using class wizard which is CMyTabCtrl m_Tab I have selected the owner draw fixed properties But still the drawitem of CMyTabCtrl does not called. Please implement this and if u r getting let me know what u did.
-
Thanks for ur help I created a dialog based application. I selected a tab control and moved to my dialog . I have created an MFC class named CMyTabCtrl derived from CTabCtrl. I added ur code to it. I created a member variable in the dialog class for the tab control using class wizard which is CMyTabCtrl m_Tab I have selected the owner draw fixed properties But still the drawitem of CMyTabCtrl does not called. Please implement this and if u r getting let me know what u did.
I did the same - I used a DDX_Control() call in DoDataExchange() to subclass the control...
void CMyDialog::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDC_TAB1, m_Tab); <-- make sure you use the right ID!!!
}Mark Salsbery Microsoft MVP - Visual C++ :java:
-
I did the same - I used a DDX_Control() call in DoDataExchange() to subclass the control...
void CMyDialog::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDC_TAB1, m_Tab); <-- make sure you use the right ID!!!
}Mark Salsbery Microsoft MVP - Visual C++ :java:
I have done that. But still does not work Can u send me ur sample project.
-
I have done that. But still does not work Can u send me ur sample project.
It's a VS2008 project - is that OK?
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
It's a VS2008 project - is that OK?
Mark Salsbery Microsoft MVP - Visual C++ :java:
ok
-
The following code works for me... Note you have to have a tab control subclassed by an object of your CTabCtrl-derived class, otherwise DrawItem() will never get called...
class CMyTabCtrl : public CTabCtrl
{
public:
CMyTabCtrl() : CTabCtrl() {}virtual void DrawItem(LPDRAWITEMSTRUCT /\*lpDrawItemStruct\*/);
};
void CMyTabCtrl::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
CDC dc;
dc.Attach(lpDrawItemStruct->hDC);// Note: My test tab control has two tabs inserted :) if (0 == lpDrawItemStruct->itemID) dc.DrawText(\_T("Tab 1"), &lpDrawItemStruct->rcItem, DT\_CENTER); else dc.DrawText(\_T("Tab 2"), &lpDrawItemStruct->rcItem, DT\_CENTER); dc.Detach();
}
Mark Salsbery Microsoft MVP - Visual C++ :java:
Am I doing anything wrong in setting the properties of the tab control. Shall I send the sample code.
-
Am I doing anything wrong in setting the properties of the tab control. Shall I send the sample code.
It seems like you're doing everything.... Send me an email from here and I'll reply with the project. Mark
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
It seems like you're doing everything.... Send me an email from here and I'll reply with the project. Mark
Mark Salsbery Microsoft MVP - Visual C++ :java:
I am waiting for ur reply
-
It seems like you're doing everything.... Send me an email from here and I'll reply with the project. Mark
Mark Salsbery Microsoft MVP - Visual C++ :java:
It works now when i call insert item Thanks
-
It works now when i call insert item Thanks
Ohhh you had no tabs :) I guess the email through CodeProject isn't working yet....I sent one so I could get your address to send the project. Glad you got it working! Mark
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
Ohhh you had no tabs :) I guess the email through CodeProject isn't working yet....I sent one so I could get your address to send the project. Glad you got it working! Mark
Mark Salsbery Microsoft MVP - Visual C++ :java:
Thanks for ur support
-
Thanks for ur support
You're welcome!
Mark Salsbery Microsoft MVP - Visual C++ :java: