Rover12421's Blog

The End.

ListView编辑单元格

       这个在CU帮朋友解决的一个问题,他用的是SDK,我也正准备需要在MFC中使用ListView的这个功能。知道怎么处理,在MFC中使用到也就差不多了。

listview

下面是SDK中操作的关键代码:

01 if(((LPNMHDR)lParam)->code == NM_DBLCLK)
02                 {
03                     int nItem, nSubItem;
04                     LPNMITEMACTIVATE temp = (LPNMITEMACTIVATE)lParam;
05
06                     RECT rect;
07                     //Get the row number
08                     nItem = temp->iItem;
09                     //Get the Column number
10                     nSubItem = temp->iSubItem;
11                     if (/*nSubItem == 0 || */nSubItem == -1 || nItem == -1)
12                     {
13                         return FALSE;
14                     }
15                
16                     char text[255]={};
17                     memset(&LvItem,,sizeof(LvItem));
18                     LvItem.mask=LVIF_TEXT;
19                     LvItem.iSubItem=nSubItem;
20                     LvItem.pszText=text;
21                     LvItem.cchTextMax=256;
22                     LvItem.iItem=nItem;
23                     SendMessage(hList,LVM_GETITEMTEXT, nItem, (LPARAM)&LvItem);
24                     char text2[255]={};
25                    
26                     RECT rect1,rect2;
27                     ListView_GetSubItemRect(hList,nItem,nSubItem,LVIR_BOUNDS,&rect);
28 //                     sprintf(text2,"rect,rect.left:%d,rect.right:%d,rect.top:%d,rect.bottom:%d",rect.left,rect.right,rect.top,rect.bottom);
29 //                     MessageBox(NULL,text2,"rect",MB_OK);
30
31                     //Get the Rectange of the List Control
32                     GetWindowRect(temp->hdr.hwndFrom,&rect1);
33 //                     sprintf(text2,"rect1,rect1.left:%d,rect1.right:%d,rect1.top:%d,rect1.bottom:%d",rect1.left,rect1.right,rect1.top,rect1.bottom);
34 //                     MessageBox(NULL,text2,"rect1",MB_OK);
35                     //Get the Rectange of the Dialog
36                     GetWindowRect(hWnd, &rect2);
37 //                     sprintf(text2,"rect1,rect2.left:%d,rect2.right:%d,rect2.top:%d,rect2.bottom:%d",rect2.left,rect2.right,rect2.top,rect2.bottom);
38 //                     MessageBox(NULL,text2,"rect2",MB_OK);
39                     int x = rect1.left - rect2.left;
40                     int y = rect1.top - rect2.top;
41
42
43                     HWND hEdit = GetDlgItem(hWnd, IDC_INPUT);
44                     //SetWindowPos(hEdit,HWND_TOP,rect.left+x,rect.top+4,rect.right-rect.left-3,rect.bottom-rect.top-1,NULL);
45                     SetWindowPos(hEdit,HWND_TOP,rect.left+x,rect.top+14*2+7,rect.right-rect.left-3,rect.bottom-rect.top-1,NULL);
46                     ShowWindow(hEdit, SW_SHOW);
47                     SetFocus(hEdit);
48                     //Draw a rectangle around the SubItem
49                     Rectangle(GetDC(temp->hdr.hwndFrom), rect.left,rect.top-1,rect.right,rect.bottom);
50                     //Set the listItem text in the EditBox
51                     SendMessage(hEdit,WM_SETTEXT, , (LPARAM)"aaaaaa");   
52                 }

 

下载地址:
</images/uploads/2011/04/listview.rar>

Comments