List View Item Control.

List View Item Control.

Here is a sample listing of code that will add bitmap IDs(win32 application) or ICON Ids to the list view control. few month back I made this to add a feature to my existing application module.
You cannot blindly add this to ur workspace since it need some modifications. Treat this as a code snippet or an example to make the target.!! Happy coding






/**
     class/structure:     SListControl
     author:     renjith

     creation: 25-march-2008

     Modification History
     ---------------------------------------------------------------------------------
     Date                                   comments                    Reason

     ---------------------------------------------------------------------------------
     27-Mar-08     Added ne method AddBmpImage() which           To add this class in
                    takes a vector of Ids and Names as Input.     main dialog of CADPartDB
    

     16-Jun-08 Added new methods SetProductName() and Support for new fron-end
                    GetProductName() to support the new front interface (insert/update
                    end Interface                                        the contents of DB)


     ---------------------------------------------------------------------------------
**/

 
#pragma once

#include <commctrl.h>
#include "../resource.h"
#include "../stdafx.h"


struct SListControl
{
    

     private:
          LV_ITEM lvi;
          LV_COLUMN lvc;
    
          std::vector<_str> m_strProdName;


     public:
    
     //int AddString ( LPCTSTR str ) { return ::SendMessage( handle, LB_ADDSTRING, 0, (LPARAM)str ); };

     int GetCurSel();
     void SetProductName(const std::vector<_str> & strVecName);

     std::vector<_str> GetProductName();

     void AddBmpImage(std::vector<int> nVecIDs,std::vector<_str> strVecName);
     bool AddBmpImage(int nIDStart,int nIDEnd, _str strName);

     bool AddIconImage(int nIDStart,int nIDEnd, _str strName);
};








/**
     class/structure:     SListControl
     author:     renjith

     creation: 25-march-2008

     Modification History
     ---------------------------------------------------------------------------------
     Date                                   comments                    Reason

     ---------------------------------------------------------------------------------
     27-Mar-08     Added ne method AddBmpImage() which           To add this class in
                    takes a vector of Ids and Names as Input.     main dialog of CADPartDB
    

     16-Jun-08 Added new methods SetProductName() and Support for new fron-end
                    GetProductName() to support the new front interface (insert/update
                    end Interface                                        the contents of DB)


     ---------------------------------------------------------------------------------
**/

 


#include "guicontrolenhanced.h"
#include "StdAfx.h"

#include <commctrl.h>

