1

我收到了奇怪的范围错误:'TVM_SETBKCOLOR' was not declared in this scope和类似'TreeView_SetBkColor' was not declared in this scope的 . 我不知道为什么会这样:

  • 我已经包括commctrl.h
  • 其他树视图宏工作正常(如TreeView_DeleteItem
  • 自动完成识别并完成TreeView_SetBkColor,所以这不是拼写问题
  • 我很好地阅读了文档

这是适用窗口的片段。一切正常,直到我尝试更改tvw_filelist_变量的背景。

void PnlTree::Init(HWND hwnd0, const char * superclassname0) {
    tvw_filelist_ = CreateWindowEx (0,
            superclassname0, NULL,
            TVS_HASLINES | TVS_LINESATROOT | TVS_HASBUTTONS | WS_CHILD | WS_VISIBLE,
            0, 0, 0, 0,
            hwnd0, (HMENU) IDC_TVWFILELIST, NULL, NULL
            );

    txt_blurb0_ = CreateWindowEx (0,
            TEXT("STATIC"), "Drag files and folders into this pane.",
            SS_CENTER | SS_CENTERIMAGE | WS_CHILD | WS_VISIBLE,
            0, 0, 0, 0,
            hwnd0, NULL, NULL, NULL
            );

    txt_blurb1_ = CreateWindowEx (0,
            TEXT("STATIC"), "Press DELETE to remove an entry.",
            SS_CENTER | SS_CENTERIMAGE | WS_CHILD | WS_VISIBLE,
            0, 0, 0, 0,
            hwnd0, NULL, NULL, NULL
            );

    HFONT hFont = CreateFont(15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "Segoe UI");

    ::SendMessage(txt_blurb0_, WM_SETFONT, (WPARAM) hFont, 0);
    ::SendMessage(txt_blurb1_, WM_SETFONT, (WPARAM) hFont, 0);

    // Everything works perfectly, if this line is commented out.
    TreeView_SetBkColor(tvw_filelist_, RGB(235, 235, 235));
}

//
//
//
void PnlTree::RemoveItem(WPARAM wParam) {
    if (wParam == VK_DELETE) {
        TreeView_DeleteItem(tvw_filelist_, TreeView_GetSelection(tvw_filelist_));
    }
}

我也试过

::SendMessage(tvw_filelist_, TVM_SETBKCOLOR, 0, RGB(235, 235, 235));

但我得到同样的错误。这是怎么回事?

(环境:代码::块,MinGW,Win7 x64)

4

1 回答 1

2

仅当应用程序指定必须在目标系统上安装 Internet Explorer 4 或更高版本时,才定义TVM_SETBKCOLOR消息及其关联的TreeView_SetBkColor()宏。

换句话说,_WIN32_IE预处理器符号必须设置为0x0400或更大。

头文件的相关部分(CommCtrl.hWindows SDK 版本 7.0A 中的第 5752 到 5792 行)是:

#if (_WIN32_IE >= 0x0400)

/* [get/set item height...] */

#define TVM_SETBKCOLOR              (TV_FIRST + 29)
#define TreeView_SetBkColor(hwnd, clr) \
    (COLORREF)SNDMSG((hwnd), TVM_SETBKCOLOR, 0, (LPARAM)(clr))

#define TVM_SETTEXTCOLOR              (TV_FIRST + 30)
#define TreeView_SetTextColor(hwnd, clr) \
    (COLORREF)SNDMSG((hwnd), TVM_SETTEXTCOLOR, 0, (LPARAM)(clr))

#define TVM_GETBKCOLOR              (TV_FIRST + 31)
#define TreeView_GetBkColor(hwnd) \
    (COLORREF)SNDMSG((hwnd), TVM_GETBKCOLOR, 0, 0)

#define TVM_GETTEXTCOLOR              (TV_FIRST + 32)
#define TreeView_GetTextColor(hwnd) \
    (COLORREF)SNDMSG((hwnd), TVM_GETTEXTCOLOR, 0, 0)

/* [get/set scroll time...] */

/* [get/set insert mark color...] */

#endif  /* (_WIN32_IE >= 0x0400) */
于 2012-11-07T07:30:36.643 回答