Вопрос

I'm getting the strange scope error: 'TVM_SETBKCOLOR' was not declared in this scope and similar 'TreeView_SetBkColor' was not declared in this scope. I can't figure out why this is happening:

  • I have included commctrl.h
  • Other treeview macros work fine (like TreeView_DeleteItem)
  • Autocomplete recognizes and finishes TreeView_SetBkColor so it's not a spelling problem
  • I read the documentation pretty well

Here's a snippet from the applicable window. Everything is working fine, until I try to change the background of the tvw_filelist_ variable.

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_));
    }
}

I've also tried

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

but I get the same error. What's going on?

(Environment: Code::Blocks, MinGW, Win7 x64)

Это было полезно?

Решение

The TVM_SETBKCOLOR message and its associated TreeView_SetBkColor() macro are only defined if the application specifies that Internet Explorer 4 or later must be installed on the target system.

In other words, the _WIN32_IE preprocessor symbol must be set to 0x0400 or greater.

The relevant parts of the header file (lines 5752 to 5792 of CommCtrl.h in version 7.0A of the Windows SDK) are:

#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) */
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top