#include "../resource.h"
/*

#include <string>
#include <vector>
using namespace std;*/




     void SListControl::SetProductName(const std::vector<_str> & strVecName)

     {
          m_strProdName = strVecName;
     }

     std::vector<_str> SListControl::GetProductName()
     {
          return m_strProdName;

     }

     void SListControl::AddBmpImage(std::vector<int> nVecIDs,std::vector<_str> strVecName)
     {
          int nMAX = nVecIDs.size();

          HWND hList = handle;
          RECT Rect;
          HIMAGELIST himlLarge;

          SetProductName(strVecName);

          //LV_ITEM lvi;
          //LV_COLUMN lvc;

          int iStatus;
          int i;
          char szStr[ 32 ];

          //Registers and initializes certain common control window classes.

          InitCommonControls();

          if( ! hList )
               MessageBox(NULL,"hList is Null","",MB_OK);
         

          // Create an Image list, of 80x80 pixels
          himlLarge = ImageList_Create(80,80,ILC_COLOR32,100,100);
          //4th argument is the number of images that the image list initially contains.
          //5th argument is the the number of images by which the image list can grow when
          //the system needs to make room for new images.

    
          for( i = 0; i < nMAX; i++ ) // Add Images to each image list
          {              
               HBITMAP hBitMap; // bitmap handler

               int imlindex=-1;

               hBitMap=LoadBitmap(g_hModule,MAKEINTRESOURCE(nVecIDs[i]));
               if(!hBitMap)
                    MessageBox(NULL,"hBitMap is null","Msg",MB_OK);


               imlindex = ImageList_Add(himlLarge,hBitMap,NULL);
          }
              
          // Make the listview use the images lists and exit

          //ListView_SetImageList( hList, himlLarge, LVSIL_NORMAL);

          // this is # defined in the header as...
          SendMessage(hList, LVM_SETIMAGELIST, (WPARAM)(LVSIL_NORMAL), (LPARAM)(HIMAGELIST)(himlLarge));
   
          GetClientRect( hList, &Rect ); // Get the listview RECT size
         
          lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;

          lvc.fmt = LVCFMT_LEFT;
          lvc.cx = Rect.right - Rect.left; // Make bar width of window
          lvc.pszText = "Item Status";
          lvc.iSubItem = 0; // Add display column (for Report View)

          //iStatus = ListView_InsertColumn( hList, 0, &lvc );
          iStatus = SendMessage((hList), LVM_INSERTCOLUMN, (WPARAM)(int)(0), (LPARAM)(const LV_COLUMN *)(&lvc));
         

          lvi.mask = LVIF_IMAGE | LVIF_PARAM | LVIF_TEXT | LVIF_STATE;
          lvi.state = 0;
          lvi.stateMask = LVIS_FOCUSED; // Set generic structure values
          lvi.pszText = szStr;

          for( i = 0; i < nMAX; i++ ) // Add 20 items to the control

          {
              
               wsprintf( szStr, "%s",strVecName[i].c_str() ); // Name depends on number
               lvi.iImage = i ; // 5 images

               lvi.iItem = i;
               lvi.iSubItem = 0;
               lvi.lParam = 1;
               //iStatus = ListView_InsertItem( hList, &lvi ); // Add item to control

               iStatus = ::SendMessage((hList), LVM_INSERTITEM, 0, (LPARAM)(const LV_ITEM *)( &lvi));
          }
     }

     bool SListControl::AddBmpImage(int nIDStart,int nIDEnd, _str strName)

     {
          int nMAX = nIDEnd - nIDStart;
          HWND hList = handle;
          RECT Rect;
          HIMAGELIST himlLarge;
// HIMAGELIST himlSmall;

         
          //LV_ITEM lvi;
          //LV_COLUMN lvc;
          int iStatus;
          int i;

          char szStr[ 32 ];

         
          InitCommonControls();

          if( ! hList )
               MessageBox(NULL,"hList is Null","",MB_OK);

                              // Create two lists, one for 32x32 and another for 16x16 icons

          himlLarge = ImageList_Create(80,80,ILC_COLOR32,100,100);//100, 100, ILC_COLOR32, 0, 10

          for( i = 0; i <= nMAX; i++ ) // Add icons to each image list

          {              
               HBITMAP hBitMap; // bitmap handler
               int imlindex=-1;


               hBitMap=LoadBitmap(g_hModule,MAKEINTRESOURCE(nIDStart+i));
               if(!hBitMap)
                    MessageBox(NULL,"hBitMap is null","Msg",MB_OK);


               imlindex = ImageList_Add(himlLarge,hBitMap,NULL);
          }
              
          // Make the listview use the images lists and exit

          //ListView_SetImageList( hList, himlLarge, LVSIL_NORMAL);

          SendMessage(hList, LVM_SETIMAGELIST, (WPARAM)(LVSIL_NORMAL), (LPARAM)(HIMAGELIST)(himlLarge));
   
          GetClientRect( hList, &Rect ); // Get the listview RECT size
         
          lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
          lvc.fmt = LVCFMT_LEFT;

          lvc.cx = Rect.right - Rect.left; // Make bar width of window
          lvc.pszText = "Item Status";
          lvc.iSubItem = 0; // Add display column (for Report View)
          //iStatus = ListView_InsertColumn( hList, 0, &lvc );

          iStatus = SendMessage((hList), LVM_INSERTCOLUMN, (WPARAM)(int)(0), (LPARAM)(const LV_COLUMN *)(&lvc));
         
          lvi.mask = LVIF_IMAGE | LVIF_PARAM | LVIF_TEXT | LVIF_STATE;
          lvi.state = 0;

          lvi.stateMask = LVIS_FOCUSED; // Set generic structure values
          lvi.pszText = szStr;

          for( i = 0; i <= nMAX; i++ ) // Add 20 items to the control
          {

              
               wsprintf( szStr, "%s #%d",strName.c_str(), i + 1 ); // Name depends on number
               lvi.iImage = i ; // 5 images

               lvi.iItem = i;
               lvi.iSubItem = 0;
               lvi.lParam = 1;
               //iStatus = ListView_InsertItem( hList, &lvi ); // Add item to control

               iStatus = ::SendMessage((hList), LVM_INSERTITEM, 0, (LPARAM)(const LV_ITEM *)( &lvi));
          }
          // SendMessage(hList,LVM_DELETEITEM,3,0);

     return true;

     }

     bool SListControl::AddIconImage(int nIDStart,int nIDEnd, _str strName)
     {
          int nMAX = nIDEnd - nIDStart;

          HWND hList = handle;
          RECT Rect;
          HICON hiconItem;
          HIMAGELIST himlLarge;
          //LV_ITEM lvi;
          //LV_COLUMN lvc;

          int iStatus;
          char szStr[ 32 ];
          int i;

          InitCommonControls();

         
          if( ! hList )
               MessageBox(NULL,"hList is Null","",MB_OK);
          // Create lists, for 32x32 icons

          himlLarge = ImageList_Create( GetSystemMetrics( SM_CXICON ),
                                                  GetSystemMetrics( SM_CYICON ),
                                                  TRUE, 1, 1 );

         
          for( i = 0; i < nMAX; i++ ) // Add icons to each image list
          {              
              

               hiconItem = (HICON)LoadImage( g_hModule, MAKEINTRESOURCE( 1000+i ),IMAGE_ICON, 32, 32, LR_DEFAULTCOLOR );
               if(!hiconItem)
                    MessageBox(NULL,"hiconItem is Null","",MB_OK);

              
               ImageList_AddIcon( himlLarge, hiconItem );
               DeleteObject( hiconItem );
          }
              

          // Make the listview use the images lists and exit
          //ListView_SetImageList( hList, himlLarge, LVSIL_NORMAL);
          SendMessage(hList, LVM_SETIMAGELIST, (WPARAM)(LVSIL_NORMAL), (LPARAM)(HIMAGELIST)(himlLarge));
         
          GetClientRect( hList, &Rect ); // Get the listview RECT size

         
          lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
          lvc.fmt = LVCFMT_LEFT;
          lvc.cx = Rect.right - Rect.left; // Make bar width of window
          lvc.pszText = "Item Status";

          lvc.iSubItem = 0; // Add display column (for Report View)
          //iStatus = ListView_InsertColumn( hList, 0, &lvc );
          iStatus = SendMessage((hList), LVM_INSERTCOLUMN, (WPARAM)(int)(0), (LPARAM)(const LV_COLUMN *)(&lvc));


         
          lvi.mask = LVIF_IMAGE | LVIF_PARAM | LVIF_TEXT | LVIF_STATE;
          lvi.state = 0;
          lvi.stateMask = LVIS_FOCUSED; // Set generic structure values
          lvi.pszText = szStr;

          for( i = 0; i < nMAX; i++ ) // Add 20 items to the control

          {
               wsprintf( szStr, "%s #%d",strName.c_str(), i + 1 ); // Name depends on number
               lvi.iImage = i ;//% 5; // 5 images

               lvi.iItem = i;
               lvi.iSubItem = 0;
               lvi.lParam = 1;
               //iStatus = ListView_InsertItem( hList, &lvi ); // Add item to control

               iStatus = ::SendMessage((hList), LVM_INSERTITEM, 0, (LPARAM)(const LV_ITEM *)( &lvi));
          }

         
          return true;

     }

     int SListControl::GetCurSel()
     {
          //return ListView_GetNextItem(handle,-1,LVNI_FOCUSED);;
          return SendMessage(handle,LVM_GETNEXTITEM,-1,LVNI_FOCUSED); // return item selected

     }



