PDA

View Full Version : گرفتن تمام آیتمهای List View با API



roox_3000
سه شنبه 31 اردیبهشت 1392, 13:02 عصر
با سلام

دوستان من هندل یک List View رو در یک برنامه دیگه میگیرم و با این کد آیتم شو را میگیرم و میخوام اونارو در یک List view در برنامه خودم قرار دهم




private const int LVM_FIRST = 0x1000;
private const int LVM_GETITEMCOUNT = LVM_FIRST + 4;
private const int LVM_GETITEM = LVM_FIRST + 75;
private const int LVIF_TEXT = 0x0001;

[DllImport("user32.dll", CharSet = CharSet.Auto)]

private static extern IntPtr SendMessage(IntPtr hWnd, int Msg, IntPtr wParam,IntPtr lParam);
[StructLayoutAttribute(LayoutKind.Sequential)]

private struct LVITEM

{

public uint mask;
public int iItem;
public int iSubItem;
public uint state;
public uint stateMask;
public IntPtr pszText;
public int cchTextMax;
public int iImage;
public IntPtr lParam;
}






و در قسمت رویداد باتن :





LVITEM lvi = new LVITEM();
lvi.mask = LVIF_TEXT;
lvi.cchTextMax = 512;
lvi.iItem = 1; // the zero-based index of the ListView item
lvi.iSubItem = 0; // the one-based index of the subitem, or 0 if this
// structure refers to an item rather than a subitem
lvi.pszText = Marshal.AllocHGlobal(512);
// Send the LVM_GETITEM message to fill the LVITEM structure
IntPtr ptrLvi = Marshal.AllocHGlobal(Marshal.SizeOf(lvi));
Marshal.StructureToPtr(lvi, ptrLvi, false);
SendMessage(hListView, LVM_GETITEM, IntPtr.Zero, ptrLvi);
// Extract the text of the specified item
string itemText = Marshal.PtrToStringAuto(lvi.pszText);





اما در قسمت آخر که Item بصورت string دریافت میشه هیچ Item رو از برنامه نمیگیره !!!

در این مورد راهنمایی میخواستم

با تشکر

roox_3000
سه شنبه 31 اردیبهشت 1392, 17:22 عصر
از مدیرای انجمن خواهش میکنم راهنمایی کنن
کله پروژام لنگه همین موضوعه

roox_3000
چهارشنبه 01 خرداد 1392, 18:24 عصر
راه حلشو پیدا کردم , از 2 راه میشه این کارو کرد

1- با استفاده از تابع LVM_GETITEM و OpenProcesses و ایجاد یک حافظه مجازی داخل برنامه با virtualallocex

2- با استفاده از فریم ورک UIAutomation Client که به عنوان Reference میتونید به پروژتون اضافه کنید و ازش استفاده کنید