If you haven't find any solution (I find lots in VB and MFC, but none in C) you can try that: first some global vars:
Code:
HWND llista;//listview
HWND hlEdit;//a global editlabel box
WNDPROC prevHLEditProc;//the proc of that edit control
struct _INFOHLEDITBOX//struct for internal information
{
HWND phwnd;//main window
HWND fhwnd;//focused window, not necessary
LV_ITEM lvi;//item edited
};
struct _INFOHLEDITBOX ihleb;//internal information for the hlEdit box
#define HLEBP_ENDLABELEDIT WM_USER+1//message notification equivalent to ENDLABELEDIT
Here in Cboard there's a thread about how to setup user messages in the right way, I can't remember if was that or not, for the moment this works for me.
First create the listview without LVS_EDITLABELS but with the fullrow select on. Then create a hidden edit box, setup the internal information and give it the alternative procedure:
Code:
llista=CreateWindowEx(WS_EX_CLIENTEDGE,WC_LISTVIEW,"",WS_CHILD|WS_VISIBLE|WS_TABSTOP|LVS_REPORT|LVS_SHOWSELALWAYS|LVS_NOSORTHEADER,0,0,0,0,hwnd,(HMENU)LLISTA_DADES,GetModuleHandle(0),NULL);
SendMessage(lt,LVM_FIRST+54,0,32);
hlEdit=CreateWindowEx(0,"EDIT","",WS_CHILD|WS_BORDER|ES_AUTOHSCROLL,0,0,0,0,hwnd,(HMENU)LVEDITBOX,GetModuleHandle(0),NULL);
SendMessage(hlEdit,WM_SETFONT,(WPARAM)hf1,(LPARAM)MAKELPARAM(TRUE,0));
prevHLEditProc=(WNDPROC)GetWindowLong(hlEdit,GWL_WNDPROC);
SetWindowLong(hlEdit,GWL_WNDPROC,(LONG_PTR)hlEditProc);
ihleb.phwnd=hwnd;
ihleb.fhwnd=NULL;
memset(&ihleb.lvi,0,sizeof(ihleb.lvi));
ihleb.lvi.mask=0;
ihleb.lvi.iItem=0;
ihleb.lvi.iSubItem=0;
Now go to catch the NM_DBLCLK on WM_NOTIFY from the listview, it will be the BEGINLABELEDIT equivalent:
Code:
case NM_DBLCLK:
{
int i;
char bff[512];
LVHITTESTINFO_EX lvHit;
DWORD dwPos;
POINT pLoc;
RECT lvEditRect;
//get the item selected
i=SendMessage(llista,LVM_GETNEXTITEM,(WPARAM)-1,(LPARAM)LVNI_FOCUSED|LVNI_SELECTED);
//I have a report on the 3 last rows, so I make it noneditable
if(i<0 || i>=SendMessage(llista,LVM_GETITEMCOUNT,0,0)-3) {break;}
//the same as in your code
dwPos=GetMessagePos();
pLoc.x=LOWORD(dwPos);
pLoc.y=HIWORD(dwPos);
ScreenToClient(hwnd,&pLoc);
//the same as in your code
lvHit.pt.x=pLoc.x;
lvHit.pt.y=pLoc.y;
lvHit.iItem=i;
SendDlgItemMessage(hwnd,LLISTA_DADES,LVM_FIRST+57,0,(LPARAM)&lvHit);
//the same as in your code
lvEditRect.top=lvHit.iSubItem;
lvEditRect.left=LVIR_LABEL;
SendDlgItemMessage(hwnd,LLISTA_DADES,LVM_FIRST+56,i,(LPARAM)&lvEditRect);
//setup the internal information for the label editing
memset(&ihleb.lvi,0,sizeof(ihleb.lvi));
ihleb.fhwnd=NULL;//you can delete it from here and from the struct
ihleb.lvi.mask=LVIF_TEXT;
ihleb.lvi.iItem=i;
ihleb.lvi.iSubItem=lvHit.iSubItem;
ihleb.lvi.pszText=bff;
ihleb.lvi.cchTextMax=sizeof(bff);
SendMessage(llista,LVM_GETITEM,0,(LPARAM)&ihleb.lvi);
//set the initial text to the edit
SendMessage(hlEdit,WM_SETTEXT,0,(LPARAM)bff);
//and show/focuse it
SetWindowPos(hlEdit,HWND_TOP,lvEditRect.left,lvEditRect.top+1,(lvEditRect.right-lvEditRect.left),(lvEditRect.bottom-lvEditRect.top)+2,SWP_SHOWWINDOW);
SetFocus(hlEdit);
}
break;
The next is to set the alternative procedure, like that:
Code:
LRESULT CALLBACK hlEditProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam)
{
switch(msg)
{
case WM_KILLFOCUS:
{
ihleb.fhwnd=(HWND)wParam;//not necessary
//this is the end label editing state, so hide the box and inform the parent
SetWindowPos(hlEdit,HWND_BOTTOM,0,0,0,0,SWP_HIDEWINDOW);
SendMessage(ihleb.phwnd,HLEBP_ENDLABELEDIT,0,0);
return 0;
}
break;
}
return CallWindowProc(prevHLEditProc,hwnd,msg,wParam,lParam);
}
Finally evalue the HLEBP_ENDLABELEDIT message on the main window proc as it be the ENDLABELEDIT:
Code:
case HLEBP_ENDLABELEDIT:
{
char bff[512];
//get the new text
SendMessage(hlEdit,WM_GETTEXT,(WPARAM)sizeof(bff),(LPARAM)bff);
/setup the new item text, don't modify the item index
ihleb.lvi.pszText=bff;
ihleb.lvi.cchTextMax=strlen(bff);
SendMessage(llista,LVM_SETITEM,0,(LPARAM)&ihleb.lvi);
}
break;
Just make some more implementations like the escape or return key press to quit the label editing.
I'm sure that can be done in a better way, or in a most elegant way; but for the moment hope that helps.
Niara