【问题标题】:Start another application on top most in tablet mode在平板电脑模式下在最上面启动另一个应用程序
【发布时间】:2023-03-09 22:31:01
【问题描述】:

当我从我的应用程序运行另一个 .exe 时,它​​会在后台启动,并且不会在屏幕顶部显示应用程序,而是显示平板电脑模式主屏幕,它在正常桌面模式下工作正常,但当我在 Windows 10 中运行它时平板电脑模式然后它不会显示在顶部它在后台启动。

我使用过 myWindow.TopMost = true; ,但它在 Windows 10 平板电脑模式下无法正常工作。

用来启动exe文件的代码

Process p = new Process();
p.StartInfo.RedirectStandardOutput= true;
p.RedirectStandardInput = true;
p = Process.Start("myApp.exe");
p.WaitForExit();

我正在调用(启动)的 exe 是我自己的 exe 应用程序(它不是系统应用程序),我正在 Windows 10 上运行应用程序。

它仅在平板电脑模式下无法正常工作(而且我的应用程序仅针对平板电脑)。

任何帮助表示赞赏..!

【问题讨论】:

  • 您应该设置处理您的应用程序的父窗口。如果不设置,TopMost = true 将无济于事。

标签: c# wpf windows-10 desktop-application tablet-pc


【解决方案1】:

当我遇到类似情况时,(它与平板电脑或 windows-10 无关。只有 WPFTopMost 标签有相似之处)我会告诉你我如何解决它: 我希望 FilterWindow 总是 TopMost(但仅在我的应用程序上,而不是在我的操作系统中的整个应用程序集上)

查看我的代码。希望对你有帮助。

private void OnFilter() {   
    var filterViewModel = ViewModelLocator.FilterViewModel;

    /* ... */

    var filterWindow = new FilterWindow {
        DataContext = filterViewModel,
        Owner = GetParentWindow()
    };
    filterWindow.ShowDialog();
    SelectedIndex = 0;
}

private static Window GetParentWindow() {
    Window parent = null;

    var activeWindows = Application.Current.Windows.Cast<Window>().Where(item => (item).IsActive).ToList();
    if (activeWindows.Any()) {
    parent = activeWindows[activeWindows.Count - 1];
    }
    else {
        foreach (var item in 
            Application.Current.Windows.Cast<object>().Where(item => item.GetType().Name == typeof(RibbonWindow).Name)) {
            parent = item as Window;
        }
    }
    return parent;
}

魔法是Owner = GetParentWindow()
没有设置Owner FilterWindow 有一个荒谬的行为。

希望对您有所帮助。如果没有,我将删除回复。 (它不适合评论)

【讨论】:

  • 感谢您的回复,但是我应该在哪里编写此代码,因为我正在寻找新的 exe(应用程序)。当我发布我的代码以从 Process.Start() 调用 exe..??
  • @RahulShirphule,如果是进程,您应该处理来自 WinApi 的窗口函数。 SetParent 应该可以解决问题(当您启动 EXE 时)查看更多信息:msdn.microsoft.com/en-us/library/windows/desktop/…。此外,这对您来说也可能很有趣:stackoverflow.com/questions/8312535/…
  • 是的,我浏览了这个链接..但是没有提到何时调用 setParent 方法,表示在 p = Process.Start("myApp.exe"); 之前或之后p.WaitForExit();我都试过了,但都没有运气……你知道吗……?请告诉我?
  • @RahulShirphule,我在这里看到(附加的 url),SetParent 在进程启动后被调用。 stackoverflow.com/questions/10434658/… 。另外,在这里:stackoverflow.com/questions/15393707/…
【解决方案2】:

Moerfi 使用Owner = GetParentWindow() 的解决方案效果非常好,非常感谢这个解决方案。它还解决了我遇到的另一个问题。

我正在为 Surface 3 编写一个在平板电脑模式下在 Windows 10 Pro 上运行的应用程序,每当关闭 MessageBox 或自定义对话框控制框时,Win 10 就会进入开始菜单,而不是返回父窗口。

好像一旦打开对话框控件,父窗口就会被置于后台,所以当对话框控件关闭时,Win 10 没有活动窗口可以切换回来。

在子对话框控件上设置所有者解决了这个问题。非常感谢。

【讨论】:

    猜你喜欢
    • 2019-04-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-12
    • 1970-01-01
    • 2023-03-03
    • 2014-09-18
    • 1970-01-01
    相关资源
    最近更新 更多