使用 winapi 或 mfc 从 .NET 应用程序列表控件中获取项目名称

Get item names from a .NET applications list control using winapi or mfc(使用 winapi 或 mfc 从 .NET 应用程序列表控件中获取项目名称)

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

问题描述

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

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.

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

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.

但是我不知道如何访问列表本身,以便我可以阅读其中的项目.我已经在Panel2"句柄上尝试了 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.

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

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

Axilles 在评论中提到它可能是用 .NET 编写的,是否可以使用 http://reflector.red-gate.com/download.aspx?TreatAsUpdate=1 ?

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++ 是一个出色的工具,但它不支持 .Net.我建议在应用程序上尝试 UISpy.exe 以查看它能够找到比 Spy++ 更多的元素.UISpy.exe 位于 http://msdn.microsoft.com/en-us/library/ms727247.aspx 还有 ManagedSpy.exe http://msdn.microsoft.com/en-us/magazine/cc163617.aspx

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

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

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).

如果列表实际上是 Windows 演示表单 (WPF) 列表,您可能必须利用 .Net UIAutomation 类来访问列表的内容.UIAutomation 记录在这里:http://msdn.microsoft.com/en-us/库/ms747327.aspx

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

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

UISpy.exe is now obsolete according to MSDN docs:

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

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

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

本文标题为:使用 winapi 或 mfc 从 .NET 应用程序列表控件中获取项目名称