取得&设置SysListView32控件项 [英] Getting & Setting SysListView32 control items

查看:142
本文介绍了取得&设置SysListView32控件项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

以下是我正在工作的C#代码,用于从另一个应用程序的syslistview32控件获取项目文本.

Hello,

below is my working C# code for getting item text from syslistview32 control of another application.

IntPtr SysListView32 = Value[1];
            int count = SendMessage(SysListView32, LVM_GETITEMCOUNT,0,"0");
           
            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;
            lvi.pszText = Marshal.AllocHGlobal(512);
            IntPtr ptrLvi = Marshal.AllocHGlobal(Marshal.SizeOf(lvi)); 
            Marshal.StructureToPtr(lvi, ptrLvi, false);
            SendMessage(SysListView32, LVM_GETITEM, IntPtr.Zero, ptrLvi);  // Extract the text of the specified item 
            string itemText = Marshal.PtrToStringAuto(lvi.pszText); 

[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; 
} 



我有SysListview32控件的正确句柄,因为我将正确的项目计数为"4",并且目标SysListView32应用程序如下所示

http://www.freeimagehosting.net/t/f07ab.jpg

但是当我尝试发送消息以使用
获取项目时,具有此syslistview32控件的目标应用程序始终挂起



I have correct handle for SysListview32 control cause I am getting correct items count as "4" & Target SysListView32 application is shown as below

http://www.freeimagehosting.net/t/f07ab.jpg

But target aplication having this syslistview32 control always hanged when I tried to sendmessage for getting item with

lvi.iItem = 1; 
lvi.iSubItem = 0;
SendMessage(SysListView32, LVM_GETITEM, IntPtr.Zero, ptrLvi);  


我认为这一定与内存分配问题有关.
有人可以告诉我上面的代码在哪里出错吗?

注意:Visual Studio&在我的Win 7 pc中以管理员身份运行的目标SysteListView32控件应用程序.


I think it has to with something memmory allocation problem.
can anybody please tell me where did I make mistake in above code?

Note : Both visual studio & Target SysteListView32 control application running as administrator in my Win 7 pc.

推荐答案



要访问另一个应用程序中的内存(和控件内容),您需要使用win32 API函数准备一个可供其他进程访问的内存缓冲区.如果您从自己的进程传递了指针,则无法从目标进程访问此指针所指向的内存区域.

我不记得API名称,可能virtualalloc是其中之一.

BR,
约瑟夫(Jozsef)
Hi

To access memory (and the control contents) in another application you need to use win32 API functions to prepare a memory buffer that is accessible for the other process. If you pass a pointer from your own process, the memory area pointed to by this pointer cannot be accessed from the target process.

I do not remember the API names, possibly virtualalloc is one of them.

BR,
Jozsef


这篇关于取得&设置SysListView32控件项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