Please help me some one...........

In my win32 application i created a dialog box with resource editor and inside that dialog box a list control also(With resource editor).from main window i am subclassing the dialog box
ListviewDlgProc:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#define IDC_LIST 10004
HWND hwndListview=NULL,hEdit=NULL;
LVCOLUMN  LvCol;
WNDPROC wpRecordProc,EOldProc;
HWND hDlg;//ListviewDlgProc handle
int iItem,iSubItem;
BOLL CALLBACK ListviewDlgProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)//Caling From MainProc
{
switch(message)
{  
    case WM_INITDIALOG:
    {
         hwndListview=GetDlgItem(hwnd,IDC_LIST);
         Memset(&LvCol,0,sizeof(LvCol));                  // Zero Members
         LvCol.mask=LVCF_TEXT|LVCF_WIDTH|LVCF_SUBITEM;    // Type of mask
         LvCol.cx=0x28;                                   // width betweencoloum
         LvCol.pszText="S.NO:";                            // First Header Text
         LvCol.cx=0x35;
         SendMessage(hwndListview,LVM_INSERTCOLUMN,0,(LPARAM)&LvCol);
          LvCol.cx=0x89;
          LvCol.pszText="Name"; 
         SendMessage(hwndListview,LVM_INSERTCOLUMN,1,(LPARAM&LvCol);  
         
      wpRecordProc=(WNDPROC)SetWindowLong(hwndListview, GWL_WNDPROC, (LONG)ListViewProc);
         
       return TRUE;                             
    }    
    break;
    case WM_COMMAND:
    {
      switch(LOWORD(wParam))
      {
          case IDOK:
            EndDialog(hwnd,IDOK);
          case IDCANCEL:
              EndDialog(hwnd,IDOK);

      }
    } 
     break;
   default
       return FALSE;
}
return TRUE;
}

So iadded 2 column to the list control.Next iwant to edit the sub items of list window control when user click on the perticular subitem area.
ListViewProc:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
LRESULT CALLBACK ListViewProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{  
 switch(message)
{       
  case WM_LBUTTONDOWN:       
  {       /*It uses SubItemHitTest to see which SubItem was clicked,            and stores it in the struct itemclicked.*/    
	 if (hEdit != NULL){SendMessage(hEdit,WM_KILLFOCUS,0,0);};           
	 LVHITTESTINFO itemclicked;           
	 long x, y;          
	 x = (long)LOWORD(lParam);           
	 y = (long)HIWORD(lParam);            
          itemclicked.pt.x = x;            
	 itemclicked.pt.y = y;            
	 int lResult = ListView_SubItemHitTest(hwnd,&itemclicked);   //Failure returns -1
  /*If SubItemHitTest doesn't return any error (lResult!=-1), it gets the Rect            of the SubItem (or Item) clicked, and creates an EditBox (hEdit) with the            same size as the SubItem. Then, it sets focus on hEdit and sets a            callback function (EditProc) for it.*/        
	 if (lResult!=-1)
	 {               
		 RECT subitemrect;               
                   ListView_GetSubItemRect(hwnd,itemclicado.iItem,itemclicado.iSubItem,LVIR_BOUNDS,&subitemrect);                
		 int altura = subitemrect.bottom - subitemrect.top;                
		 int largura = subitemrect.right - subitemrect.left;               
		 if (itemclicado.iSubItem==0){largura=largura/2;}; 
/*NOTE: the ListView has 2 columns;                                        when iSubItem == 0 (an item is clicked),                                        the width (largura) is divided by 2,                                        because for items (not subitems) the                                        width returned is that of the whole row.*/              
		 hEdit = CreateWindowEx(WS_EX_CLIENTEDGE, "EDIT", "",                 WS_CHILD|WS_VISIBLE|ES_WANTRETURN, subitemrect.left, subitemrect.top, largura, 1.5*altura, hwnd, 0, GetModuleHandle(NULL), NULL);               
		 if(hEdit == NULL)  MessageBox(hwnd, "Could not create edit box.", "Error", MB_OK | MB_ICONERROR);               
		 SetFocus(hEdit);                
		 EOldProc = (WNDPROC)SetWindowLong(hEdit, GWL_WNDPROC, (LONG)EditProc);               
		 iItem = itemclicked.iItem;                
		 iSubItem = itemclicked.iSubItem;           
	 }           
	 return 0;           
	 break;       
   }    
} 
return CallWindowProc(wpRecordProc, hwnd, message, wParam, lParam);
}

EditProc:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
LRESULT CALLBACK EditProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{    switch(message)
      {        
	  case WM_KILLFOCUS:        
		{            
			LV_DISPINFO lvDispinfo;            
                           ZeroMemory(&lvDispinfo,sizeof(LV_DISPINFO));            
			lvDispinfo.hdr.hwndFrom = hwnd;            
			lvDispinfo.hdr.idFrom = GetDlgCtrlID(hwnd);            
			lvDispinfo.hdr.code = LVN_ENDLABELEDIT;            
			lvDispinfo.item.mask = LVIF_TEXT;            
			lvDispinfo.item.iItem = iItem;            
			lvDispinfo.item.iSubItem = iSubItem;            
			lvDispinfo.item.pszText = NULL;           
			char szEditText[10];            
			GetWindowText(hwnd,szEditText,10);            
			lvDispinfo.item.pszText = szEditText;            
			lvDispinfo.item.cchTextMax = lstrlen(szEditText);            SendMessage(GetParent(GetDlgItem(hDlg,IDC_LIST)),WM_NOTIFY,(WPARAM)IDC_LIST,(LPARAM)&lvDispinfo); //the LV ID and the LVs Parent window's HWND            DestroyWindow(hwnd);            break;        
		}    
	}     
	  
	  return CallWindowProc(EOldProc, hwnd, message, wParam, lParam);
}

But this code is not working.i am not getting anything.Please helpme to solve this problem.Please.
Last edited on
Topic archived. No new replies allowed.