【发布时间】:2012-10-01 19:13:37
【问题描述】:
我正在尝试访问另一个应用程序中的 ListView 控件(位于对话框中),并从该控件中获取数据。这是我正在编写的 Win32 代码(带有适当的 cmets):
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只能在同一个进程中工作。参见例如David Heffernans 转至this SO question。
标签: winapi win32-process