您好,我正在尝试实现一个冻结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窗口未正确显示
发布评论