Google Answers Logo
View Question
 
Q: vc++ programming doubt ( Answered,   1 Comment )
Question  
Subject: vc++ programming doubt
Category: Computers > Programming
Asked by: rnd-ga
List Price: $2.00
Posted: 05 Sep 2002 06:50 PDT
Expires: 05 Oct 2002 06:50 PDT
Question ID: 61896
i am using VC++ 6 to display some results in a list view,
and images next to aech one of them, but my problem is i dont want the
images to appear in the FIRST COLUMN only, but the images should
appear in the subsequent sub items..can u pls send me the code for
that
Answer  
Subject: Re: vc++ programming doubt
Answered By: spot_tippybuttons-ga on 10 Sep 2002 16:16 PDT
 
The list view control is not designed to do this. However, if you are
willing to do your own rendering, you can use the Custom Draw feature
of the list view control which will allow you to display graphics,
formatted text, or anything else you please. To do so, you will need
version 4.70 or later of Comctl32.dll... odds are, you have this
already. To use the Custom Draw functionality, you will need to
process the NM_CUSTOMDRAW notification message.

The following source code sample is from the MSDN and shows a simple
example of custom rendering. To draw the _entire_ control yourself,
return CDRF_SKIPDEFAULT instead and draw the desired contents into the
given hDC.


LRESULT DoNotify(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) 
{
    LPNMLISTVIEW  pnm    = (LPNMLISTVIEW)lParam;   
    
    switch (pnm->hdr.code) 
    {

        case NM_CUSTOMDRAW:
        {
            LPNMLVCUSTOMDRAW  lplvcd = (LPNMLVCUSTOMDRAW)lParam;

            /*
                CDDS_PREPAINT is at the beginning of the paint cycle.
You
                implement custom draw by returning the proper value.
In this
                case, we're requesting item-specific notifications.
            */
            if(lplvcd->nmcd.dwDrawStage == CDDS_PREPAINT)
                // Request prepaint notifications for each item.
                return CDRF_NOTIFYITEMDRAW;         
            
            /*
                Because we returned CDRF_NOTIFYITEMDRAW in response to
                CDDS_PREPAINT, CDDS_ITEMPREPAINT is sent when the
control is
                about to paint an item.         
            */
            if(lplvcd->nmcd.dwDrawStage == CDDS_ITEMPREPAINT){
                
                /*
                    To change the font, select the desired font into
the
                    provided HDC. We're changing the font for every
third item
                    in the control, starting with item zero.
                */
                
                if(!(lplvcd->nmcd.dwItemSpec % 3))
                    SelectObject(lplvcd->nmcd.hdc, g_hNewFont);
                else
                    return(CDRF_DODEFAULT);            
                
                /*
                    To change the text and background colors in a list
view
                    control, set the clrText and clrTextBk members of
the
                    NMLVCUSTOMDRAW structure to the desired color.
                    This differs from most other controls that support
                    CustomDraw. To change the text and background
colors for
                    the others, call SetTextColor and SetBkColor on
the provided HDC.
                */            
                
                lplvcd->clrText = RGB(150, 75, 150);
                lplvcd->clrTextBk = RGB(255,255,255);            
                
                /*
                    We changed the font, so we're returning
CDRF_NEWFONT. This
                    tells the control to recalculate the extent of the
text.
                */            
                
                return CDRF_NEWFONT;            
            }         
        }      

        default:         
            break;   
    }   

    return 0;
}



Hope this helps!

Custom Draw Reference
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/commctls/custdraw/refs.asp

"Custom Draw", MSDN Library, Microsoft Corporation, (1997)
Comments  
Subject: Re: vc++ programming doubt
From: darrenw-ga on 06 Sep 2002 04:26 PDT
 
I have used this control myself in the past and I needed to do the
same thing. I did not find any text that told me how to do this and
from memory I believe you cannot do this. My only suggestion (and I
only thought of this as I was typing in this comment) is to create two
list views next to each other with the images in the first column of
the second view. You will need to link them up so if the user scrolls
one view you will need to scroll the other one to match them up.
Sounds like a bad way of achieving the effect though.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy