-
[RESOLVED] Coloring header row of CListCtrl C++
I have class MyClistCtrl derived from CListCtrl. I want to do two things:
1. Show only horizontal grid lines (I tried LVS_EX_GRIDLINES ,but this displays both horizontal as well as Vertical grid lines)
2. Change background color of header row,it is of gray color(system color),i want it to be white.I read several post and codes but nothing helped so please if anyone from Scratch can tell me with Code how to achieve that
-
Re: Coloring header row of CListCtrl C++
Quote:
Originally Posted by
Beginner_MFC
I have class MyClistCtrl derived from CListCtrl. I want to do two things:
1. Show only horizontal grid lines (I tried LVS_EX_GRIDLINES ,but this displays both horizontal as well as Vertical grid lines)
But the Vertical grid lines are drawn by default. isn't it?
-
Re: Coloring header row of CListCtrl C++
Quote:
Originally Posted by
Beginner_MFC
... Change background color of header row,it is of gray color(system color),i want it to be white.I read several post and codes but nothing helped so please if anyone from Scratch can tell me with Code how to achieve that
Have a look at this thread.
-
Re: Coloring header row of CListCtrl C++
No no no..confusion.
You are right vertical grid lines are drawn by default but my requirement is i only want horizontal grid lines not both horizontal and vertical grid lines..
-
Re: Coloring header row of CListCtrl C++
Quote:
Originally Posted by
Beginner_MFC
... but my requirement is i only want horizontal grid lines not both horizontal and vertical grid lines..
You may want to create your own user defined control. :rolleyes:
-
Re: Coloring header row of CListCtrl C++
Means there is nothing like LVS_ something which can only draw horizontal gridlines,if so please can you help me with code snippet of user defined control you are talking about which can help me in achieving this.
-
Re: Coloring header row of CListCtrl C++
Quote:
Originally Posted by
Beginner_MFC
Means there is nothing like LVS_ something which can only draw horizontal gridlines,if so please can you help me with code snippet of user defined control you are talking about which can help me in achieving this.
Sorry! I never needed such a control... So try to google for that. :)
-
Re: Coloring header row of CListCtrl C++
I did googled but no success...nothing worth found
-
Re: Coloring header row of CListCtrl C++
Quote:
Originally Posted by
Beginner_MFC
I did googled but no success...nothing worth found
sorry... :sick:
-
Re: Coloring header row of CListCtrl C++
Can you please tell how and where WM_DRAWITEM should be called...and where is m_ HeaderCtrl declared?
-
Re: Coloring header row of CListCtrl C++
Quote:
Originally Posted by
Beginner_MFC
...and where is m_ HeaderCtrl declared?
See:
CListCtrl::GetHeaderCtrl
Header Control and List Control
-
Re: Coloring header row of CListCtrl C++
-
Re: Coloring header row of CListCtrl C++
And plz help me with correct code because i have read all this CListCtrl::GetHeaderCtrl and Header Control stuff but couldn't able to implement it in a successful way
That's why asking for urgent help
-
Re: Coloring header row of CListCtrl C++
Quote:
Originally Posted by
Beginner_MFC
And plz help me with correct code because i have read all this CListCtrl::GetHeaderCtrl and Header Control stuff but couldn't able to implement it in a successful way
That's why asking for urgent help
post your code
-
Re: Coloring header row of CListCtrl C++
class IEHeaderCtrl : public CHeaderCtrl { // Construction public: IEHeaderCtrl(); // Generated message map functions protected: afx_msg virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct);
DECLARE_MESSAGE_MAP()
}
Code for IEHeaderCtrl.cpp
BEGIN_MESSAGE_MAP(IEHeaderCtrl, CHeaderCtrl)
END_MESSAGE_MAP
void IEHeaderCtrl::
DawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) { HDITEM hdi; CBrush brush(RGB(255, 0, 0)); CString csBuffer; CRect rectFrame(lpDrawItemStruct->rcItem); ZeroMemory(&hdi, sizeof(HDITEM)); hdi.mask = HDI_TEXT; LPTSTR pBuf = csBuffer.GetBufferSetLength(MAX_PATH); hdi.mask = HDI_TEXT; hdi.pszText = pBuf; hdi.cchTextMax = MAX_PATH; GetItem(lpDrawItemStruct->itemID, &hdi); csBuffer.ReleaseBuffer(); CDC *pDC = CDC::FromHandle(lpDrawItemStruct->hDC); pDC->FillRect(rectFrame, &brush); pDC->SetTextColor(RGB(255, 255, 255)); pDC->SetBkMode(TRANSPARENT); pDC->DrawText(csBuffer, &lpDrawItemStruct->rcItem, DT_LEFT | DT_SINGLELINE | DT_VCENTER); brush.Detach();
}
/*code for Myformview.cpp where my listctrl is embedded:*/
void MyFormView :: OnInitiUpdate()
{
IEHeaderCtrl m_HeaderCtrl;
CHeaderCtrl* pHeader = NULL; pHeader=m_List.GetHeaderCtrl(); VERIFY(m_HeaderCtrl.SubclassWindow(pHeader->m_hWnd)); HDITEM hdItem; hdItem.mask = HDI_FORMAT;
}
-
Re: Coloring header row of CListCtrl C++
Quote:
Originally Posted by
Beginner_MFC
class IEHeaderCtrl : public CHeaderCtrl { // Construction public: IEHeaderCtrl(); // Generated message map functions protected: afx_msg virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct);
DECLARE_MESSAGE_MAP()
}
Code for IEHeaderCtrl.cpp
BEGIN_MESSAGE_MAP(IEHeaderCtrl, CHeaderCtrl)
END_MESSAGE_MAP
void IEHeaderCtrl::
DawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) { HDITEM hdi; CBrush brush(RGB(255, 0, 0)); CString csBuffer; CRect rectFrame(lpDrawItemStruct->rcItem); ZeroMemory(&hdi, sizeof(HDITEM)); hdi.mask = HDI_TEXT; LPTSTR pBuf = csBuffer.GetBufferSetLength(MAX_PATH); hdi.mask = HDI_TEXT; hdi.pszText = pBuf; hdi.cchTextMax = MAX_PATH; GetItem(lpDrawItemStruct->itemID, &hdi); csBuffer.ReleaseBuffer(); CDC *pDC = CDC::FromHandle(lpDrawItemStruct->hDC); pDC->FillRect(rectFrame, &brush); pDC->SetTextColor(RGB(255, 255, 255)); pDC->SetBkMode(TRANSPARENT); pDC->DrawText(csBuffer, &lpDrawItemStruct->rcItem, DT_LEFT | DT_SINGLELINE | DT_VCENTER); brush.Detach();
}
/*code for Myformview.cpp where my listctrl is embedded:*/
void MyFormView :: OnInitiUpdate()
{
IEHeaderCtrl m_HeaderCtrl;
CHeaderCtrl* pHeader = NULL; pHeader=m_List.GetHeaderCtrl(); VERIFY(m_HeaderCtrl.SubclassWindow(pHeader->m_hWnd)); HDITEM hdItem; hdItem.mask = HDI_FORMAT;
}
Can you read what you have posted?
I can't. :eek::sick:
Please, post good readable, formatted code snippet. Use Code tags.
-
Re: Coloring header row of CListCtrl C++
Code:
class IEHeaderCtrl : public CHeaderCtrl
{
public:
IEHeaderCtrl();
protected:
afx_msg virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct);
DECLARE_MESSAGE_MAP()
}
Code for IEHeaderCtrl.cpp
Code:
BEGIN_MESSAGE_MAP(IEHeaderCtrl, CHeaderCtrl)
END_MESSAGE_MAP
void IEHeaderCtrl::DawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
HDITEM hdi;
CBrush brush(RGB(255, 0, 0));
CString csBuffer;
CRect rectFrame(lpDrawItemStruct->rcItem);
ZeroMemory(&hdi, sizeof(HDITEM));
hdi.mask = HDI_TEXT;
LPTSTR pBuf= csBuffer.GetBufferSetLength(MAX_PATH);
hdi.mask = HDI_TEXT;
hdi.pszText = pBuf;
hdi.cchTextMax = MAX_PATH;
GetItem(lpDrawItemStruct->itemID, &hdi);
csBuffer.ReleaseBuffer();
CDC *pDC = CDC::FromHandle(lpDrawItemStruct->hDC);
pDC->FillRect(rectFrame, &brush);
pDC->SetTextColor(RGB(255, 255, 255));
pDC->SetBkMode(TRANSPARENT);
pDC->DrawText(csBuffer, &lpDrawItemStruct->rcItem, DT_LEFT | DT_SINGLELINE | DT_VCENTER);
brush.Detach();
}
code for Myformview.cpp where my listctrl is embedded:
Code:
void MyFormView :: OnInitiUpdate()
{
IEHeaderCtrl m_HeaderCtrl;
CHeaderCtrl* pHeader = NULL;
pHeader=m_List.GetHeaderCtrl();
VERIFY(m_HeaderCtrl.SubclassWindow(pHeader->m_hWnd));
HDITEM hdItem;
hdItem.mask = HDI_FORMAT;
}
-
Re: Coloring header row of CListCtrl C++
Quote:
Originally Posted by
Beginner_MFC
Code:
class IEHeaderCtrl : public CHeaderCtrl
{
public: IEHeaderCtrl();
protected: afx_msg virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct);
DECLARE_MESSAGE_MAP()
}
Code for IEHeaderCtrl.cpp
Code:
BEGIN_MESSAGE_MAP(IEHeaderCtrl, CHeaderCtrl)
END_MESSAGE_MAP
void IEHeaderCtrl::
DawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
HDITEM hdi;
CBrush brush(RGB(255, 0, 0));
CString csBuffer;
CRect rectFrame(lpDrawItemStruct->rcItem); ZeroMemory(&hdi, sizeof(HDITEM));
hdi.mask = HDI_TEXT;
LPTSTR pBuf= csBuffer.GetBufferSetLength(MAX_PATH);
hdi.mask = HDI_TEXT;
hdi.pszText = pBuf;
hdi.cchTextMax = MAX_PATH; GetItem(lpDrawItemStruct->itemID, &hdi); csBuffer.ReleaseBuffer();
CDC *pDC = CDC::FromHandle(lpDrawItemStruct->hDC);
pDC->FillRect(rectFrame, &brush);
pDC->SetTextColor(RGB(255, 255, 255));
pDC->SetBkMode(TRANSPARENT);
pDC->DrawText(csBuffer, &lpDrawItemStruct->rcItem, DT_LEFT | DT_SINGLELINE | DT_VCENTER); brush.Detach();
}
Please, post your real code that compiles! not just a pseudo code.
And use the proper code indentations!
-
Re: Coloring header row of CListCtrl C++
This is a real code and compiling at my end..
-
Re: Coloring header row of CListCtrl C++
Quote:
Originally Posted by
Beginner_MFC
This is a real code and compiling at my end..
Then where and how is this method
Code:
void IEHeaderCtrl::
DawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
declared?
-
Re: Coloring header row of CListCtrl C++
See this, although already posted above..
Code:
class IEHeaderCtrl : public CHeaderCtrl
{
public:
IEHeaderCtrl();
protected:
afx_msg virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct);
DECLARE_MESSAGE_MAP()
}
-
Re: Coloring header row of CListCtrl C++
Quote:
Originally Posted by
Beginner_MFC
See this, although already posted above..
Code:
class IEHeaderCtrl : public CHeaderCtrl
{
public: IEHeaderCtrl();
protected:
afx_msg virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct);
DECLARE_MESSAGE_MAP()
}
Well, there is
Code:
...
afx_msg virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct);
...
, not the
Code:
DawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
-
Re: Coloring header row of CListCtrl C++
Not getting what else you want.see the code below(already posted) which is having definition of DrawItem
Code:
BEGIN_MESSAGE_MAP(IEHeaderCtrl, CHeaderCtrl)
END_MESSAGE_MAP
void IEHeaderCtrl::DawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
HDITEM hdi;
CBrush brush(RGB(255, 0, 0));
CString csBuffer;
CRect rectFrame(lpDrawItemStruct->rcItem);
ZeroMemory(&hdi, sizeof(HDITEM));
hdi.mask = HDI_TEXT;
LPTSTR pBuf= csBuffer.GetBufferSetLength(MAX_PATH);
hdi.mask = HDI_TEXT;
hdi.pszText = pBuf;
hdi.cchTextMax = MAX_PATH;
GetItem(lpDrawItemStruct->itemID, &hdi);
csBuffer.ReleaseBuffer();
CDC *pDC = CDC::FromHandle(lpDrawItemStruct->hDC);
pDC->FillRect(rectFrame, &brush);
pDC->SetTextColor(RGB(255, 255, 255));
pDC->SetBkMode(TRANSPARENT);
pDC->DrawText(csBuffer, &lpDrawItemStruct->rcItem, DT_LEFT | DT_SINGLELINE | DT_VCENTER);
brush.Detach();
}
-
Re: Coloring header row of CListCtrl C++
Quote:
Originally Posted by
Beginner_MFC
Not getting what else you want.see the code below(already posted) which is having definition of DrawItem
Code:
BEGIN_MESSAGE_MAP(IEHeaderCtrl, CHeaderCtrl)
END_MESSAGE_MAP
void IEHeaderCtrl::
DawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
...
}
There is no "definition of DrawItem".
There is a definition of DawItem. :rolleyes:
-
Re: Coloring header row of CListCtrl C++
Oohhh Victor.i spelled it wrong here but at my wnd its DrawItem only
.Sorry ,plz assume it as DrawItem and tell the solution
-
Re: Coloring header row of CListCtrl C++
Quote:
Originally Posted by
Beginner_MFC
Oohhh Victor.i spelled it wrong here but at my wnd its DrawItem only
.Sorry ,plz assume it as DrawItem and tell the solution
Again: post your real code.
Why don't you want just copy/paste the code from your IDE?
Why do you ignore code indentation (or you remove it before sending a post?)
-
Re: Coloring header row of CListCtrl C++
Code tags and formatting please. That mess is unreadable.
-
Re: Coloring header row of CListCtrl C++
Quote:
Originally Posted by
GCDEF
Code tags and formatting please. That mess is unreadable.
:thumb: [Code formatted]
-
Re: Coloring header row of CListCtrl C++
Quote:
Originally Posted by
Beginner_MFC
Not getting what else you want.see the code below(already posted) which is having definition of DrawItem
Code:
BEGIN_MESSAGE_MAP(IEHeaderCtrl, CHeaderCtrl)
END_MESSAGE_MAP
void IEHeaderCtrl::DawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
HDITEM hdi;
CBrush brush(RGB(255, 0, 0));
CString csBuffer;
CRect rectFrame(lpDrawItemStruct->rcItem);
ZeroMemory(&hdi, sizeof(HDITEM));
hdi.mask = HDI_TEXT;
LPTSTR pBuf= csBuffer.GetBufferSetLength(MAX_PATH);
hdi.mask = HDI_TEXT;
hdi.pszText = pBuf;
hdi.cchTextMax = MAX_PATH;
GetItem(lpDrawItemStruct->itemID, &hdi);
csBuffer.ReleaseBuffer();
CDC *pDC = CDC::FromHandle(lpDrawItemStruct->hDC);
pDC->FillRect(rectFrame, &brush);
pDC->SetTextColor(RGB(255, 255, 255));
pDC->SetBkMode(TRANSPARENT);
pDC->DrawText(csBuffer, &lpDrawItemStruct->rcItem, DT_LEFT | DT_SINGLELINE | DT_VCENTER);
brush.Detach();
}
Did you debug your code? Is this DawItem (or DrawItem) called?
And BTW, do you set the ownerdraw flag to the header control items? See the Owner-Drawn Header Controls section in MSDN
-
Re: Coloring header row of CListCtrl C++
-
Re: Coloring header row of CListCtrl C++
Quote:
Originally Posted by
Beginner_MFC
Resolved..Thankyou
Could you share your solution?
-
Re: Coloring header row of CListCtrl C++
Derive your own class from CListCtrl.
Derive your own class from CHeaderCtrl.
Replace the standard CListCtrl header with yours.
Use custom drawing for the header control.
In derived CListCtrl
Code:
void MyListCtrl::PreSubclassWindow()
{
// TODO: Add your specialized code here and/or call the base class
CHeaderCtrl* pHeader = NULL;
pHeader = GetHeaderCtrl();
if (pHeader != NULL)
{
VERIFY(m_HeaderCtrl.SubclassWindow(pHeader->m_hWnd)); // m_HeaderCtrl is the new wrapper object
}
CListCtrl::PreSubclassWindow();
}
In the headerCtrl class
Code:
void MyHeader::OnNMCustomdraw(NMHDR *pNMHDR, LRESULT *pResult)
{
LPNMCUSTOMDRAW pNMCD = reinterpret_cast<LPNMCUSTOMDRAW>(pNMHDR);
// TODO: Add your control notification handler code here
*pResult = CDRF_DODEFAULT;
if (pNMCD->dwDrawStage == CDDS_PREPAINT)
{
CDC* pDC = CDC::FromHandle(pNMCD->hdc);
CRect rect(0, 0, 0, 0);
GetClientRect(&rect);
pDC->FillSolidRect(&rect, RGB(255, 0, 0));
*pResult = CDRF_NOTIFYITEMDRAW;
}
else if (pNMCD->dwDrawStage == CDDS_ITEMPREPAINT)
{
HDITEM hditem;
TCHAR buffer[MAX_PATH] = { 0 };
SecureZeroMemory(&hditem, sizeof(HDITEM));
hditem.mask = HDI_TEXT;
hditem.pszText = buffer;
hditem.cchTextMax = MAX_PATH;
GetItem(pNMCD->dwItemSpec, &hditem);
CDC* pDC = CDC::FromHandle(pNMCD->hdc);
pDC->SetTextColor(RGB(0, 0, 0));
pDC->SetBkColor(RGB(255, 0, 0));
CString str(buffer);
pDC->DrawText(str, CRect(pNMCD->rc), DT_VCENTER | DT_LEFT);
*pResult = CDRF_SKIPDEFAULT;
}
}
-
Changing color of Button in ZApp
Has anyone worked upon ZApp(third party),if yes than plz tell how to change the color of button in a dialog of ZApp.