Jump to content
  • Advertisement
Sign in to follow this  
B_Knight

how do i open a htlm file from a program?

This topic is 4748 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Advertisement
You need to be more precise?

You simply want to open the file?

A good old fopen should do the job

Share this post


Link to post
Share on other sites
If you simply want to know how to prepare the file for reading with your application and the file you want to open is in the same directory as your executable, you will only need the name of the HTML file for your program to be able to open it.

In C#, you can use the StreamReader class to read in the file.

In C++, you can use ifstream to read the file.

I hope this helps.

Share this post


Link to post
Share on other sites
Do you mean that you'd like to open and read an url on the internet?
If so look up the following functions in MSDN:

InternetOpen
InternetOpenUrl / FtpOpenFile
InternetQueryDataAvailable
InternetReadFile
InternetWriteFile
InternetCloseHandle

Using these you'd be able to read html/gopher/ftp files and write to ftp's.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster

//use these to open window with html - game documentation

#include

//-----------------------------------------------------------------------------------------------------------------

bool GetRegString(LPSTR pszKey, LPSTR pszValue, LPBYTE pszData)
{
HKEY hKey;
DWORD dwDataSize = MAX_PATH - 1;
DWORD dwValueType = REG_SZ;
DWORD openOK, queryOK;

openOK = RegOpenKeyEx(HKEY_LOCAL_MACHINE, pszKey, 0, KEY_QUERY_VALUE, &hKey);

queryOK = RegQueryValueEx(hKey, pszValue, 0, &dwValueType, pszData, &dwDataSize);

if (pszData[dwDataSize] != '\0') pszData[dwDataSize] = '\0';

RegCloseKey(hKey);

return(openOK == ERROR_SUCCESS && queryOK == ERROR_SUCCESS);
} // end of GetRegString()

//-----------------------------------------------------------------------------------------------------------------

DWORD launchProcess(char* sProcName, char* sCmdLine) // for launchBrowser()
{
STARTUPINFO wtTSRinfo;
PROCESS_INFORMATION procInfo;

memset(&wtTSRinfo, 0, sizeof(wtTSRinfo)); // zero the contents of the structure
wtTSRinfo.cb = sizeof(wtTSRinfo); // size of(STARTUPINFO)

if (CreateProcess(sProcName, // lpApplicationName
sCmdLine, // lpCommandLine
NULL, // Process LPSECURITY_ATTRIBUTES
NULL, // Thread LPSECURITY_ATTRIBUTES
FALSE, // BOOL bInheritHandles
0, // creation flags
NULL, // inherit environmental vars from parent
NULL, // inherit CWD from parent
&wtTSRinfo, // gives info about new process
&procInfo)) // receives info about new process
{
// If your program does not make use of the handles for the new process and
// its primary thread, you should close both right away. Otherwise, even if the
// PROCESS_INFORMATION structure is a local variable and goes out of scope, abandoning
// whatever it contained, the two object entries remain in your process’s object table
// and the system counts them as open handles.
CloseHandle(procInfo.hProcess); // get rid of handles of new process
CloseHandle(procInfo.hThread);
return(TRUE);
}
else
{
int x = GetLastError();
MessageBox(NULL, "Process failed to create.", "Error", MB_OK);
MessageBox(NULL, sProcName, sCmdLine, MB_OK);
return(FALSE);
}
} // end of launchProcess()

//-----------------------------------------------------------------------------------------------------------------

void launchBrowser(char *docpath)
{
char htmlAssocReg[] = "Software\\CLASSES\\.htm";
char htmlAssoc[_MAX_PATH] = {0};
char browserReg[_MAX_PATH] = {0};
char launchString[4096];
char browser[_MAX_PATH];

GetRegString(htmlAssocReg, NULL, (LPBYTE)htmlAssoc); // get browser name

wsprintf(browserReg, "Software\\CLASSES\\%s\\shell\\open\\command", htmlAssoc);

GetRegString(browserReg, NULL, (LPBYTE)browser); // get browser exe

char* bws = strtok(browser, "\"");

wsprintf(launchString, "%s %s", bws, docpath); // build command line

launchProcess(NULL, launchString);
} // end of launchBrowser()

//-----------------------------------------------------------------------------------------------------------------

VOID help_window()
{
MessageBox(NULL,"Opening Documentation window with your favorite browser", "Fatal Error", MB_OK);

//launchBrowser("http://www.wildtangent.com/download/");
launchBrowser("C:\\mssdk\\samples\\Multimedia\\Direct3D\\Project\\help_doc.htm");
}

//-----------------------------------------------------------------------------------------------------------------

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
He said htlm, not html.

Share this post


Link to post
Share on other sites
Quote:
Original post by Anonymous Poster
*snippet removed*


That's quite a masochistic way of doing
ShellExecute(NULL, "open", "C:\\mssdk\\samples\\Multimedia\\Direct3D\\Project\\help_doc.htm", NULL, NULL, 0);
[grin]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!