简体   繁体   English

使用C ++在新窗口中启动URL(Windows)

[英]Launch a URL in a NEW window using C++ (Windows)

How can I launch a URL in a NEW window using C++ (Windows only)? 如何使用C ++在Windows窗口中启动URL(仅限Windows)?

The straight-forward approach seems to open a new tab in an existing browser window. 直接的方法似乎在现有的浏览器窗口中打开一个新选项卡。 (Or, if tabbed browsing is disabled, the new URL hijacks the existing browser window). (或者,如果禁用选项卡式浏览,则新URL会劫持现有的浏览器窗口)。

This is for a (large) desktop app, using MFC and Qt. 这适用于使用MFC和Qt的(大型)桌面应用程序。

I've used this for showing locally generated html in the default browser, in my case filename is something like "c:\\temp\\page.html", perhaps replacing filename with the URL might work?? 我用这个在默认浏览器中显示本地生成的html,在我的情况下,文件名是“c:\\ temp \\ page.html”,或许用URL替换filename可能会工作?

ShellExecute(NULL,"open",filename,NULL,NULL,SW_SHOWNORMAL);

Updated: http://support.microsoft.com/kb/224816 更新: http //support.microsoft.com/kb/224816

How ShellExecute Determines Whether to Start a New Instance When ShellExecute looks through the registry, it looks for the shell\\open subkey. ShellExecute如何确定是否启动新实例当ShellExecute查看注册表时,它会查找shell \\ open子项。 If the shell\\open\\ddeexec key is defined, then a Dynamic Data Exchange (DDE) message with the specified application IExplore and the topic WWW_OpenURL is broadcast to all top-level windows on the desktop. 如果定义了shell \\ open \\ ddeexec键,则会将具有指定应用程序IExplore和主题WWW_OpenURL的动态数据交换(DDE)消息广播到桌面上的所有顶级窗口。 The first application to respond to this message is the application that goes to the requested URL. 响应此消息的第一个应用程序是转到请求的URL的应用程序。 If no application responds to this DDE message, then ShellExecute uses the information that is contained in the shell\\open\\command subkey to start the application. 如果没有应用程序响应此DDE消息,则ShellExecute使用shell \\ open \\ command子项中包含的信息来启动该应用程序。 It then re-broadcasts the DDE message to go to the requested URL. 然后它重新广播DDE消息以转到请求的URL。

So it looks like you have no control over opening a new window. 所以看起来你无法控制打开一个新窗口。 Whatever browser currently running can handle opening it in whatever way they want. 无论当前运行的浏览器能够以任何他们想要的方式打开它。

This is controlled by windows. 这是由windows控制的。 The only way to explicitly tell it to open in a new browser window is to spawn the browser explicitly and give it the url. 明确告诉它在新浏览器窗口中打开的唯一方法是显式生成浏览器并为其提供URL。

Here's a link to some code that will open a URL in a new browser . 这是一些代码的链接, 这些代码将在新浏览器中打开URL The code looks up the default application for handling an HTML document and then explicitly opens that application with a ShellExecute call. 代码查找用于处理HTML文档的默认应用程序,然后使用ShellExecute调用显式打开该应用程序。

You can't in general. 你不能一般。 The user's browser is free to do whatever the user wants it to do. 用户的浏览器可以自由地做任何用户想要做的事情。

One way to achieve your desired effect might be to embed a particular browser in a window of your own (say, the IE ActiveX control) and have that render your URL. 实现所需效果的一种方法可能是将特定浏览器嵌入到您自己的窗口中(例如,IE ActiveX控件)并使其呈现您的URL。

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

相关问题 使用c ++在Mac OS X上启动“新电子邮件”窗口 - Launch “new email” window on Mac OS X with c++ Windows上的C ++:在没有窗口的情况下使用DirectInput? - C++ on Windows: Using DirectInput without a window? 在Windows 7上以编程方式启动sfx存档(使用_execv)? (C ++) - Programmatically launch sfx archive on Windows 7 (using _execv)? (C++) 在 C++ 中使用 Windows 组合引擎的透明窗口 - transparent window using Windows Composition engine in c++ 使用带有 c++ 的 uiautomation 在 windows 上获取子 window 按钮的标题 - Get caption of child window button on windows using uiautomation with c++ Sublime Text启动单独的命令窗口(C / C ++) - Sublime Text launch separate command window (C/C++) 是否可以在不使用 C++ 的情况下打开 URL<windows.h> ? - Is it possible to open URL in C++ WITHOUT using <windows.h>? 使用c ++创建一个新的Windows注册表项 - Create a new windows registry key using c++ 如何在没有控制台窗口的情况下从C ++启动.jar文件 - How to launch .jar file from C++ WITHOUT console window 执行控制台应用程序,而不创建在屏幕上闪烁的新控制台窗口(C ++,Windows) - Execute console applications without creating a new console window flickering on the screen (C++, Windows)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM