Home > Software engineering >  VB use SendMessage to obtain external application listView control content
VB use SendMessage to obtain external application listView control content

Time:09-20

ListCount=SendMessage (HWND, LVM_GETITEMCOUNT, 0, 0)
ItemText=SendMessage (hlist LVM_GETITEMTEXT, 0, 0)
ListCount can normal access lines, but get ItemText will go wrong

CodePudding user response:

To get the data not so simple!

Need to work, with several other apis to complete,

Refer to this:
Read listview control the content of other software

CodePudding user response:

For reference only, although not VB6:
//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
//read the Item in the ListView
//hWindow as the goal of the ListView handle
//strlist used to store the Item of ListView string
//http://www.ccrun.com
//by ccrun (old demon)
//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Void MyGetListViewItem (HWND hWindow, TStrings * strlist)
{
Const nMaxLen=1023;
Char szBuf [nMaxLen + 1];
Char buf [nMaxLen + 1];

Int nLVItemCount;
Int nColumns;
DWORD dwProcessID;
HANDLE hProcess;
HANDLE hHeaderCtrl;
LVITEM lvItemLocal;
HDITEM hdItemLocal;
DWORD dwBytesRead dwBytesWrite;
Bool bSuccess, bWriteOK;

//note: this article from www.ccrun.com, by ccrun (old demon), reprint please indicate the source,
//this article from the c + + Builder research - http://www.ccrun.com/article.asp? I=583 & amp; D=eahk4z
//in order to prevent some irresponsible ZhuanZaiZhe, so out of it, join statements in your code, please forgive me,

GetWindowThreadProcessId (hWindow, & amp; DwProcessID);
HProcess=OpenProcess (PROCESS_ALL_ACCESS, FALSE, dwProcessID);
if(! HProcess)//get a handle to the specified process
return;
//allocate storage space within a specified process
LPVOID lpTextRemote=VirtualAllocEx (hProcess, NULL, nMaxLen + 1, MEM_COMMIT, PAGE_READWRITE);
LPVOID lpListItemRemote=VirtualAllocEx (hProcess, NULL, sizeof (LVITEM), MEM_COMMIT, PAGE_READWRITE);
LPVOID lpHeadItemRemote=VirtualAllocEx (hProcess, NULL, sizeof (HDITEM), MEM_COMMIT, PAGE_READWRITE);
If ((! LpTextRemote) | | (! LpListItemRemote) | | (! LpHeadItemRemote))//can't allocate storage space within a specified process
return;

NLVItemCount=ListView_GetItemCount (hWindow);
HHeaderCtrl=ListView_GetHeader (hWindow);
NColumns=Header_GetItemCount (hHeaderCtrl);
If (nColumns<=0) {
NColumns=1;
} else {
Buf [0]=0;
for (int j=0; JZeroMemory (szBuf, nMaxLen + 1);
BWriteOK=WriteProcessMemory (hProcess, lpTextRemote, (LPVOID) szBuf, nMaxLen + 1, (LPDWORD) & amp; DwBytesWrite);
if(! BWriteOK)//write memory error
return;
HdItemLocal. Mask=HDI_TEXT;
HdItemLocal. CchTextMax=nMaxLen;
HdItemLocal. PszText=(LPTSTR lpTextRemote);
DwBytesWrite=0;
BWriteOK=WriteProcessMemory (hProcess, lpHeadItemRemote, (LPVOID) & amp; HdItemLocal, sizeof (HDITEM), (LPDWORD) & amp; DwBytesWrite);
if(! BWriteOK)//write memory error
return;

SendMessage (hHeaderCtrl HDM_GETITEM, (WPARAM), j (LPARAM) lpHeadItemRemote);
BSuccess=ReadProcessMemory (hProcess, lpTextRemote szBuf, nMaxLen + 1, & amp; DwBytesRead);
//storage space to read text from the specified process
if(! BSuccess)//
to read text within a specified processreturn;
If (j> 0) strcat (buf, "|");
Strcat (buf, AnsiString (szBuf). C_str ());
}
Strlist - & gt; Add (buf);
}
//strlist - & gt; Add (" the number of Columns ListView: "+ String (nColumns));
//strlist - & gt; Add (" -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- ");

for (int i=0; iBuf [0]=0;
for (int j=0; JZeroMemory (szBuf, nMaxLen + 1);
BWriteOK=WriteProcessMemory (hProcess, lpTextRemote, (LPVOID) szBuf, nMaxLen + 1, (LPDWORD) & amp; DwBytesWrite);
if(! BWriteOK)//write memory error
return;
LvItemLocal. IItem=I;
LvItemLocal. ISubItem=j;
LvItemLocal. Mask=LVIF_TEXT;
LvItemLocal. CchTextMax=nMaxLen;
LvItemLocal. PszText=(LPTSTR lpTextRemote);
DwBytesWrite=0;
BWriteOK=WriteProcessMemory (hProcess, lpListItemRemote, (LPVOID) & amp; LvItemLocal, sizeof (LVITEM), (LPDWORD) & amp; DwBytesWrite);
if(! BWriteOK)//write memory error
return;
SendMessage (hWindow LVM_GETITEMTEXT, (WPARAM), I (LPARAM) lpListItemRemote);
BSuccess=ReadProcessMemory (hProcess, lpTextRemote szBuf, nMaxLen + 1, & amp; DwBytesRead);
//storage space to read text from the specified process
if(! BSuccess)//
to read text within a specified processreturn;
If (j> 0) strcat (buf, "|");
Strcat (buf, AnsiString (szBuf). C_str ());
}
Strlist - & gt; Add (buf);
}//end of the for (I)
//release of storage space within a specified process
VirtualFreeEx (hProcess, lpHeadItemRemote, 0, MEM_RELEASE);
VirtualFreeEx (hProcess, lpListItemRemote, 0, MEM_RELEASE);
VirtualFreeEx (hProcess, lpTextRemote, 0, MEM_RELEASE);
//close the handle to the specified process
The CloseHandle (hProcess);
}
  • Related