NM_CUSTOMDRAW and CListCtrl

Forgive me if this is a duplicate post. I'm using a CListCtrl with
LVS_OWNERDATA and using NM_CUSTOMDRAW to draw the items myself, rather than
letting windows do it -- however, this is quite slow. How does windows do it
so fast, and why is my code so slow? Keep in mind that becuase of the
LVS_OWNERDATA style, NM_CUSTOMDRAW is only fired once per item, not once per
sub item, so when I get the event, I have to draw the entire row at one
time. Heres the code:

void CMusikPlaylistCtrl::OnLvnGetdispinfo(NMHDR *pNMHDR, LRESULT *pResult)
{
     NMLVDISPINFO *pDispInfo = reinterpret_cast<NMLVDISPINFO*>(pNMHDR);

     // items are drawn manually

     *pResult = 0;
}

void CMusikPlaylistCtrl::OnNMCustomdraw(NMHDR *pNMHDR, LRESULT *pResult)
{
     NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>( pNMHDR );

     *pResult = CDRF_DODEFAULT;

     if ( CDDS_PREPAINT == pLVCD->nmcd.dwDrawStage )
         *pResult = CDRF_NOTIFYITEMDRAW;

     else if ( CDDS_ITEMPREPAINT == pLVCD->nmcd.dwDrawStage )
     {
            int iRow = (int)pLVCD->nmcd.dwItemSpec;

            CDC* pDC = CDC::FromHandle(pLVCD->nmcd.hdc);
            CRect item_rect;
            GetItemRect( iRow, &item_rect, LVIR_BOUNDS );

            DrawItem( pDC, iRow, item_rect );    // draw the item [see
below]

            *pResult = CDRF_SKIPDEFAULT;
    }

    else if( pLVCD->nmcd.dwDrawStage == CDDS_ITEMPOSTPAINT )
        *pResult = CDRF_DODEFAULT;
}

void CMusikPlaylistCtrl::DrawItem( CDC* pDC, int item, const CRect& rect )
{
    CMemDC dc( pDC, &rect );

    // setup the font and highlight colors
    COLORREF bg = GetSysColor( COLOR_BTNHILIGHT );
    COLORREF text = GetSysColor( COLOR_WINDOWTEXT );

    // color each sub item
    CRect rcSubItem;
    dc.SetTextColor( text );

    for ( size_t i = 0; i < m_Prefs->GetPlaylistColCount(); i++ )
    {
         GetSubItemRect( item, i, LVIR_BOUNDS, rcSubItem );

        dc.FillSolidRect( &rcSubItem, bg );
        dc.TextOut( rcSubItem.left + 6, rcSubItem.top, _T( "Test" ) );
    }
}

Any help or advice as to why this is so slow would be much appreciated.
Thanks :)

Casey Langen


0
casey678 (6)
10/30/2003 7:49:13 PM
vc.mfc 33608 articles. 0 followers. Follow

0 Replies
1622 Views

Similar Articles

[PageSpeed] 22

Reply:

Similar Artilces:

CListCtrl questions
Hi, I am developping on Pocket pc and smartphone and I have a few questions about CListCtrl in report mode. First how can I know how many items I can display without having a vertical scrollbar? On smartphone we are using keypad to move, so first time when I press down key, the curent selection doesn't move.It's only the second time I press the key that is starts to move. First I thought it was a focus problem but even with the focus, it still the same. I also tried to select the first line first with a setitemstate but same result.any idea ? Last question is once a clistctrl h...

SetItemHeight in CListCtrl
Is there a way for me to set the height of all the items in a CListCtrl? I am trying to overlay one of the columns in an item with a CComboxBox and the minimum height in the comboBox appears to be greater than the height of the item in the CListCtrl. Brian Westcott wrote: > Is there a way for me to set the height of all the items in a CListCtrl? I > am trying to overlay one of the columns in an item with a CComboxBox and the > minimum height in the comboBox appears to be greater than the height of the > item in the CListCtrl. > > You have to create OWNERDRAW CLi...

CListCtrl
I have used LVS_EX_CHECKBOXES extended style for my CListCtrl. Do Parent Window/Dialog receive any notification message when user set/reset the checkbox. I tried to use NM_CLICK , but checkbox value is changed after this notification is processed. ...

