Home > Software engineering >  Using the Windows API SendMessage send WM_NOTIFY failed to get the content of the virtual list
Using the Windows API SendMessage send WM_NOTIFY failed to get the content of the virtual list

Time:09-16

Think through the Windows API SendMessage across processes for another program of the data in the table, the table for a virtual form, form the class for ListView20WndClass, parent Window for the ThunderRT6FormDC, that can capture to the parent Window in SPY++ send WM_NOTIFY, message for LVN_GETDISPINFOA, through the Windows API, using SendMessage send WM_NOTIFY, get failure, in SPY++ monitoring is less than the signal, please expert help debug, thank you, on the code, specific information in code comments:

HWND form_hwnd=reinterpret_cast & lt; HWND> (0 x00101cf4);//handle to the parent window ThunderRT6FormDC
HWND list_hwnd=reinterpret_cast & lt; HWND> (0 x001b2506);//handle to the parent window ThunderRT6FormDC

Char item [512], * _item;
HANDLE hProcess;
DWORD PID;

LV_DISPINFOA LVD, * _lvd;

//by WM_GETTEXT parent window title, can get, normal SPY++ detected in the signal,
Int len=SendMessage (form_hwnd WM_GETTEXTLENGTH, 0, 0).
Char * buffer=new char [len + 1];
SendMessage (form_hwnd, WM_GETTEXT, + 1, len (lPARAM) buffer);

//get the parent window process ID
GetWindowThreadProcessID (form_hwnd, & amp; PID);
HProcess=OpenProcess (PROCESS_ALL_ACCESS, FALSE, PID);

//in the process of memory
_lvd=(LV_DISPINFOA *) VirtualAllocEx (hProcess, nullptr, sizeof (LV_DISPINFOA), MEM_COMMIT, PAGE_READWRITE);
_item=(char *) VirtualAllocEx (hProcess, nullptr, 512, MEM_COMMIT, PAGE_READWRITE);

//through LVM_GETITEMCOUNT access to table rows (normal access to, but also to monitoring to the message in SPY++)
Long long rows=SendMessage (list_hwnd LVM_GETITEMCOUNT, 0, 0).
//by LVM_GETHEADER handle to get the header () can be detected in SPY++ the message
HWND headers=(HWND) SendMessage (list_hwnd LVM_GETHEADER, 0, 0).
//get the number of columns (which can be normal access to)
Int cols=Header_GetItemCount (headers);

//assigned to NMHDR, message for LVN_GETDISPINFOA, the first line of the first column of text
LVD. HDR. HwndFrom=list_hwnd;
LVD. HDR. IdForm=0;
LVD. HDR. Code=LVN_GETDISPINFOA;
LVD. Item. Mask=LVIF_TEXT;
LVD. Item. CchTextMax=512;
LVD. Item. PszText=_item;
LVD. Item. ISubItem=0;
LVD. Item. The iItem=0;

//to write LVD into the target process
WriteProcessMemory (hProcess, _lvd, & amp; LVD, sizeof (LV_DISPINFOA));
//send a WM_NOTIFY message
//the message is sent failure, SPY++ monitoring is less than the parent window has the signal
SendMessage (form_hwnd WM_NOTIFY, (WPARAM) 0, (LPARAM) _lvd);
ReadProcessMemory (hProcess, _item, item, 512, 0).

The CloseHandle (HWND);
The CloseHandle (hProcess);
VirtualFreeEx (hProcess, _lvd, 0, MME_RELEASE);
VirtualFreeEx (hProcess, _item, 0, MME_RELEASE);
  •  Tags:  
  • API
  • Related