home ‣ Windows programming tip: launching a browser
| 07 Aug 2002 · Tags: win32, c++ | ← newer • 545 of 588 • older → |
void LaunchIE(char *site) {
ShellExecute( GetDesktopWindow(), "", "iexplore", site, NULL, SW_SHOWNORMAL );
}
There's one problem with this code: it doesn't run on Windows 95 and 98 and those are still very popular. Fortunately, there is another way to do almost the same:
HANDLE JustCreateProcess(char *cmd, char *dir) {
PROCESS_INFORMATION ProcInfo={0,};
STARTUPINFO StartUp={0,};
StartUp.cb=sizeof(StartUp);
if (!CreateProcess(NULL, cmd, NULL, NULL, FALSE, 0, NULL, dir, ;&StartUp, &ProcInfo))
return NULL;
if (NULL != ProcInfo.hThread) CloseHandle( ProcInfo.hThread );
return ProcInfo.hProcess;
}
void LaunchIE(char *site) {
assert(site);
std::string fullStr( "c:\Program Files\Internet Explorer\IEXPLORE.EXE" );
fullStr.append( " " );
fullStr.append( site );
HANDLE hProc;
hProc = JustCreateProcess( (char*) fullStr.c_str(), "c:\Program Files\Internet Explorer" );
if (hProc) CloseHandle(hProc);
}
blog comments powered by Disqus