繁体   English   中英

使用 C++ 在浏览器中打开 HTML 文件

[英]Open HTML file in browser using C++

我正在使用 Visual Studio 在 C++ 中编写程序,我需要做的是创建一个 HTML 文件并在其中写入数据,然后我希望在浏览器中打开它。 现在我可以创建文件,写东西但我无法打开它,任何人都可以帮忙吗?

这可能是一个简单的问题,但我只是一个初学者。

#include <windows.h>

void main()
{  
   ShellExecute(NULL, "open", "http://dreamincode.net",
                NULL, NULL, SW_SHOWNORMAL);
}

http://www.dreamincode.net/code/snippet357.htm您只需将代码中显示的上述 URL 替换为您的 html 文件的绝对路径。 当然可以用变量来完成。

    void CAboutDlg::OnButton1()
{
    CString strDir;
    char buffer[255];

    GetCurrentDirectory(255, buffer);

    strDir = buffer;

    strDir.TrimRight("\\");
    strDir += "\\";
    strDir += _T("helpindex.html");

    if( 32 >= (int)ShellExecute( NULL, "open", strDir, NULL, NULL, SW_SHOWNORMAL))
    {
        AfxMessageBox("::ShellExecuteFailed"
             " to open this link!");
    }  
}

试试这个……对我来说很好用……

#include <windows.h>
void main()
{ 
    LPCTSTR helpFile = "c\help\helpFile.html";
    ShellExecute(NULL, "open", helpFile, NULL, NULL, SW_SHOWNORMAL);
    system("PAUSE");
}

如果您正在为 UWP 开发:

    Windows::System::Launcher::LaunchUriAsync(ref new Uri("https://www.google.com"));

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM