
Nguyên bản được gửi bởi
fms17
Được rồi thôi, vì tôi biết trước, biết cả câu trả lời. Trong regedit.exe :
- có cái bạn tìm (SysListView32) và
- có cái bạn cần tương tác sendMessage
Tách từ một CT thật có tiếng tăm (tìm khóa và hiện thị nó trên regEdit), winApi
REHWnd
= FindWindow
("RegEdit_RegEdit",
null);//...
lvHwnd
= FindWindowEx
(REHWnd,
0,
"SysListView32",
null);//...
SendMessage(lvHwnd, LVM_Msg, p1, p2);
Coi như là thông báo đến mọi người :
Nếu bạn không san sẻ điều bạn đã biết
Ai người trợ giúp những khó khăn đang cần
//Xem yêu cầu trên
Bạn có thể cho mình tham khảo code của truơng trình này không?, mình đã có thể select nhưng double click hoặc right click thì chưa được 
Code:
public static voi SendDoubleClick(IntPtr lstview, int item)
{
const int dwBufferSize = 1024;
int dwProcessID;
string retval;
bool bSuccess;
IntPtr hProcess = IntPtr.Zero;
IntPtr lpRemoteBuffer = IntPtr.Zero;
IntPtr lpLocalBuffer = IntPtr.Zero;
IntPtr threadId = IntPtr.Zero;
try
{
lpLocalBuffer = Marshal.AllocHGlobal(dwBufferSize);
// Get the process id owning the window
threadId = new IntPtr(GetWindowThreadProcessId(lstview, out dwProcessID));
if ((threadId == IntPtr.Zero) || (dwProcessID == 0))
throw new ArgumentException("hWnd");
// Open the process with all access
hProcess = OpenProcess(ProcessAccessFlags.All, false, dwProcessID);
if (hProcess == IntPtr.Zero)
throw new ApplicationException("Failed to access process");
// Allocate a buffer in the remote process
lpRemoteBuffer = VirtualAllocEx(hProcess, IntPtr.Zero, new IntPtr(dwBufferSize), AllocationType.Commit,
MemoryProtection.ReadWrite);
if (lpRemoteBuffer == IntPtr.Zero)
throw new SystemException("Failed to allocate memory in remote process");
// Fill in the LVITEM struct, this is in your own process
// Set the pszText member to somewhere in the remote buffer,
// For the example I used the address imediately following the LVITEM stuct
NMITEMACTIVATE nmitem = new NMITEMACTIVATE();
nmitem.hdr.code = NM_DBLCLK;
nmitem.hdr.idFrom = lstview;
nmitem.hdr.hwndFrom = threadId;
nmitem.iItem = item;
nmitem.iSubItem = 0;
IntPtr tmp = new IntPtr(0);
SendMessage(lstview, LVM_GETITEMPOSITION, new IntPtr(item), lpRemoteBuffer);
bSuccess = ReadProcessMemory(hProcess, lpRemoteBuffer, lpLocalBuffer, dwBufferSize, out tmp);
if (!bSuccess)
throw new SystemException("Failed to read from process memory");
POINT tmpPOINT = new POINT();
Marshal.PtrToStructure((IntPtr)lpLocalBuffer, tmpPOINT);
nmitem.ptAction = tmpPOINT;
// Copy the local LVITEM to the remote buffer
bSuccess = WriteProcessMemory(hProcess, lpRemoteBuffer, ref nmitem,
Marshal.SizeOf(typeof(NMITEMACTIVATE)), out tmp);
if (!bSuccess)
throw new SystemException("Failed to write to process memory");
// Send the message to the remote window with the address of the remote buffer
SendMessage(threadId, 0x004E, lstview, lpRemoteBuffer);
}
finally
{
if (lpLocalBuffer != IntPtr.Zero)
Marshal.FreeHGlobal(lpLocalBuffer);
if (lpRemoteBuffer != IntPtr.Zero)
VirtualFreeEx(hProcess, lpRemoteBuffer, 0, FreeType.Release);
if (hProcess != IntPtr.Zero)
CloseHandle(hProcess);
}
}