PDA

View Full Version : Simple C++ question


psycholord
04-25-2003, 12:53 AM
ok, I am pretty much a C++ newbie, but I need some help. I want to open a webpage in a users default browser. there has to be an easy way to this. And it isnt' even an internet webpage, it s a local file page. Like file:\\c:\page.html.

Can anyone hekp me with this?

stuka
04-25-2003, 11:12 AM
The quick and dirty way to do it is with the system() call: system("iexplore c:\\file.html") The better way to do it would be to look into the CreateProcess() function that will allow you to launch the default browser (which in turn means reading the Windows Registry....)

psycholord
04-25-2003, 05:58 PM
But iexplore is not in the path. And can you go into more detail about the createprocess function?Or registry reading? This would be the preferrable option

stuka
04-25-2003, 06:24 PM
Here's the declaration of CreateProcess - MSDN has a full write up on it, which goes into a TON of detail;BOOL CreateProcess(
LPCTSTR lpApplicationName,
// pointer to name of executable module
LPTSTR lpCommandLine, // pointer to command line string
LPSECURITY_ATTRIBUTES lpProcessAttributes, // process security attributes
LPSECURITY_ATTRIBUTES lpThreadAttributes, // thread security attributes
BOOL bInheritHandles, // handle inheritance flag
DWORD dwCreationFlags, // creation flags
LPVOID lpEnvironment, // pointer to new environment block
LPCTSTR lpCurrentDirectory, // pointer to current directory name
LPSTARTUPINFO lpStartupInfo, // pointer to STARTUPINFO
LPPROCESS_INFORMATION lpProcessInformation // pointer to PROCESS_INFORMATION
);
As for reading the registry, I've never done it, and not sure I want to - though as a guess, I'd bet that whatever you read from the registry will fill in the lpApplicationName in the above, and so most of your work would be done.

psycholord
04-25-2003, 06:45 PM
thanks. I'll give it a shot. Do you know where in the registry default applications and stuff is stored?

Kamikaze!
04-26-2003, 11:02 AM
You can also use the ShellExecute() API function, might be easier.