使用WinAPI或MFC从.NET应用程序列表控件获取项目名称 [英] Get item names from a .NET applications list control using winapi or mfc

查看:206
本文介绍了使用WinAPI或MFC从.NET应用程序列表控件获取项目名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以基本上我有这个软件以列表形式输出数据.感谢这里的评论,我们已经了解到它很可能是用.NET编写的.

我想扫描列表,以便可以对数据进行一些算法.

使用Spy ++,我发现保存此列表的标题为"Panel2",并且可以使用EnumChildWindows来获取此句柄(其类为"WindowsForms10.Window.8.app").

但是,我不知道如何进入列表本身,因此我可以阅读其项目.我已经在"Panel2"句柄上尝试了EnumChildWindows并输出了所有这些窗口的标题,但是它们都是空的.

panel2可以是实际列表吗?如果可以的话,我可以将其转换为(CListCtrl *)吗?

Axilles在评论中提到它可能是用.NET编写的,因此可以使用

Spy ++是出色的工具,但它不支持.Net.我建议也尝试在应用程序上尝试UISpy.exe,以查看它比Spy ++能够找到更多的元素.可以在 http://msdn.microsoft.com/zh-我们/library/ms727247.aspx ,并且还有ManagedSpy.exe http://msdn.microsoft.com/zh-cn/magazine/cc163617.aspx

可以通过将调试器附加到该应用程序(是Visual Studio还是WinDBG)来确定该应用程序是否是.Net应用程序;如果您还没有Visual Studio,我建议您使用VC ++的免费版本.不确定C#版本是否具有本机调试支持).另一种选择是利用Windows平台SDK中的Depends.exe,甚至利用来自 http://technet.microsoft.com/zh-cn/sysinternals/bb896653.aspx ,以查看将哪些DLL加载到进程中(即.Net应用程序将加载核心.Net DLL). /p>

如果该列表实际上是Windows Presentation Forms(WPF)列表,则可能必须使用.Net UIAutomation类来访问列表的内容. UIAutomation记录在这里: http://msdn.microsoft.com/zh-cn/library/ms747327.aspx

根据MSDN文档,UISpy.exe现在已过时:

注意Accessible Explorer和UI Spy工具已过时,不再可用.开发人员应改用Inspect或AccScope.

So basically i have this software which outputs data in a list form. Thanks to the comments here we have understood that it is most likely written in .NET.

I want to scan the list so i can do some algorithms on the data.

Using Spy++ i found that what holds this list is titled "Panel2" and i can get the handle to this (its class is "WindowsForms10.Window.8.app") using EnumChildWindows.

However i don't know how to get to the list itself so i can read its items. I have tried EnumChildWindows on the "Panel2" handle and outputting the caption of all those windows but they are all empty.

Can panel2 be the actuall list? If so could i just cast it to (CListCtrl*) ?

Axilles mentions in the comments that it probably is written in .NET, wold it be possible to get the controlID / handle to the list using something like http://reflector.red-gate.com/download.aspx?TreatAsUpdate=1 ?

   CWnd* mainWindow;
    CWnd* panel;
    CListCtrl* list;



BOOL CALLBACK findWindow( HWND hwnd,LPARAM lParam)
{
    char text[8];
    GetWindowText(hwnd,text,8);

    if(strcmp(text,"Fetcher") == 0)
    {
        mainWindow= CWnd::FromHandle(hwnd);

        return false;
    }

    return true;
}

BOOL CALLBACK findPanel(HWND hwnd,LPARAM lParam)
{

    char text[7];
    GetWindowText(hwnd,text,7);

    if(strcmp(text,"Panel2") == 0)
    {
        panel = CWnd::FromHandle(hwnd);

        return false;
    }

    return true;
}


void CAnalyzeDlg::OnBnClickedButton1()
{
    mainWindow = 0;

    while(mainWindow == 0)
    {
    ::EnumWindows(findWindow,0);
    }

    mainWindow ->ActivateTopParent();

    while(panel == 0) ::EnumChildWindows(mainWindow ->m_hWnd,findPanel,0);

    CWnd* pointTest = NULL;

    CString text = "";

    int xx = 337;
    int yy = 95;

    while(yy < 1024 && (pointTest == NULL || strcmp(text,"") == 0 || strcmp(text,"Panel2") == 0))
    {
        pointTest = mainWindow->ChildWindowFromPoint(CPoint(xx,yy));
        yy++;
        if(pointTest != 0)
            pointTest->GetWindowTextA(text);
    }



    if(strcmp(text,"") != 0)
        MessageBox(0,text,0); // This never shows

}

解决方案

Spy++ is an excellent tool, but it's not .Net aware. I suggest trying UISpy.exe on the application as well to see it is able to find more elements than Spy++. UISpy.exe can be found at http://msdn.microsoft.com/en-us/library/ms727247.aspx and there is ManagedSpy.exe as well http://msdn.microsoft.com/en-us/magazine/cc163617.aspx

You can be certain if the application is a .Net application or not by attaching a debugger to it (either Visual Studio or WinDBG; I'd recommend the free version of VC++ if you don't have Visual Studio already as I'm not sure that the C# version has native debugging support). Another option is to utilize depends.exe from the Windows Platform SDK or even just ProcessExplorer.exe from http://technet.microsoft.com/en-us/sysinternals/bb896653.aspx to see what DLLs are loaded into the process (i.e. a .Net app will have the core .Net DLLs loaded).

If the list is actually a Windows Presentation Forms (WPF) list you will likely have to utilize the .Net UIAutomation classes to access the list's contents. UIAutomation is documented here: http://msdn.microsoft.com/en-us/library/ms747327.aspx

Edit: UISpy.exe is now obsolete according to MSDN docs:

Note The Accessible Explorer and UI Spy tools are obsolete and no longer available. Developers should use Inspect or AccScope instead.

这篇关于使用WinAPI或MFC从.NET应用程序列表控件获取项目名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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