Thread: LVM_INSERTITEM I cannot make head or tail of it.

  1. #1
    Registered User
    Join Date
    Sep 2009
    Posts
    37

    LVM_INSERTITEM I cannot make head or tail of it.

    hello all,

    is there another way to insert ListView Subitems exept over the WndProc


    btw i list some code of mine:
    Code:
    ///////////////////////
    /////     ListView Insertitem
    ///
    ////////////////////
    bool LVaddColumn(PCHAR pszText,HWND ListView,int Index){
    LV_COLUMN LvCol;
    LvCol.mask=LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;    // Type of mask
    LvCol.cx=0x0;
    LvCol.pszText=pszText;                            // First Header Text
    LvCol.cx=0x1E;
    SendMessage(ListView,LVM_INSERTCOLUMN,Index,(LPARAM)&LvCol);
    //ListView_InsertColumn(ListView, 0, &LvCol) ;
    return(TRUE);
    }
    
    void LVaddItem(PUCHAR pszText,HWND ListView,BOOL subitem){
    LV_ITEM lvI;
     // Initialize LVITEM members that are common to all items.
    lvI.mask = LVIF_TEXT|LVIF_PARAM | LVIF_IMAGE | LVIF_STATE|LVCF_SUBITEM;
    lvI.state = 0;
    if(subitem==1){
    lvI.iItem=0;
    lvI.iSubItem=1,0;
    lvI.pszText=pszText;
    SendMessage(    // returns LRESULT in lResult
       ListView,           // (HWND) handle to destination control
       LVM_SETITEM,           // (UINT) message ID
       0,                // = 0; not used, must be zero
      (LPARAM)(LPLVITEM)&lvI                  // = const (LPARAM)(LPLVITEM) pitem;
    );
    
    } else {
    lvI.iItem=0;
    lvI.stateMask = LVIS_SELECTED|LVIS_FOCUSED;
    lvI.pszText=pszText;
    SendMessage(    // returns LRESULT in lResult
       ListView,           // (HWND) handle to destination control
       LVM_INSERTITEM,        // (UINT) message ID
       0,                // = 0; not used, must be zero
       (LPARAM)(LPLVITEM)&lvI                 // = const (LPARAM)(LPLVITEM) pitem;
    );
    }
    }
    Code:
    ListView0=CreateListView(ObjEditorWindow,"ListView",HMENU)ID_LISTVIEW,0,0,400,400);
    LVaddItem("b",ListView0,false);
    LVaddItem("c",ListView0,false);
    LVaddItem("d",ListView0,false);
    LVaddItem("a",ListView0,true);
    
    
    LVaddColumn("03",ListView0,1);
    LVaddColumn("04",ListView0,2);
    it adds d c b in the ListView collumn namend 03
    but nothing into the 04

    if use the Winproc WM_Notify routine
    like this (at the ObjEditorWindow WndProc)
    Code:
    case WM_NOTIFY:
    	 {
     switch (((LPNMHDR) lParam)->code)
    	{
    		case LVN_GETDISPINFO:
    			NMLVDISPINFO* plvdi = (NMLVDISPINFO*)lParam;
    					switch (plvdi->item.iItem)
    			{
    				case 0:
    			  plvdi->item.pszText ="9";
    							break;
    										default:
    					break;
    			}  
    
    	}         break;
    	}
    it puts the 9 into the column namend 04

    but is there a way without the WndProc

  2. #2
    Registered User
    Join Date
    Sep 2009
    Posts
    37

    Thumbs up FIXED i GOT it

    Code:
    void LVaddItem(PUCHAR pszText,HWND ListView,BOOL subitem){
    LV_ITEM lvI;
     // Initialize LVITEM members that are common to all items.
    Code:
    lvI.mask = LVIF_TEXT|LVIF_PARAM | LVIF_IMAGE | LVIF_STATE|LVCF_SUBITEM;
    1. // |LVIF_PARAM VALUE shoud not be set in subitems than it works

    Code:
    lvI.mask = LVIF_TEXT|LVIF_IMAGE | LVIF_STATE|LVCF_SUBITEM;
    Code:
    lvI.state = 0;
    if(subitem==1){
    lvI.iItem=0;
    lvI.iSubItem=1,0;
    lvI.pszText=pszText;
    SendMessage(    // returns LRESULT in lResult
       ListView,           // (HWND) handle to destination control
       LVM_SETITEM,           // (UINT) message ID
       0,                // = 0; not used, must be zero
      (LPARAM)(LPLVITEM)&lvI                  // = const (LPARAM)(LPLVITEM) pitem;
    );
    
    } else {
    lvI.iItem=0;
    lvI.stateMask = LVIS_SELECTED|LVIS_FOCUSED;
    lvI.pszText=pszText;
    SendMessage(    // returns LRESULT in lResult
       ListView,           // (HWND) handle to destination control
       LVM_INSERTITEM,        // (UINT) message ID
       0,                // = 0; not used, must be zero
       (LPARAM)(LPLVITEM)&lvI                 // = const (LPARAM)(LPLVITEM) pitem;
    );
    }
    }
    Last edited by punkywow; 10-03-2009 at 07:24 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. head & last ptrs in linked lists
    By sahil_m in forum C Programming
    Replies: 2
    Last Post: 10-13-2005, 07:00 AM
  2. Cant head insert on doubly linked list
    By aciarlillo in forum C++ Programming
    Replies: 4
    Last Post: 09-18-2005, 11:31 AM
  3. Can't figure out problem with code
    By Beast() in forum C Programming
    Replies: 4
    Last Post: 04-16-2005, 05:27 PM
  4. how to make the worm move
    By Unregistered in forum C++ Programming
    Replies: 0
    Last Post: 11-10-2001, 03:11 PM