mardi 1 décembre 2015

How to handle click events on a Windows treeview items

How can I handle individual items being clicked in a MS Windows treeview ?

My windows proc has :

LRESULT CALLBACK WndProcTreeView(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {
PAINTSTRUCT paintStruct;
HDC hDC;

switch (message)
{
case WM_PAINT:
{
    hDC = BeginPaint(hwnd, &paintStruct);
    EndPaint(hwnd, &paintStruct);
    break;
}

case WM_NOTIFY:
{
    switch (reinterpret_cast<LPNMHDR>(lParam)->code) {
    case NM_CLICK:
        MessageBox(nullptr, "click", "click", MB_OK);
    }
}
default:
{
    return DefWindowProc(hwnd, message, wParam, lParam);
    break;
}
}

Which outputs a message box when I click on the treeview control. How can I handle individual elements ?

Example of a treeview item being added to the list :

std::string vTxt = std::string("Vertex count : ") + std::to_string(mesh.v.size());
tvinsert.hInsertAfter = mesh_items[mesh_items.size() - 1];
tvinsert.hParent = mesh_items[mesh_items.size() - 1];
tvinsert.item.mask = TVIF_TEXT;
tvinsert.item.pszText = (LPSTR)vTxt.c_str();
mesh_items_sub.push_back((HTREEITEM)SendMessage(hwnd, TVM_INSERTITEM, 0, (LPARAM)&tvinsert));

I have seen using SendDlgItemMessage instead (which gives an ID as LOWORD(wParam) inside the windows proc) but it requires IDs set in a resource file - which I don't know how to create.

Aucun commentaire:

Enregistrer un commentaire