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

标签 c++ winapi mfc

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

我想扫描列表,这样我就可以对数据做一些算法。

使用 Spy++ 我发现保存此列表的内容名为“Panel2”,我可以使用 EnumChildWindows 获取此列表的句柄(其类为“WindowsForms10.Window.8.app”)。

但是我不知道如何访问列表本身以便阅读它的项目。我已经尝试在“Panel2”句柄上使用 EnumChildWindows 并输出所有这些窗口的标题,但它们都是空的。

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

Axilles 在评论中提到它可能是用 .NET 编写的,如果可以使用类似 http://reflector.red-gate.com/download.aspx?TreatAsUpdate=1 的方式获取列表的 controlID/句柄?

   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

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

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

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

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

关于c++ - 使用 winapi 或 mfc 从 .NET 应用程序列表控件中获取项目名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13286178/

相关文章:

c++ - CreateFile 失败并出现错误 ERROR_SHARING_VIOLATION

c++ - 使用 C++ 获取 Windows 文件信息

c++ - 如何在MFC中的CArray中使用CArray?

winapi - 如何找到MFC使用父进程的主HWND句柄

c++ - AfxGetAppName() 返回垃圾字符

c++ - 从原始指针创建 shared_ptr

windows - 为什么我要使用无限超时的 Sleep()?

c++ - fopen() 在内部更改我的文件名?

c++ - 将 bool 转换为位域中的位

c++ - 32位机器如何计算 double