Dave's Brain

Browse - Programming Tips - I want to display a local HTML file in the default browser.

Date: 2008jul17
Platform: win32
OS: Windows
Language: C/C++
Keywords: web, page, webpage, local

Q.  I want to display a local HTML file in the default browser.
How can I simply do that.

A.  Simulate the user clicking on it like this:

BOOL WebPage(const HWND hwndParent, LPCSTR szUrl) { return ShellExecute(hwndParent, "open", szUrl, NULL, NULL, SW_SHOWNORMAL) > (HINSTANCE) 32; } BOOL LocalWebPage(const HWND hwndParent, LPCSTR szFile) { char szUrl[MAX_PATH*2+1]; _snprintf(szUrl, sizeof(szUrl), "file://%s", szFile); return WebPage(hwndParent, szUrl); } ExampleUse() { LocalWebPage(NULL, "c:\\temp\\hello.htm"); }

Add a comment

Sign in to add a comment
Copyright © 2008-2017, dave - Code samples on Dave's Brain is licensed under the Creative Commons Attribution 2.5 License. However other material, including English text has all rights reserved.