Setting up state images


As you are already aware, the tree view control can display two images for each item. Each of these two images belong in different image list controls that have to be associated with the tree control. Whereas, an item can have upto 256 item images, it can only have 15 state images. Nevertheless, the programming for the state images is very similar to the programming for item images.

An image list has to be created before it can be associated with the tree view control. You can create the image list from a single bitmap, horizontally laid out to contain all the images or you can add individual icons to the image list.

Step 1: Create the bitmap

Add a bitmap resource in the resource editor that contains all the icons. Here is an example below. The individual icons in this bitmap are 13x13 pixels, but you may choose a different size and it need not be a square. The first image in the list is not used.

 

Step 2: Add a member variable to hold the image list

The member variable is usually added to the class that is responsible for setting up the tree view control. This would usually be the CView derivative or a CDialog derivative. You can also add the member variable to the sub-class of CTreeCtrl which is what I recommend.
 
class CTreeCtrlX : public CTreeCtrl
{
// Construction
public:
        CTreeCtrlX();

// Attributes
public:
    CImageList m_imageState ;
    :
    :
    :

}

Step 3: Create and set the image list

Call the Create() function of the image object with the resource id of the bitmap we created in step 1 and the width of each icon. The height of the icons is automatically set to the height of the bitmap. The third argument required by the Create() function represents the number of new images the resized image list can contain. Since we are creating the image list from a bitmap, we would normally not add any more images at runtime so we let this value be one. The last argument is the mask color. That is, all the pixels of this color will behave as a transparent color. Since normally the window color is white, we set the mask color to white.

Once the image list has been created, the tree view control has to be instructed to use it. We do that by calling the SetImageList() function. The following statement usually belongs in the OnInitDialog() function or the OnInitialUpdate() function. Note that in the call to SetImageList(), the second argument is TVSIL_STATE.
 
        m_tree.m_imageState.Create( IDB_STATE, 13, 1, RGB(255,255,255) );
        m_tree.SetImageList( &(m_tree.m_imageState), TVSIL_STATE );

Step 4: Specify state icons for the items

Once an image list has been associated with the tree view control, you can instruct the tree view control to the use the state image you want when inserting an item to the control. You can also use the SetItemState() image function. In both the cases you have to use the macro INDEXTOSTATEIMAGEMASK(). This macro essentially rearranges the bits of the index value to be compatible with what the tree view control expects. To remove the state image for an item, use the index zero. Here are example usages
 
        // Using TV_INSERTSTRUCT
        CString str = "xyzASDFqwerZCV";
        TV_INSERTSTRUCT tv_is;
        tv_is.hParent = parent ? parent : TVI_ROOT;
        tv_is.hInsertAfter = TVI_LAST ;
        tv_is.item.mask = TVIF_TEXT | TVIF_STATE;
        tv_is.item.stateMask = TVIS_STATEIMAGEMASK;
        tv_is.item.state = INDEXTOSTATEIMAGEMASK( 1 );
        tv_is.item.pszText = str.GetBuffer(1);
        tv_is.item.cchTextMax = str.GetLength();
        hItem = InsertItem( &tv_is );
        str.ReleaseBuffer();


        // Using SetItemState
        SetItemState( hItem, INDEXTOSTATEIMAGEMASK(1), TVIS_STATEIMAGEMASK );
 



