2

快速提问...

我正在使用 win32 (VC++) 中的树视图。

我想删除为树视图提供的选择工具。谁能告诉在树视图的AfterSelect 事件上发布了什么窗口消息。

电视也有复选框。所以禁用鼠标点击不是一个选项......

提前致谢...

- 瓦伦

更多信息 我被困在另一个点。我的 win32 应用程序本质上是一个无模式对话框 - 使用 CreateDialog 和 ShowWindow。获得 TVN_SELCHANGING 后,当我返回 1 时,它不起作用。我认为在绕过 Windows 消息之前会调用默认的 wndproc。我现在该怎么办?

4

3 回答 3

3

我遇到了这个问题,一旦它已经发生,我就反转了选择。无论如何,如果您没有对此做出反应,那么应该不会有任何副作用。

case WM_NOTIFY:     
    {
        if(wParam == IDC_TREE_MC)
        {
            LPNMHDR lpnmh = (LPNMHDR) lParam;
            TVHITTESTINFO ht = {0};

            if ((lpnmh->code  == NM_CLICK) && (lpnmh->idFrom == IDC_TREE_MC)) // For Treeview Check Box Check Event
            {
                DWORD dwpos = GetMessagePos();

                ht.pt.x = GET_X_LPARAM(dwpos);
                ht.pt.y = GET_Y_LPARAM(dwpos);
                MapWindowPoints(HWND_DESKTOP, lpnmh->hwndFrom, &ht.pt, 1);

                TreeView_HitTest(lpnmh->hwndFrom, &ht);

                if(TVHT_ONITEMSTATEICON & ht.flags)
                    PostMessage(hDlg, UM_CHECKSTATECHANGE, (WPARAM)lpnmh->hwndFrom, (LPARAM)ht.hItem);
                else
                    TreeView_SelectItem(lpnmh->hwndFrom, NULL);
            }
            else if ((lpnmh->code  == TVN_SELCHANGED ) && (lpnmh->idFrom == IDC_TREE_MC))
                TreeView_SelectNode(lpnmh->hwndFrom, NULL);
        }
        break;
    }
于 2014-01-03T22:08:03.980 回答
0

删除为树视图提供的选择工具

你能澄清一下吗?

您想阻止用户更改选择吗?

如果您真的想这样做,请在父窗口中插入 WM_NOTIFY 案例处理程序,检查 NMTREEVIEW 代码成员(lParam 是指向 NMTREEVIEW 的指针)。

如果代码是 TVN_SELCHANGING,如果您想阻止选择更改,则返回 1。返回 0 将导致选择更改。

于 2013-01-09T01:11:35.740 回答
0

int CALLBACK WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { hWndDialog = CreateDialog(hInstance, MAKEINTRESOURCE(IDD_MAIN), NULL, WndProc);

if (hWndDialog != NULL)
{
    ShowWindow(hWndDialog, SW_SHOW);
}

while(GetMessage(&Msg, NULL, 0, 0))
{
    if(!IsDialogMessage(hWndDialog, &Msg))
    {
        TranslateMessage(&Msg);
        DispatchMessage(&Msg);
    }
}
return 0;

}

INT_PTR CALLBACK WndProc(HWND hDlg, UINT 消息, WPARAM wParam, LPARAM lParam) { UNREFERENCED_PARAMETER(lParam); switch (message) { case WM_INITDIALOG: return (INT_PTR)TRUE;

case WM_COMMAND:
    switch(LOWORD(wParam))
    {
    case IDC_BTN_REFRESH:
        RefreshButtonHandler();             
        break;
    case IDC_BTN_ADD_INSTALL:
        AddInstallBtnHandler();
        break;
    case IDOK:
    case IDCANCEL:
        DestroyWindow(hDlg);
        PostQuitMessage(0);
        return (INT_PTR)TRUE;
        break;  
    }
case WM_NOTIFY:     
    {
        if(wParam == IDC_TREE_MC)
        {
            LPNMHDR lpnmh = (LPNMHDR) lParam;
            TVHITTESTINFO ht = {0};

            if ((lpnmh->code  == NM_CLICK) && (lpnmh->idFrom == IDC_TREE_MC)) // For Treeview Check Box Check Event
            {
                DWORD dwpos = GetMessagePos();

                ht.pt.x = GET_X_LPARAM(dwpos);
                ht.pt.y = GET_Y_LPARAM(dwpos);
                MapWindowPoints(HWND_DESKTOP, lpnmh->hwndFrom, &ht.pt, 1);

                TreeView_HitTest(lpnmh->hwndFrom, &ht);

                if(TVHT_ONITEMSTATEICON & ht.flags)
                    PostMessage(hDlg, UM_CHECKSTATECHANGE, (WPARAM)lpnmh->hwndFrom, (LPARAM)ht.hItem);
                else
                    TreeView_SelectItem(lpnmh->hwndFrom, NULL);
            }
            else if ((lpnmh->code  == TVN_SELCHANGING ) && (lpnmh->idFrom == IDC_TREE_MC))
                return (INT_PTR)TRUE;
        }
        break;
    }
case UM_CHECKSTATECHANGE:
    {
        //Handle TreeView Check State Event
    }
    break;
}
return (INT_PTR)FALSE;

}

抱歉格式不好...我睡眠不足:-)

于 2013-01-10T10:30:13.710 回答