×

Loading...
Ad by
Ad by

Hey guys, I need help. Here is the problem: I put a ListView and a ImageList on a form, need to add add dropped file icon to listview, and encounter some problems...(Thanks in advance)...

Here is what i did:

Approach 1:
1. Add one icon to the ImageList
2. Set ListView.Icons to ImageList
3. Set ListView.OLEDropMode to 1
4. In ListView.OleDragDrop Event, add ...
___a) check if GetFormat(15) is true
___b) use SHGetFileInfo() to get drop file name
___c) Get Icon handle
___d) API Call: ImageList_ReplaceIcon(hImageList, -1, hIcon), and return value is valid (2)
___e) call ListView.ListItems.Add() to add new Item, failed, index of out of bound
___f) check ImageList.ListImages.Count, it is one, which means no new icon is added


Approach Two:
1. Add one icon to the ImageList
2. SendMessage(hListView, 0x1003, 0, hImageList), failed, return is not valid (0), which mean cannot associate the Imagelist with ListView.


Any suggestion?
Report

Replies, comments and Discussions:

  • 工作学习 / IT技术讨论 / Hey guys, I need help. Here is the problem: I put a ListView and a ImageList on a form, need to add add dropped file icon to listview, and encounter some problems...(Thanks in advance)...
    Here is what i did:

    Approach 1:
    1. Add one icon to the ImageList
    2. Set ListView.Icons to ImageList
    3. Set ListView.OLEDropMode to 1
    4. In ListView.OleDragDrop Event, add ...
    ___a) check if GetFormat(15) is true
    ___b) use SHGetFileInfo() to get drop file name
    ___c) Get Icon handle
    ___d) API Call: ImageList_ReplaceIcon(hImageList, -1, hIcon), and return value is valid (2)
    ___e) call ListView.ListItems.Add() to add new Item, failed, index of out of bound
    ___f) check ImageList.ListImages.Count, it is one, which means no new icon is added


    Approach Two:
    1. Add one icon to the ImageList
    2. SendMessage(hListView, 0x1003, 0, hImageList), failed, return is not valid (0), which mean cannot associate the Imagelist with ListView.


    Any suggestion?
    • up
    • /.
    • 救不了你。几年前我做过半年Delphi程序员,和这些冬冬打过交道,现在已经忘光了。
      • 谢谢。
    • try this control. You can do what ever you want. Very powerful. I did some very complex treeview/listview application base on that. It is very fast.
      • Thank you too, I might consider it if there is no workaround of the #$%^ ListView
    • 自己解决了。。
      1. Plain API call 得到的Image Count 与调用COM 接口得到的并不一样。
      2. MSDN 上说ImageList_ReplaceIcon() 中的第二个参数index 设置成-1表示把Image add to Imagelist, 这个没有错。但是新加入的Image通过COM接口访问不到。
      3. 解决办法:预先将Icon加入到ImageList。在OLEDragDrop 方法中用新hIcon的替换现有的icon,