Comments

  • yxpcvcrn

    Posted by wlgxfmip on 04/22/2013 11:07pm

    ouufluhs http://casquebeatsbydreoffzhot.fr/ xtcurhux http://salzchaneloutletoffr.com/ xkuumexr http://nowsalzhollisteroutlet.co.uk/ tybinzfj http://coolralphlaurenpascheroffz.fr/ iuxsfmhq http://louisvuittonhandbagsoffzhot.com/ roofdhpj casque beats by dre kwfinjls chanel outlet plwyrqxx hollister outlet hgjvdtin ralph lauren pas cher jppmnowe louis vuitton handbags That allows you to maintain fantastic car or truck variety source, the particular chemical substance account balance from the cellphone must be actually maintained. Should you usually have some vainness webpage so are curious about the reason you just aren't finding visitors, subsequently you need to comprehend that the vanity web log markets is completely saturated. Via assets in several media, drivers can learn plans which are designed thus to their each and every have.

    Reply
  • izrirekp

    Posted by sjxmfyjo on 04/22/2013 01:38pm

    coqbbcuu http://oakleysunglassesaustraliao.co.uk/ fygemtid http://casquebeatspascherq.fr/ ehufwbmw http://louisvuittonwalletet.com/ pucmcgoc http://hollisteroutletlet.co.uk/ zgzxfmif http://todsbagndrivingshoese.com/ mfomjnfe oakley sunglasses australia kiuqgzvk casque beats pas cher nnorbysx louis vuitton wallet rnqnckho hollister outlet ntmvotnk tods bag {People|Families|Consumers|Men and women|Folks} {attempt|consider|try out|effort|test} {prescription|pharmaceutical|recommended|health professional prescribed|prescribed} {diet pills|fat burning supplements|fat burners|weightloss pills|weight loss supplements} {to help|for helping|that will help|to help you|to aid} {them|these products|him or her|these people|these} {but they|only to find they|they also|nonetheless they|nevertheless they} {discover|explore|find|learn|find out} {there's|there are|you can find|there may be|there is certainly} {significantly|tremendously|very much|drastically|substantially} {worse|rather more serious|worse yet|more serious|a whole lot worse} {unwanted side effects|negative effects} {than|as opposed to|compared with|when compared with|as compared to} {being overweight|obese|excessive weight|obesity|carrying excess fat}. {Therefore|Thus|Subsequently|For that reason|For this reason}, {as a possible|just as one|as an} advisory {physical|real|vigorous|actual physical|bricks-and-mortar} {body|human body|overall body|system|body system}, {must be|need to be|is required to be|have to be|ought to be} {high|excessive|big|substantial|huge} {using|applying|by using|employing|implementing} {man|male|mankind|gentleman|fella} {or|or maybe|and / or|as well as|or simply} {women|women of all ages|a lot of women|girls|most women} {high quality|premium quality|superior|excellent|premium} {current|recent|active|latest|ongoing} {administration|current administration|managing|supervision|maintenance} {on the|within the|at the|for the|over the} {electronic|automated|vapor|electric|electrical} {degree|stage|measure|amount|college degree} {and / or|or|and|as well as|or even} {huge|big|vast|enormous|significant} {provider|service|specialist|company|issuer} synergy. {Without|Without the need of|With out|Free of|While not} {regular|common|typical|routine|ordinary} {maintenance|routine maintenance|servicing|routine service|protection}, {an|some sort of|a powerful|the|a great} {air conditioning unit|air conditioner} {has the ability to|is able to|has the capacity to|can} {lose|suffer a loss of|burn|get rid of|drop} {up to|around|about|close to|as much as} {five|your five|six|a few|several} {percent|p .

    Reply
  • sjywsxnt

    Posted by jtnvmvto on 04/21/2013 08:32pm

    gmxzizxl http://jetztlouisvuittons.de/ khxpbtmq http://beatsbydrdreoffrsale.fr/ nwmjdfvc http://cheapchanelukhotsale.co.uk/ vtrzbzwr http://hotzpoloralphlaurenpaschers.fr/ ykztzoub http://louisvuittonshoeshotoffr.com/ rpguwlts louis vuitton ypeqxipf beats by dr dre shfkikkb chanel uk lygwilft polo ralph lauren pas cher mlrdzugq louis vuitton shoes {The water|Water|The tank|This type of water|The river} {inside the|within the|contained in the|from the|inside} {batteries|electric batteries|electrical power|energy|battery power} {must also|should also|also wants|also need to|need to} {be|end up being|turn out to be|often be|always be} {changed|transformed|replaced|evolved|improved} {regularly|frequently|constantly|consistently|often}. {Although|Even if|While|Nevertheless|Though} {you might not|may very well not|would likely not|you possibly will not|you do not} {want to|plan to|would like to|like to|need to} {go around|bypass} broadcasting {your|a|ones|ones own|your current} {credit score|fico score|credit worthiness|credit ranking|credit standing}, {it is|it happens to be|it truly is|it will be|it can be} {okay|o . {You will need to|You simply must|You'll want to|You must|You've got to} {ask|inquire|you can ask|check with|talk to} {your|your current|a|a person's|an individual's} {auto|vehicle|car or truck|automatic|motor vehicle} {collision|accident|smashup|impact|wreck} {repair shop|repair center|mechanic shop} {to|for you to|towards|so that you can|that will} {send|mail|transmit|give|ship} {the|your|typically the|a|any} {insurance company|insurer|insurance underwriter|insurance broker|insurance vendor} {an|the|a particular|a strong|some sort of} {estimate|calculate|guess|approximation|guesstimate} {for|pertaining to|for the purpose of|to get|meant for} {repairs|vehicle repairs|fixing|problems|car repairs}.

    Reply
  • vqnntzlr

    Posted by jmckijhg on 04/08/2013 12:55am

    llxvgxi http://oakleysunglassesaustraliazaus.com/ bwvhuaj http://chanelbagsnell.co.uk/ dqicfzo http://truereligionjeansme.com/ qlijjap http://hollisterukolr.co.uk/ spujdbln http://cheapoakleysunglassesrraus.com/ wkycmmzg true religion jeans vfumicua hollister uk fxcllskp cheap oakley sunglasses mrohnclr oakley sunglasses australia ogigdsuk chanel bags {See|Notice|Check out|Discover|Find out}? {Easy|Effortless|Convenient|Uncomplicated|Very easy} isnt {it|that|it again|the idea|the application}? {I|My partner and i|I just|My spouse and i|As i} didnt {call|contact|label|call up|phone call} {this one|this place|gas 4 free :|this|this town} {easy|effortless|convenient|uncomplicated|very easy} paleo {dinner|meal|meals|evening meal|food} {for|regarding|for the purpose of|pertaining to|designed for} {nothing|practically nothing|not a single thing|nothing at all|not a thing} {okay|ok|o . {Our body|Our own bodies|Your body|Our system|The body} {knows|is familiar with|is aware of|recognizes|understands} {what|what precisely|precisely what|whatever|exactly what} {it|it all|the idea|it again|this} {wants|likes|wishes|requirements|desires}, {we now|we have now} {just have to|simply have to|only have to|just need to|have to} {respect|adhere to|admiration|dignity|regard} {it|it all|the idea|it again|this} {and|together with|along with|not to mention|as well as} {listen to|play|hear|take note on|pay attention to} {it|it all|the idea|it again|this}. {To be able to|Kid|Every single child|In order to|So that you can} {be aware of|know|be familiar with|know about|understand} {some of the|the various|a few of the|a number of the|a lot of the} {dressing|dress up|outfitting|dressing up|attire} {tips for|advise for|strategies for|methods for|techniques for} {college|faculty|university|school|college or university} {guys|gentlemen|men|fellas|people}, {you must|you have got to|you have to|you need to|you will need to} {try|have a shot at|attempt|test|look at} {reading|analyzing|reading through|studying|examining} {fashion magazines|magazines|fashion periodicals|advertisements} {which can|which sometimes|which could|that may|which will} {give you the|present you with the|provide you with the|supply you with the|provides you with the} {latest|most recently released|most recent|newest|most current} {trends|fashion|developments|styles|movements} {and|and even|as well as|and also|in addition to} {styles|versions|designs|types|models}.

    Reply
  • gpgryaso

    Posted by ktcwmxmc on 04/03/2013 11:17am

    zndipxin http://casquebeatsbydrec.fr/ dfwoqkiu http://louisvuittonspeedy3035y.com/ gxdrepxf http://hollistererruk.co.uk/ gssyivur http://hollisteruker.co.uk/ vtrppvph http://todsshoesess.com/ dujcwfrx casque beats by dre dkrehdiq louis vuitton speedy 35 bhrbgsjl hollister uk yptgubkc hollister uk bohxlmtm tods shoes

    Reply
  • lvnjgxmq

    Posted by vhuorawo on 03/07/2013 12:05am

    rllqbysq http://louissvuittonhandbagss.com/ elnagrjs http://louissvuittonoutlet.com/ ylblxylw http://beatsbydrebeatsz.com/ cxlhrrho louis vuitton handbags jhyaaezj louis vuitton outlet crbuebze beats by dre Your task habitat is vital which enable it to surely be an element in the man or woman suffering with sluggish next lunchtime. Alaska Halibut Fishing Trips- Ideas for Leisure Hunters Crashed medical tests clearly show of which fit belts start a fairly good occupation intended for protecting the driver's human body in any frontal impact, yet many though not always keep the driver's venture from impacting the tyre (which usually may end up in significant pain or even passing).

    Reply
  • What if you need more than 15 state images?

    Posted by Legacy on 12/02/2002 12:00am

    Originally posted by: Pierre

    Is there some way to do this without the ownerdraw options

    Reply
  • specifying state image in the tree view

    Posted by Legacy on 09/20/2001 12:00am

    Originally posted by: deepak jain

    it's a good example, if u could elaborate more on state, stagemask and mask members of item structure, it'll be good.

    Reply
  • How to determine whether a node is expanded or not?

    Posted by Legacy on 07/05/2001 12:00am

    Originally posted by: Angshuman Chatterjee

    I want to examine whether a node in the tree control is presently expanded on not (i.e. it has the '-' sign infront of its label. I cannot do it with
    GetItemState(hItem,TVIS_EXPANDED).
    The problem is that the return valu of GetItemState is the combination of the flags TVIS_EXPANDEDONCE and TVIS_EXPANDED. How can I test for ONLY TVIS_EXPANDED?

    Reply
  • Don't forget TVS_CHECKBOXES

    Posted by Legacy on 05/24/2000 12:00am

    Originally posted by: Peter Hahm

    You forgot to mention that it is usefull to create the treecontrol with a specific style constant, TVS_CHECKBOXES.

    Yours
    Peter

    • Thanks !

      Posted by Trimoulin on 05/23/2012 12:50am

      This remark solves my problem, thanks a lot :-)

      Reply
    Reply
  • Loading, Please Wait ...

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Live Event Date: August 20, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT When you look at natural user interfaces as a developer, it isn't just fun and games. There are some very serious, real-world usage models of how things can help make the world a better place – things like Intel® RealSense™ technology. Check out this upcoming eSeminar and join the panel of experts, both from inside and outside of Intel, as they discuss how natural user interfaces will likely be getting adopted in a wide variety …

  • Hybrid cloud platforms need to think in terms of sweet spots when it comes to application platform interface (API) integration. Cloud Velocity has taken a unique approach to tight integration with the API sweet spot; enough to support the agility of physical and virtual apps, including multi-tier environments and databases, while reducing capital and operating costs. Read this case study to learn how a global-level Fortune 1000 company was able to deploy an entire 6+ TB Oracle eCommerce stack in Amazon Web …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds