How to change the content of an Item in the ListView control of other programs | 您所在的位置:网站首页 › nova系列移动 › How to change the content of an Item in the ListView control of other programs |
Reprinted from: http://www.vckbase.com/index.php/wv/1274 One: Program Description This time I will introduce how to change the content of an Item in the ListView control of other programs. I have written two similar articles. This is the third article. LVM_GETITEMTEXT message" is similar, the difference is: 1. The message sent is different: the former is to read the content of pszText - send LVM_GETITEMTEXT; this time is to set pszText, it should send LVM_SETITEMTEXT; 2. The role of the string buffer is different: the former pItem is used to receive ITEMTEXT, we can read its content through the ReadProcessMemory function; and in this article, p_MyItemText is used to store the ITEMTEXT we want to set, and write it with the WriteProcessMemory function into the target program. As a demonstration, the following program will change the content of column 1 in item 6 of the TaskManager. The effect picture after the program runs: Two: specific practice //////////////////////////////////////////////////// /////////////////// * _ * Send LVM_SETITEMTEXT * Copyright (C) 2005 Tianjin Zhao Chunsheng * 2005.10.28 * http://timw.yeah.net * http://timw.126.com * This program is applicable to: Win2KP+SP4[Windows TaskManager(5.0.2195.6620)] * WinXP+SP1[Windows TaskManager] * The code passed the test of Win2000P+SP4 + VC6+SP6 */ ///////////////////////////////////////////////// ////////////////////// #include < windows.h > #include < commctrl.h > int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { HWND hwnd; int iItem = 0 ; LVITEM lvitem, * plvitem; DWORD PID; HANDLE hProcess; char *p_MyItemText; // The address used to store TEXT in the target program // The pszText member is the pointer to a null-terminated // string containing the new text; it can also be NULL. // The above information is obtained from the API manual, so in this example the string length cannot be >= 12, // to ensure that there is a NULL after the string. char str_MyItemText[ 12 ]={ 0 }; strcpy(str_MyItemText, " Tianjin Zhao Chunsheng " ); hwnd =FindWindow( " #32770 " , " Windows Task Manager " ); hwnd =FindWindowEx(hwnd, 0 , " #32770 " , 0 ); hwnd =FindWindowEx(hwnd, 0 , " SysListView32 " , 0 ); if (! hwnd) MessageBox(NULL, " [Windows Task Manager] has not started yet! " , " Error! " ,NULL); else { GetWindowThreadProcessId(hwnd, & PID); hProcess =OpenProcess(PROCESS_ALL_ACCESS, false ,PID); if (! hProcess) MessageBox(NULL, " Failed to obtain process handle operation! " , " Error! " , NULL); else { plvitem =(LVITEM*)VirtualAllocEx(hProcess, NULL, sizeof (LVITEM), MEM_COMMIT, PAGE_READWRITE); p_MyItemText =( char *)VirtualAllocEx(hProcess, NULL, 12 , MEM_COMMIT, PAGE_READWRITE); if ((!plvitem)||(! p_MyItemText)) MessageBox(NULL, " Unable to allocate memory! " , " Error! " , NULL); else { MessageBox(NULL, " This demonstration program will change the content of column 1 in the sixth item in TaskManager. " , " Prompt " , NULL); iItem = 5 ; // 5 is the sixth here (from zero) lvitem.iSubItem = 0 ; // ditto lvitem.pszText = p_MyItemText; WriteProcessMemory(hProcess, p_MyItemText, &str_MyItemText, 12 , NULL); WriteProcessMemory(hProcess, plvitem, &lvitem, sizeof (LVITEM), NULL); // Send LVM_SETITEMTEXT message to the target program SendMessage(hwnd, LVM_SETITEMTEXT, (WPARAM)iItem, (LPARAM)plvitem); } } } // Release memory CloseHandle(hwnd); CloseHandle(hProcess); VirtualFreeEx(hProcess, plvitem, 0 , MEM_RELEASE); VirtualFreeEx(hProcess, p_MyItemText, 0 , MEM_RELEASE); return 0 ; }3. The above code passed the test of Win2000P+SP4+VC6+SP6. Other articles: How to send LVM_GETITEMTEXT message to ListView control of other programs How to select an Item in the ListView control of other programs |
CopyRight 2018-2019 实验室设备网 版权所有 |