English 中文(简体)
在列表视图中插入时禁用自动拼贴( Win32 API, C)
原标题:Disable autoscrolling when inserting in List View (win32 API, C)

我在我的通用控制列表中插入一个项 像这样:

void InsertRow (HWND hWnd, char *col1, char *col2)
{
    LV_ITEM     lvItem;

    lvItem.mask = 0;
    lvItem.iItem = 0;
    lvItem.iSubItem = 0;
    lvItem.iItem = ListView_InsertItem (hWnd, &lvItem);

    lvItem.mask = LVIF_TEXT;
    lvItem.pszText = col1;
    lvItem.cchTextMax = strlen (lvItem.pszText);
    ListView_SetItem (hWnd, &lvItem);

    lvItem.iSubItem = 1;
    lvItem.pszText = col2;
    lvItem.cchTextMax = strlen (lvItem.pszText);
    ListView_SetItem (hWnd, &lvItem);
}

并且工作很好, 但这是一个麻烦, 因为垂直滚动会回到列表的顶端, 所以如果我在看一个项目, 并调用这个插入函数, 我失去了我的视野, 并且不得不手动滚动回滚, 使我的程序无法工作 。

我怎样才能防止这种自动滚动?

我在C区编程,以直接(而非MFC)的 Win32 API为主。

P.D.: ListView style: LVS_SINGLESEL | WS_BORDER | WS_TABSTOP | WS_CHILD|WS_VISIBLE|WS_BORDER|WS_VSCROLL|WS_HSCROLL|LVS_REPORT

问题回答

一种方式是获取当前的顶部位置,插入新项目,然后(按比例)滚回到保存的顶部位置。

  1. Call ListView_GetItem to get the index of the item you want to watch
  2. Call ListView_EnsureVisible(hWnd, index_you_want_to_watch, TRUE) every time you insert a new row.

如果您可以将 ListView 切换到虚拟模式( 应用 < code> LVS_ OWNERDATA 样式, 然后使用 < code> LVN_ GETDISPINFO 通知向 ListView < listerView_ SetTroitCountEx () 来添加/ 插入/ 重新移动项目。 它有一个 < code> LVSICF_ NOSCROLL 标志来防止滚动 。





相关问题
Fastest method for running a binary search on a file in C?

For example, let s say I want to find a particular word or number in a file. The contents are in sorted order (obviously). Since I want to run a binary search on the file, it seems like a real waste ...

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

Tips for debugging a made-for-linux application on windows?

I m trying to find the source of a bug I have found in an open-source application. I have managed to get a build up and running on my Windows machine, but I m having trouble finding the spot in the ...

Trying to split by two delimiters and it doesn t work - C

I wrote below code to readin line by line from stdin ex. city=Boston;city=New York;city=Chicago and then split each line by ; delimiter and print each record. Then in yet another loop I try to ...

Good, free, easy-to-use C graphics libraries? [closed]

I was wondering if there were any good free graphics libraries for C that are easy to use? It s for plotting 2d and 3d graphs and then saving to a file. It s on a Linux system and there s no gnuplot ...

Encoding, decoding an integer to a char array

Please note that this is not homework and i did search before starting this new thread. I got Store an int in a char array? I was looking for an answer but didn t get any satisfactory answer in the ...

热门标签