需要列表控制 LVM_SETTOPINDEX

Jab*_*cky 6 winapi mfc comctl32

列表视图控件具有LVM_GETTOPINDEX允许获取最顶层可见项的索引的消息。

现在我需要设置最上面的可见项目,但令人惊讶的是没有任何 LVM_SETTOPINDEX消息是自然的。

有没有一种简单干净的方法来设置最上面的项目?

我的列表控件始终处于报告模式。

Jab*_*cky 1

这个函数的作用是:

void SetTopIndex(CListCtrl & listctrl, int topindex)
{
  int actualtopindex = listctrl.GetTopIndex();
  int horspacing;
  int lineheight;
  listctrl.GetItemSpacing(TRUE, &horspacing, &lineheight);

  CSize scrollsize(0, (topindex - actualtopindex) * lineheight);
  listctrl.Scroll(scrollsize);
}
Run Code Online (Sandbox Code Playgroud)

这里没有进行参数清理。

感谢 David Heffernan 和 Remy Lebeau 给了我这个想法。