首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >发送消息TVM_EDITLABEL失败

发送消息TVM_EDITLABEL失败
EN

Stack Overflow用户
提问于 2020-06-14 13:47:10
回答 1查看 103关注 0票数 1

TreeView_EditLabel(tv, item)失败(返回零)。

item是有效的,并且是treeview中的唯一项。

有什么问题吗?有什么先决条件吗?还是根本不起作用?

我在Windows 10上。

下面是一个最小可重现性的例子

代码语言:javascript
复制
#include <windowsx.h>
#include <CommCtrl.h>
#include <assert.h>

#pragma comment(lib, "Comctl32.lib")

HWND hTv;
HTREEITEM hItem;
auto className = L"someclass";

ATOM                MyRegisterClass(HINSTANCE hInstance);
void                InitInstance(HINSTANCE, int);
LRESULT CALLBACK    WndProc(HWND, UINT, WPARAM, LPARAM);

int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow)
{
    InitCommonControls();
    MyRegisterClass(hInstance);
    InitInstance(hInstance, nCmdShow);
    MSG msg;
    while (GetMessage(&msg, nullptr, 0, 0)) {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }
    return (int)msg.wParam;
}
ATOM MyRegisterClass(HINSTANCE hInstance)
{
    WNDCLASSEXW wcex{};

    wcex.cbSize = sizeof(WNDCLASSEX);

    wcex.style = CS_HREDRAW | CS_VREDRAW;
    wcex.lpfnWndProc = WndProc;
    wcex.lpszClassName = className;

    return RegisterClassExW(&wcex);
}
void InitInstance(HINSTANCE hInstance, int nCmdShow)
{
    HWND hWnd = CreateWindowW(className, L"", WS_OVERLAPPEDWINDOW, 400, 400, 400, 400, nullptr, nullptr, hInstance, nullptr);
    assert(hWnd);

    hTv = CreateWindowW(WC_TREEVIEW, L"Tree View", WS_VISIBLE | WS_CHILD | WS_BORDER | TVS_HASLINES, 0, 0, 300, 300, hWnd, 0, 0, NULL);
    assert(hTv);
    {
        TVITEM tvi{};
        TVINSERTSTRUCT tvins{};
        tvi.mask = TVIF_TEXT;

        wchar_t name[] = L"item";
        tvi.pszText = name;

        tvins.item = tvi;
        hItem = TreeView_InsertItem(hTv, &tvins);
    }
    ShowWindow(hWnd, nCmdShow);
    SetFocus(hTv);
}

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch (message)
    {
    case WM_NOTIFY:
    {
        switch (reinterpret_cast<LPNMHDR>(lParam)->code)
        {
        case NM_CLICK:
            assert(TreeView_EditLabel(hTv, hItem));
            break;
        }
        break;
    }
    case WM_DESTROY:
        PostQuitMessage(0);
        break;
    default:
        return DefWindowProc(hWnd, message, wParam, lParam);
    }
    return 0;
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-06-14 14:13:49

树形视图控件需要设置艾德拉斯控件样式以支持树视图项的编辑标签。

您需要替换树形视图控件创建代码。

代码语言:javascript
复制
hTv = CreateWindowW(
    WC_TREEVIEW,
    L"Tree View",
    WS_VISIBLE | WS_CHILD | WS_BORDER | TVS_HASLINES,
    0, 0, 300, 300,
    hWnd,
    0,
    0,
    NULL);

在这方面:

代码语言:javascript
复制
hTv = CreateWindowW(
    WC_TREEVIEW,
    L"Tree View",
    WS_VISIBLE | WS_CHILD | WS_BORDER | TVS_HASLINES | TVS_EDITLABELS,
    0, 0, 300, 300,
    hWnd,
    0,
    0,
    NULL);

树视图控件概述概述在标题为树视图标签版的一节中提供了其他详细信息。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62373384

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档