在新桌面中创建的WPF窗口未正确显示 [英] WPF window created in new desktop is not displayed correctly

查看:87
本文介绍了在新桌面中创建的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();
}


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


The only clue i found is  http://social.expression.microsoft.com/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窗口未正确显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