Displaying JPEG images in CListCtrl
Hi All, I am writing an application in which I want to display a set of JPEG images into a CListCtrl. Is there a way of doing this by using just MFC? Awaiting for your reply Thanks & Regards Sachin Bhave > I am writing an application in which I want to display a set of JPEG > images into a CListCtrl. Is there a way of doing this by using just MFC? Try codeguru/codeproject for something like this. Here is one that should get you started: http://www.codeproject.com/listctrl/thumbnailview.asp --- Ajay ...

CListCtrl
Hi, Does anybody know an easy of removing the black vertical tracking line that appears while resizing columns? I've been trying to prevent it through HDN_ENDTRACK / HDN_TRACK, but I wasn't successfull. Is there a specific flag that I can set to disable it instead? Thanks in advance for your time, Best regards, -Onur I can't imagine why you'd want to do that, but here's my suggestion: Override the CListrCtrl and CHeaderCtrl class, and have your listview control use your derived header control. In the header control class, handle the WM_SETCURSOR message and load a d...

Mouse scroll wheel does not work under Windows XP in CListCtrl
I am using my own List-Controls which are using CListCtrl as base. In this Controls the mouse scroll wheel does not work under Windows XP. Is there any parameter which should be set? Best regards rolf brockmann On Tue, 23 May 2006 02:51:01 -0700, rolfb <rolfb@discussions.microsoft.com> wrote: >I am using my own List-Controls which are using CListCtrl as base. >In this Controls the mouse scroll wheel does not work under Windows XP. >Is there any parameter which should be set? It ought to just work. If you are using Intellipoint, note that later versions of Intellipoint requir...

Unable to fetch CListCtrl header information(Header title)
Hi, I am trying to fetch header information(header title) of CListCtrl using GetColumn function. GetColumn function is not populating the LVCOLUMN structure. I am running my code in release mode on Win2k and Win2k3 clients. I have also attached the code snippet that I'm using.. Please let me know what is worng here.. Thanks.. code snippet : int ColumnCount = m_ListCtrl.GetHeaderCtrl()->GetItemCount(); LVCOLUMN col; col.mask = LVCF_TEXT; col.pszText = new(char[50]); TmpText = ""; for (int j=0; j< ColumnCount; j++) { m_ListCtrl.GetColumn(j, &col); TmpTe...

How to know if a CListCtrl item is selected or not?
I use Visual C++ 4.2 Professional. I use the CListCtrl to display all data. I don't create the CListCtrl dynamically but from design form where I drag it onto the form. When user click a button, it will get the selected items and get the item data pointer. So I must check if the item has been selected or not. How to find out if the item has been selected or not when I click the button? Thank you very much. >So I must check if the item has been selected or not. >How to find out if the item has been selected or not when I click the button? Use GetNextItem to find items tha...

Help w/CListCtrl's NM_CUSTOMDRAW
How can you set the row height? I can do all sorts of things with this feature accept set the row height. http://www.codeguru.com/listview/change_row_height.shtml <anonymous@discussions.microsoft.com> wrote in message news:06dd01c39927$86a15480$a401280a@phx.gbl... > How can you set the row height? I can do all sorts of > things with this feature accept set the row height. ...

CListView and CListCtrl
Does the CListCtrl as used in a dialog box work exactly the same as in CListView? I have a CListCtrl in a CListView and it works perfectly. In my CListCtrl in my dialog box I have to comment out the following line in order to run my OnGetDispinfo() lvi.pszText = LPSTR_TEXTCALLBACK Yet I need it in my CListView to display my data. ...

ActiveX and NM_CUSTOMDRAW
I have an ATL Composite Control (DLL) that that includes my own control (CMySlider) derived from CSliderCtrl. Here is the message map of this control. BEGIN_MESSAGE_MAP(CMySlider, CSliderCtrl) //{{AFX_MSG_MAP(CPlayerSlider) ON_NOTIFY_REFLECT(NM_CUSTOMDRAW, OnCustomdraw) //}}AFX_MSG_MAP END_MESSAGE_MAP() When Composite Control is embedded in the Dialog or FormView, CMyControl receives notification, OnCustomdraw gets called and everything draws/works perfectly. The problem is that when the Composite Control is embedded in HTML page, I’m not receiving notification at all and instead of ...

