代码之家  ›  专栏  ›  技术社区  ›  George Stocker NotMe

以编程方式在Microsoft RemoteApp中查找子窗口

  •  4
  • George Stocker NotMe  · 技术社区  · 14 年前

    背景

    我在用 SendKeys()

    Microsoft RemoteApp 允许用户通过RDP协议连接到应用程序,但它只显示应用程序窗口,而不是显示整个远程虚拟机。对于最终用户来说,在RemoteApp下运行的应用程序和在其桌面上运行的应用程序没有区别。

    我一直在使用ManagedSpy来确定.NET应用程序窗口的类名,以便使用Win32 API函数 FindWindowEx

    Process.GetProcessesByName() mstsc.exe :

    IntPtr hwndChild = IntPtr.Zero;
    Process[] processess = Process.GetProcessesByName("mstsc");
    IntPtr appHandle = IntPtr.Zero;
    
    foreach (Process p in processess)
    {
        if ((p.MainWindowHandle != IntPtr.Zero))
        {
            appHandle = p.MainWindowHandle;
        }
    }
    
    if (appHandle == IntPtr.Zero)
    {
        MessageBox.Show("Application is not Running.");
        return;
    }
    

    但是,我不能使用 芬德韦克斯

    让非托管代码告诉我windows mstsc.exe文件 mstsc.exe文件 它返回一个不同的类名,称为 RAIL_WINDOW

    alt text

    下面是我用来查找子窗口的代码:

    [DllImport("USER32.DLL")]
    public static extern bool SetForegroundWindow(IntPtr hWnd);
    
    [DllImport("user32.dll", SetLastError = true)]
    private static extern IntPtr FindWindowEx(IntPtr parentHandle, IntPtr childAfter, string className, string windowTitle);
    hwndChild = FindWindowEx(appHandle, IntPtr.Zero, "RAIL_WINDOW", "MyApplication (Remote)");
    SetForegroundWindow(hwndChild);
    

    1. 我可以使用Spy++突出显示应用程序的RemoteApp版本中的活动子窗口,然后 铁窗

    2. 有没有其他方法可以将键盘笔划发送到通过远程应用程序运行的应用程序?

    3 回复  |  直到 14 年前
        1
  •  2
  •   Phileosophos    14 年前

    知道微软是怎么做的,我敢打赌“rail窗口”只不过是一个愚蠢的本地代理,不需要对SendKeys发送的内容进行响应。我还没看过,但我敢打赌它最终会发送WM\u CHAR消息,一个愚蠢的代理可能不会费心回复这些消息。相反,尝试手动向它发送WM\u KEYUP和WM\u KEYDOWN消息,看看这是否有效,因为我希望它会发送这些消息和鼠标点击(以及其他什么),而不是翻译的版本。

        2
  •  0
  •   kyndigs    14 年前

    SendKeys()

    与其使用“SendKeys()”,不如寻找其他解决方案。

        3
  •  0
  •   Alexander V    10 年前

    您可能可以利用处理IMsTscAxEvents的优势: OnRemoteWindowDisplayed 事件,它在正确的时间为您提供正确的窗口句柄,而不调用FindWindowEx等。

    推荐文章