我试图访问ListView控件(位于一个对话框内)在另一个应用程序获取ListView控件的内容,并从控制中获取数据。下面是我写了Win32代码(与appropiate评论):Win32-从另一个应用程序
HWND hListView32 = hRoot; //HANDLE to the ListView control within the Dialog, having class name - "SysListView32"
int cnt = (int) ::SendMessage(hListView32, LVM_GETITEMCOUNT, 0, 0L); //returns CORRECT item count of the ListView Control
int nItem=0,nRes;
for(int nItem=0;nItem<cnt;nItem++)
{
LVITEM LvItem; // ListView Item struct
char Text[255]={0};
char Temp[255]={0};
char Temp1[255]={0};
memset(&LvItem,0,sizeof(LvItem));
LvItem.mask=LVIF_TEXT;
LvItem.iSubItem=1; //Trying to get the 2nd Colomn text
LvItem.pszText=Text; //Does not returns any Text, after the below SendMessage is executed???
LvItem.cchTextMax=256;
LvItem.iItem=nItem;
nRes = (int)::SendMessage(hListView32,LVM_GETITEMTEXT, nItem, (LPARAM)&LvItem);
DWORD dd = ::GetLastError(); //returns 0
}
虽然代码执行,我不是从控制中得到任何数据。但是,我能够从控件中检索正确的项目计数,但没有数据。
另一种方法也许是使用的MSAA钩来获取数据。但那将是一个漫长而繁琐的过程。这里没有想法了。请帮助。
谢谢,
'LVM_GETITEMTEXT'只能在同一个进程内工作。见例如大卫Heffernans评论[这太问题(http://stackoverflow.com/questions/4857411/listview-getitem-macro-lv-getitemtext-returns-empty-string-while-getting-ano)。 – user786653