06-01-2010, 03:53 AM
I cant find the example Macro like this,any suggeations? :?:
how to change header color of ListView?
|
06-01-2010, 03:53 AM
I cant find the example Macro like this,any suggeations? :?:
06-01-2010, 05:16 AM
Is it listview control in your dialog?
If yes, use custom drawing. I did not try it but I think it's possible. If not, you cannot change color.
06-01-2010, 11:36 AM
google and found this:
http://windowsmobiledn.com/qa-how-can-i ... t-control/ QA: How can I change the background color of the header of a List Control? January 26th, 2005 by Joao Paulo Figueira Question How can I change the background color of the header of a List Control? Answer There are two answers for this question: 1 – The window background color is changed by overriding the WM_ERASEBKGND message processing and painting the background with the chosen color (yellow on the picture). 2 – The item background color is changed by using the custom draw service (red and blue items on the picture). So, how does one go about it? You have to specialize the CListCtrl’s embedded CHeaderCtrl. The sample application shows how this can be done through two specialized classes CColorListCtrl and CColorHeaderCtrl. The list holds an instance of the header which is subclassed when the list is created (or subclassed): // CColorListCtrl::SubclassHeader // // Subclasses the header control, if any // The return value is used for OnCreate // int CColorListCtrl::SubclassHeader() { CHeaderCtrl* pHeader; int nRval = 0; // // Subclass the header control // pHeader = GetHeaderCtrl(); if(pHeader && pHeader->GetSafeHwnd()) { if(!m_hdr.SubclassWindow(pHeader->GetSafeHwnd())) nRval = -1; } return nRval; } There is nothing more to say about CColorListCtrl (by the way, the header control can be subclassed “outside” the list control: we use this here for convenience). Now, let’s see what the CColorHeaderCtrl is doing. First, the window backgroung painting code: // CColorHeaderCtrl::OnEraseBkgnd // // This is where we specify the background color of the header // BOOL CColorHeaderCtrl::OnEraseBkgnd(CDC* pDC) { CRect rc; GetClientRect(&rc); pDC->FillSolidRect(&rc, RGB(255, 255, 0)); // Yellow return TRUE; } As you can see, it is very simple: it just paints the client area with yellow. The item painting code is a bit more tricky because it uses the custom draw service. This service interacts with the window through a message exchange mechanism. It uses the NM_CUSTOMDRAW notification message (reflected here) to tell the window in what stage the drawing process is (we handle CDDS_PREPAINT and CDDS_ITEMPREPAINT) and to request it to override the desired settings. Here, we only change the text and background colors according to the item number: // CColorHeaderCtrl::OnCustomDraw // // Handles custom draw // void CColorHeaderCtrl::OnCustomDraw(NMHDR* pNMHDR, LRESULT* pResult) { NMCUSTOMDRAW* pCD = (NMCUSTOMDRAW*)pNMHDR; DWORD dwDrawStage, dwItemSpec; *pResult = CDRF_DODEFAULT; dwDrawStage = pCD->dwDrawStage; dwItemSpec = pCD->dwItemSpec; if(dwDrawStage == CDDS_PREPAINT) { *pResult = CDRF_NOTIFYITEMDRAW; } else if(dwDrawStage == CDDS_ITEMPREPAINT) { HDC hDC = pCD->hdc; SetTextColor(hDC, RGB(255, 255, 255)); if(dwItemSpec) SetBkColor(hDC, RGB( 0, 0, 255)); // Blue else SetBkColor(hDC, RGB( 255, 0, 0)); // Red *pResult = CDRF_NEWFONT; } } It works like this: First, the service tells us that it is about to paint the header (CDDS_PREPAINT). We reply saying that we want to be notified for the painting of each item (CDRF_NOTIFYITEMDRAW). Next, the service tells us that it is about to paint an item (CDDS_ITEMPREPAINT). We change the appropriate colors on the DC and reply saying that we did so (CDRF_NEWFONT). Note that we could even have changed the font, specifying a different one per item. For all the other states we don’t care about, we tell the service to do the default painting (CDRF_DODEFAULT). And that’s it. Sample You can download the sample project from here – ListColor.zip (182K).
06-01-2010, 11:53 AM
and found a example: :lol: :lol: :lol:
messages3 NMHDR* nh=+lParam sel nh.idFrom case 3 ;;list sel nh.code case NM_CUSTOMDRAW NMLVCUSTOMDRAW* cd=+nh sel cd.nmcd.dwDrawStage case CDDS_PREPAINT ret DT_Ret(hDlg CDRF_NOTIFYITEMDRAW) case CDDS_ITEMPREPAINT cd.clrTextBk=iif(cd.nmcd.lItemlParam 0xffff iif(cd.nmcd.dwItemSpec&1 0xF8F8F8 0xFFFFFF))
06-01-2010, 12:26 PM
Function dlg_header_custom_draw
\Dialog_Editor
06-01-2010, 01:29 PM
it works very well,thanks a lot! :lol: :lol: :lol:
|
« Next Oldest | Next Newest »
|