37 comments:

teateatea1234 said...

每次看完你的文章,總是回味許久,要經常發表喔。.........................

剩沒底天 said...

xh美色網s38想看一下激激sex貼片網s383情色大網咖熟女自拍sex免費成人影片情境坊歡愉用品 視訊泳裝秀拓網交友免費成人影片,104免費成人情色文學小說視訊主播脫衣秀gogo2sexplus28論壇aa免費看a 免費影片觀賞一夜情人視訊 微風成人區壞朋友論壇一夜情視訊後宮電影院 色情影片後宮電影院 色情影片成人情色文學a漫性愛免費片貼圖片區h圖h卡通免費線上影片情色遊戲彩虹情人視訊交友網免費聊天交友
免費聊天交友淫淫美女視訊交友
淫淫美女視訊交友淫娃免費視訊聊天室拓網交友視訊聊天室
拓網交友視訊聊天室uthome 影音視訊聊天室
uthome 影音視訊聊天室

走吧 said...

enjoy your artical, thank you ........................................

寶皓 said...

great msg for me, thanks a lot dude˙﹏˙

郭怡君 said...

很喜歡你的部落格風格,期待你的更新!........................................

雅琳雅琳 said...

Cool blog網愛聊天室色情網站交友找啦咧免費影片成人笑話成人圖庫sexy女同志聊天室愛戀情人用品情趣爽翻天咆哮小老鼠入口85cc6k脫衣人妻sexy85c脫光光taiwansex淫女情色成人男女做愛美女做愛脫衣秀a片正妹淫蕩色情後宮040185c85c77p2p77p2p性幻想手淫18禁

