//从外部listview取项目文本

import winex;
import process;

//桌面句柄
var hDskManager,hShellView = winex.findExists("Program Manager",,"Progman","SHELLDLL_DefView")

import win.ui.ctrl.listview;
listview = win.ui.ctrl.listview();
listview.hwnd = win.findEx(hShellView,0,"SysListView32");//桌面图标列表控件

//获取进程ID
var tid,pid = win.getThreadProcessId(listview.hwnd )

//创建进程对象
prcs = process( pid )

//声明外部EXE中的API函数
SendMessageByStruct_c = prcs.remoteApi("int(int,INT,int,struct &)","User32.dll","SendMessageA" )

//API需要用到的结构体
LVITEM = class {
INT mask;
int iItem;
int iSubItem;
INT state;
INT stateMask;
int pszText; //注意这里的string类型改成表示内存地址的整型
int cchTextMax;
int iImage;
int lParam;
int iIndent;
int iGroupId;
INT cColumns;
struct puColumns = ::POINT();
}
listview.getItemText = function ( row,col=1,len=100 ) {
var item = LVITEM();
item.mask = 0x1/*_LVIF_TEXT*/;
item.iSubItem = col-1;
item.pszText = prcs.malloc( len ) ; //在对方进程分配内存
item.cchTextMax = len

//大家可以比较一下listview的源码,控制自已的listview与外部exe的listview只有很小的区别
var len = SendMessageByStruct_c(owner.hwnd, 0x102D/*_LVM_GETITEMTEXT*/, row-1, item);

var str = prcs.readString(item.pszText,len)
prcs.mfree( item.pszText ); //释放在外部进程的内存

return str;
}

io.open()
var count = listview.count //桌面图标个数
for(i=1;count ){
io.print( listview.getItemText(i) )
}