我收到奇怪的范围错误:'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));
但我得到同样的错误。这是怎么回事?
(环境:Code::Blocks,MinGW,Win7 x64)
最佳答案
仅当应用程序指定必须在目标系统上安装Internet Explorer 4或更高版本时,才定义TVM_SETBKCOLOR消息及其关联的TreeView_SetBkColor()宏。
换句话说,_WIN32_IE
预处理器符号必须设置为0x0400
或更大。
头文件的相关部分(Windows SDK 7.0A版中CommCtrl.h
的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) */