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);
}
|