友辰 said...

大奶妹貼圖區0204性影片觀賞露點自拍淫婦女生如何自慰色情站成人笑話av激情網愛視訊美女淫蕩av成人色情電話辣妹視訊聊天性關係情色vcd自慰圖淫美成人論壇台灣色情論壇成人聊天室自拍裸女貼圖視訊成人免費a片影片av成人網成人色情色情台灣辣妹小穴太太陰毛色情訊息裸女自拍色情影片a片論壇性愛技巧美女脫胸罩情色天堂av寫真色情視訊聊天做愛視訊成人影片床上戲情色聊天網火辣情色台灣女優性愛秘笈台灣av女優手淫自慰影片

惠IdellA_Fecteau1231蘋 said...

一個人的價值,應該看他貢獻了什麼,而不是他取得了什麼 ..................................................

信皇雯豪 said...

非常感謝~3Q~....................................................

OliveWol8888 said...

精彩的文章是我停留的理由~........................................

25TerinaRobles08 said...

感謝分享哦~會再來看看的~............................................................

柏勳 said...

blog的用心,看得出來~~請加油..................................................

D415_evonN_Risinger0 said...

喔!最悲慘的事並非夭折早逝,而是當我活到七十五歲,卻發現自己從未真正活過。 ..................................................

DedeJ文辰_Fe said...

A liar is not believed when he speaks the truth...................................................

vickiekurt said...

愛情是一種發明,需要不斷改良。只是,這種發明和其他發明不一樣,它沒有專利權,隨時會被人搶走。..................................................

SadeRa盈君iford0412 said...

世間是非,要如水泥地般水過則乾。..................................................................

俊毅俊毅 said...

大師手筆﹐果然不凡.................................................................

婷珊 said...

河水永遠是相同的,可是每一剎那又都是新的。......................................................................

韻枝 said...

河水永遠是相同的,可是每一剎那又都是新的。......................................................................

銘木 said...

人不能像動物一樣活著,而應該追求知識和美德............................................................

楊儀卉 said...

人有兩眼一舌,是為了觀察倍於說話的緣故。............................................................

欣怡 said...

成功可招引朋友,挫敗可考驗朋友............................................................

俊成俊成 said...

蛛絲馬跡皆學問、落花水面皆文章............................................................

吳婷婷 said...

不願彎腰撿拾一根針的人,永遠不值得一塊錢。..................................................

SarahD_Mon淑盛 said...

好久沒有這樣輕鬆享受閱讀的樂趣了~~留個言邀您分享我的快樂~~............................................................

茂慧茂慧 said...

Failure is the mother of success...................................................

原秋原秋 said...

認識自己,是發現妳的真性格、掌握妳的命運、創照你前程的根源。............................................................

陳韋夏陳韋夏益東富益東富 said...

晚上好,很喜歡你的blog哦.....................................................

RicoLisi0802志竹 said...

來拜訪囉~部落格很棒^^~幫你推個文.................................[/url]...............

ToryO_Vis建銘 said...

Look before you leap.................................................

文王廷 said...

只要有心,人人可以是熱門blog!!!............................................................

孟湖聿軒 said...

Learning makes a good man better and ill man worse.............................................................

偉曹琬 said...

所有的資產,在不被諒解時,都成了負債............................................................

李振婷李振婷 said...

the best as always thanks..................................................................

1615 said...

Make yourself necessary to someone..................................................................

王辛江淑萍康 said...

如果你批評他人。你就沒有時間付出愛......................................................................

洪勳劉耀德劉耀德華 said...

生命如夏花洵爛;死如秋葉之靜美。........................................ ........................