Problems with GetItemData in CListCtrl
Hi. I'm having problems with CListCtrl GetItemData - it always returns 0. We're talking about a modal dialog - in which values to the items are set using SetItemData in the OnInitDialog method. Checking for the values anywhere (after SetData of course) in OnInitDialog returns the correct values. When trying to GetItemData in OnOK - i always get 0. Item index is correct, since if i try to GetItemText - i get the correct text, only the data is 0. here is some code : the SetItemData in InitDialog: for(int i = 0; i < arrEntities.GetCount(); ++i) // Iterate objects { CMyObject elemen...

CTreeCtrl & CListCtrl
Hi, Its the same question that I've seen in the archives but the solution I found was an outdated one. I would like to use a tree object as the member of a list control. What are my options? Appreciate your help. Thanks. -KK This one still works. http://www.codeproject.com/treectrl/treelist.asp I use this: http://www.codejock.com/products/reportcontrol/ But it comes with a suite that you have to pay for... Tom <pedagani@gmail.com> wrote in message news:1132686291.665005.4680@o13g2000cwo.googlegroups.com... > Hi, Its the same question that I've seen in the archives but...

how to remove all selected items from CListCtrl
Hi what is wrong with following code: POSITION pos = m_wndList.GetFirtsSelectedItem(); if (NULL == pos) return; int selected_item; while(pos) { selected_item = m_wndList.GetNextSelectedItem(pos); m_wndList.DeleteItem(selected_item); } no all selected items are removed:( how to solve this problem. Regards, Robert In article <#TOnnofpEHA.1712@tk2msftngp13.phx.gbl>, "RobertK" <sftech@interia.pl> wrote: > what is wrong with following code: > > POSITION pos = m_wndList.GetFirtsSelectedItem(); > > if (NULL == pos) > return; > &...

Icons centered in a ClistCtrl (HORZ & VERT)
Hi, I have a docking bar with a ClistCtrl (using icons) on the left. I would like to know how I can have icons centered even when I resize my docking bar. Same question for an horizontal CListCtrl icons list. For now I only have one item and it's on the left while I would like it to on the middle. Try m_ListCtrl.SetWindowPos() ; (CListCtrl m_ListCTrl) to change the list ctrl position when you resize your doking bar. ...

CListCtrl in Help About Dialog Box
Hi. I’ve used a CListCtrl before in my FormView, but I haven’t used it in a Help About dialog before and I’m having trouble. MyApp.cpp has code something like this: Void CMyApp::OnAppAbout() { CAboutDlg aboutDlg; aboutDlg.m_myListCtrl.InsertColumn(0, “Name”, LVCFMT_LEFT); } I get the assert in the call to InsertColumn(). It’s in the return statement in InsertColumn() where the assert occurs (in afxcmn.inl). Any idea? Thanks. That's because the list control hasn't been created yet (because the dialog box hasn't been created yet). So you have 2 choices. One is to ...

NM_CUSTOMDRAW and LVS_OWNERDATA
Hi all, I have a question: I am using a virtual list control (LVS_OWNERDATA), and trying to handle the NM_CUSTOMDRAW message to draw something custom in one of the columns -- problem is, the NM_CUSTOMDRAW message only gets fired once for each item, rather than once for each column. Anyone know how to work around this? Thanks :) Casey This is normal behavior, you will need to draw the entire row when processing the NM_CUSTOMDRAW message. -- ============ Frank Hickman NobleSoft, Inc. ============ "Casey Langen" <avatar5d@hotmail.com> wrote in message news:yQQnb.17925$vi6.1...

CListCtrl draw question
hi there i have implemented a CListCtrl which displays graphic images as normal icons i have created for each item in the list several images relating to unselected, selected, drophilited, and hover states, and have written the code to update the image item index when the appropriate events occur all is going well, except i have one last 'issue' i would like resolve - when an item is selected in LVS_ICON mode in a CListCtrl, the icon's text is painted white on blue, and the icon has some kind of 'mask' applied to it to appear selected - i would like to prevent the icon (...

CListCtrl titles
Hello, I am working with a CListCtrl control in my VC++ app. I defined some columns o be displayed in the control. But I have been looking at the MSDN and did not find a way to set a title to every displayed colum in the CListCtrl. How can I do that ? Is there a way also to change the color of this title, as the backcolor of my list is black and I would like to display the titles in white ? Thank you for any help. -- Ceci est une signature automatique de MesNews. Site : http://www.mesnews.net ByB wrote: > Hello, > > I am working with a CListCtrl control in my VC++ app. I d...

Cloning CListCtrls
I'm looking for a example on cloning a CListCtrl. That is moving one or more items from list A to list B so that the moved items are removed from the source list. The following works to add the selected items to the list. // ---------------- CString sItem; int iSel = 0; POSITION pos = m_cAvailImagesList.GetFirstSelectedItemPosition(); while( pos ) { iSel = m_cAvailImagesList.GetNextSelectedItem(pos); sItem = m_cAvailImagesList.GetItemText(iSel, 0); m_cUseImagesList.InsertItem(0, sItem); } // -------------- Thanks. You could use callba...

How to add buttons to CListCtrl on top of header?
Hi, How to add buttons to CListCtrl on top of header. I would do it by putting the list control in a dialog and just putting other buttons on top of it. You could also put one in a CFormView if you want it in a view. Then you can put other controls anywhere you want. Tom "srikadi" <srikadi@gmail.com> wrote in message news:4b16bc81-3d29-4824-9239-7019b026bbdf@b38g2000prf.googlegroups.com... > Hi, > > How to add buttons to CListCtrl on top of header. On Oct 29, 9:48=A0am, "Tom Serface" <tom.nos...@camaswood.com> wrote: > I would do it by pu...

CListCtrl and NM_CUSTOMDRAW
Hi all, I hopefully have simple problem. I have a CListCtrl with the LVN_GETDISPINFO and NM_CUSTOMDRAW styles set. I am custom drawing every item, and its very slow compared to letting windows do it. All I'm doing is FillSolidRect() to color the background of the item, then TextOut() to draw text to it. It should be noted that because of the LVN_GETDISPINFO style, NM_CUSTOMDRAW gets fired once per item, not once per subitem. Here is my code: void CMusikPlaylistCtrl::OnLvnGetdispinfo(NMHDR *pNMHDR, LRESULT *pResult) { NMLVDISPINFO *pDispInfo = reinterpret_cast<NMLVDISPINFO*>(pNM...

CListCtrl Setting the Focus to a Row through Code
Hi i am taken a dialog based application. on the dialog i placed CListCtrl.i added 3 cols and 10 row to the list control. the first column is Checkbox. On the dialog box i placed two Buttons with captions "Next" and "Previous". when i run my application, when i Press "Next" Button the selection mark in the CListCtrl should move to the next row.and when i press "Previous" the selection mark in the CListCtrl should move to the previous row. i am using nItem=5; m_ListCtrl.SetItemState( nItem, LVIS_SELECTED|LVIS_FOCUSED, LVIS_SELECTED|LVIS_FOCUSED ); it...

attaching child ClistCtrl window to resizable parent Dialog
I'm using Visual C++ 7.0 and MFC With the Wizard, I created a Dialog Window [which I made resizable]. I've place two ClistCtrls side by side on the top of the dialog. I'd like to attach the RHS of the rightmost ctrl to the parent dialog so that when I resize the dialog, the listctrl expands. Note that I don't explicitly create the listctrls - this ia all behind the scene. I only send an initial message to each: m_ConfCtrlList.SendMessage(LVM_SETEXTENDEDLISTVIEWSTYLE,0, LVS_EX_FULLROWSELECT|LVS_REPORT|LVS_EX_GRIDLINES ); Thanks, Ihor VC++ doesn't not...

Using CListCtrl
When I click a list Item using left mouse button, I get NM_Click notification message. And When I select a list item using keyboad, I get NM_KEYDOWN notificatication message. Is there any single notification message, which will tell me about List Item Selection? ...