这个代码可以修改其他程序的listview的节点值,于是乎我想能不能修改一个dbgrid。用 Spy++ 抓了个dbgrid的句柄 测试,未果! 大家伙别忙看看
这个代码可以修改其他程序的listview的节点值,于是乎我想能不能修改一个dbgrid。用 Spy++ 抓了个dbgrid的句柄 测试,未果! 大家伙别忙看看 问题在哪??谢谢
procedure TForm1.btn1Click(Sender: TObject);var PID,t:LongWord; fh,hwnd,hProcess:Thandle; iItem:Integer; lvitem:TLVITEM; str_MyItemText:PChar; plvitem,p_MyItemText:Pointer;begin {fh:=FindWindow('#32770','Windows 任务管理器'); hwnd:=fh; hwnd:=FindWindowEx(hwnd,0,'#32770',0); hwnd:=FindWindowEx(hwnd,0,'SysListView32',0);} if edt1.Text='' then Exit; hwnd:=StrToInt(edt1.Text); if hwnd=0 then ShowMessage('尚未启动程序!') else begin Caption:=IntToStr(hwnd); GetWindowThreadProcessId(hwnd, @PID); hProcess:=OpenProcess(PROCESS_ALL_ACCESS,false,PID); if hProcess=0 then ShowMessage('获取进程句柄操作失败') else begin plvitem := VirtualAllocEx(hProcess, nil, sizeof(LVITEM), MEM_COMMIT, PAGE_READWRITE); p_MyItemText := VirtualAllocEx(hProcess, nil, 12, MEM_COMMIT, PAGE_READWRITE); if (plvitem=nil) or (p_MyItemText=nil) then ShowMessage('无法分配内存') else begin //ShowMessage('本演示程序将更改TaskManager中第6个项目中第1列的内容。'); str_MyItemText:='555'; iItem:=2; lvitem.iSubItem:=1; lvitem.pszText:=PChar(Integer(p_MyItemText)); //lvitem.pszText:=str_MyItemText; WriteProcessMemory(hProcess, p_MyItemText, str_MyItemText, 12, t); WriteProcessMemory(hProcess, plvitem, @lvitem, sizeof(LVITEM), t); SendMessage(hwnd, LVM_SETITEMTEXT, iItem, Integer(plvitem)); end; end; end;end;