在新桌面中创建的WPF窗口未正确显示

编程入门 行业动态 更新时间:2024-10-09 23:21:17
本文介绍了在新桌面中创建的WPF窗口未正确显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

您好,我正在尝试实现一个冻结UAC确认对话框之类的后台桌面的窗口. 经过一番搜索,我发现了一种方法,该方法需要创建一个新的桌面并启动一个新的线程来打开窗口. 但是我发现WPF窗口无法在新桌面中正确显示,仅显示窗口框架而不呈现内容.(但winform没问题)

Hi, I'm trying to implement a window which freezes background desktop like UAC confirmation dialog. After some search I found a way which needs to create a new desktop and start a new thread to open the window. But I found that the WPF window cannot be displayed correctly in the new desktop, only showing the window frame without rendering contents.(but no problem with winform)

部分代码:

//导入user32.dll桌面api 公共静态外部IntPtr CreateDesktop(字符串桌面,字符串设备,IntPtr devmode,int标志,intdesiredAccess,IntPtr lpsa); 公共静态外部布尔SetThreadDesktop(IntPtr桌面); 公共静态外部布尔SwitchDesktop(IntPtr桌面); ...

// import user32.dll desktop api public static extern IntPtr CreateDesktop(string desktop, string device, IntPtr devmode, int flags, int desiredAccess, IntPtr lpsa); public static extern bool SetThreadDesktop(IntPtr desktop); public static extern bool SwitchDesktop(IntPtr desktop); ...

//创建新的桌面 IntPtr newDesktop = WinApi.CreateDesktop("NewDesktop",null,IntPtr.Zero,0,WinApi.GENERIC_ALL,IntPtr.Zero);

// create new desktop IntPtr newDesktop = WinApi.CreateDesktop("NewDesktop", null, IntPtr.Zero, 0, WinApi.GENERIC_ALL, IntPtr.Zero);

//切换到新的桌面 WinApi.SetThreadDesktop(newDesktop); WinApi.SwitchDesktop(newDesktop);

// switch to new desktop WinApi.SetThreadDesktop(newDesktop); WinApi.SwitchDesktop(newDesktop);

//开始新线程以打开窗口 线程newDesktopThread =新线程(this.DoWorkInNewDesktop); newDesktopThread.SetApartmentState(ApartmentState.STA); newDesktopThread.CurrentCulture = Thread.CurrentThread.CurrentCulture; newDesktopThread.CurrentUICulture = Thread.CurrentThread.CurrentUICulture; newDesktopThread.Start(); newDesktopThread.Join();

// start new thread to open window Thread newDesktopThread = new Thread(this.DoWorkInNewDesktop); newDesktopThread.SetApartmentState(ApartmentState.STA); newDesktopThread.CurrentCulture = Thread.CurrentThread.CurrentCulture; newDesktopThread.CurrentUICulture = Thread.CurrentThread.CurrentUICulture; newDesktopThread.Start(); newDesktopThread.Join();

...

private void DoWorkInNewDesktop() { MyWindow win = new MyWindow(); win.Show(); System.Windows.Threading.Dispatcher.Run(); }

private void DoWorkInNewDesktop() { MyWindow win = new MyWindow(); win.Show(); System.Windows.Threading.Dispatcher.Run(); }

我发现的唯一线索是 social.expression.microsoft/Forums/hi-IN/wpf/thread/193c592f-a02f-4956-84f7-e3b9242b89be ,它表示WPF渲染线程不在新桌面中,而是似乎没有办法在桌面上切换渲染线程...

The only clue i found is social.expression.microsoft/Forums/hi-IN/wpf/thread/193c592f-a02f-4956-84f7-e3b9242b89be, which says the WPF rendering thread is not in the new desktop, but there seems no way to switch rendering thread desktop...

任何建议都值得赞赏.谢谢.

Any suggestion is appreciated. Thanks.

推荐答案

您好,geogu,

Hi geogu,

谢谢您的发帖.

对不起,由于系统问题而造成的延迟.

Sorry for the delay due to system issue.

您的帖子将交付给专业专家,以帮助您解决问题.

You post will deliver to an professional expert to help you resolve your issue.

谢谢您的理解.

祝你有美好的一天.

更多推荐

在新桌面中创建的WPF窗口未正确显示

本文发布于:2023-10-10 22:08:13,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1479895.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:桌面   正确   窗口   WPF

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!