简体   繁体   English

如何从C#程序关闭所有打开的窗口?

[英]How do i close all open windows from my C# program?

Hi i have a windows application where i show a webbrowser, i have a button that removes the browser (its a preview) and goes to another "view" in my application (another tab). 嗨,我有一个Windows应用程序,其中显示了一个Web浏览器,我有一个按钮,该按钮可删除浏览器(预览)并转到应用程序中的另一个“视图”(另一个选项卡)。 My problem is that my users are getting advanced, they build HTML with links (and its ok) but the links may spawn new browser windows (IExplorer), and my button needs to close these windows, but how? 我的问题是我的用户越来越先进,他们使用链接构建HTML(确定没有问题),但是这些链接可能会产生新的浏览器窗口(IExplorer),并且我的按钮需要关闭这些窗口,但是如何?

I have made some code to traverse all eht windows that ends with "Windows Internet Explorer", ahd it all seems to work - but how do i close them? 我已经编写了一些代码来遍历所有以“ Windows Internet Explorer”结尾的窗口,嗯,这一切似乎都奏效-但是如何关闭它们? I am trying to do it like this: 我正在尝试这样做:

SendMessage((int)hWnd, WM_SYSCOMMAND, SC_CLOSE, 0);

It seems to work, but the browser pops up a dialog asking me if i want to close the tab of all the tabs...how to work around/solve this? 它似乎可行,但是浏览器弹出一个对话框,询问我是否要关闭所有选项卡的选项卡...如何解决/解决这个问题?

Cheers, 干杯,

  1. walking over all top level iE windows and closing them is a bad idea, unless you are guaranteed users can't launch ie and browse the Internet on their own. 遍历所有顶级iE窗口并关闭它们是一个坏主意,除非可以保证用户无法启动ie并自行浏览Internet。 Otherwise, you might actually lose user data (say an email or a blog post the user has been working on in the last half an hour) 否则,您实际上可能会丢失用户数据(例如,用户在过去半小时内一直在处理的电子邮件或博客文章)

  2. You can't easily work around that dialog without modifying the per-user IE settings. 如果不修改每个用户的IE设置,就无法轻松解决该对话框。 Your other option is to look for that dialog and click the yes button, but that would be fragile and is not guaranteed to continue working if the user upgrades to IE9. 您的另一个选择是查找该对话框,然后单击“是”按钮,但这将是脆弱的,并且如果用户升级到IE9,则不能保证继续工作。

  3. You could potentially prevent opening links in new window by listening to BeforeNavigate event and allowing only navigations that are guaranteed to happen in your control. 您可以通过侦听BeforeNavigate事件并仅允许确保在控件中发生的导航来阻止在新窗口中打开链接。 However, there are scenarios where IE might still decide to open new window. 但是,在某些情况下IE可能仍会决定打开新窗口。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何让我的程序说我接近或远离答案然后再次输入? C# - How to make my program say that I'm close or far from the answer and then to input it again? C# 如何从C#中的第一个程序打开另一个程序? - How to open another program from my first in C#? C#如何保存程序以打开文件? - C# How do I save the program to open a file in? 如何重置我的程序(关闭并再次打开)-Windows Mobile - How to reset my program (close.. and Open again) - Windows mobile 退出程序时如何关闭所有窗体和进程(浏览器)窗口? - How can i close all forms and processes(explorer) windows when i quit my program? 如何在C#中打开Windows 7事务处理文件 - How do I open a Windows 7 transacted file in C# 如何使我的存储变量可供所有类访问? (UWP Windows.Storage,C#) - How do I make my stored variables accessible to all classes? (UWP Windows.Storage, C#) 如何从C#中打开“我的文档”和“我的电脑”文件夹? - How do I open the “My Documents” and “My Computer” folders from C#? 如何从 c# 中的 ViewModelHelper 关闭窗口(XAML)? - How do I close a window(XAML) from the ViewModelHelper in c#? 如何通过我的C#程序在我的计算机上打开所有* .xml文件? - how to open all *.xml files on my computer by my C# program?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM