Jump to content
  • Advertisement
Sign in to follow this  

Something simple, I think.

This topic is 4644 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

I would like my program to open an explorer window in a certain website, when a button is being pressed. I am programming in visual C++ 6. I think this should be simple. How do I do that? Thanks in advance.

Share this post


Link to post
Share on other sites
Advertisement
You can offer the URL as a string to the OS which will open it using the default program for that file type (for HTML for example that will be the user's default browser). In Windows this can be done using ShellExecute() if I remember well. But perhaps this is not the best solution.

Greetz,

Illco

Share this post


Link to post
Share on other sites
Here's the function we use in our engine for this sort of thing (slightly stripped down for readability):


bool SpawnActive( HANDLE hApp ) // handle to app that we will query
{
BOOL bAppQuery;
DWORD Status = 0;

// fail if we have a bad handle
if ( hApp == NULL )
{
assert( 0 );
return false;
}

// get app status
bAppQuery = GetExitCodeProcess( hApp, &Status );
if ( AppQuery == false )
{
return false;
}

// return app status
if ( STILL_ACTIVE == Status )
{
return true;
}
return false;
}

HANDLE SpawnApp( char *pLaunchString, const char *pParameters, bool bSynchronous )
{
SHELLEXECUTEINFO ShellInfo;

// Init ShellInfo struct
memset( &ShellInfo, 0, sizeof( SHELLEXECUTEINFO ) );
ShellInfo.cbSize = sizeof( SHELLEXECUTEINFO );
ShellInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
ShellInfo.nShow = SW_SHOWNORMAL;
ShellInfo.lpFile = pLaunchString;
ShellInfo.lpParameters = pParameters;

// launch new process
if ( ShellExecuteEx( &ShellInfo ) == 0 )
{
return NULL;
}

// If its a synchronous spawn, then wait for the app to finish then null its handle
if ( bSynchronous )
{
while ( SpawnActive( ShellInfo.hProcess ) );
ShellInfo.hProcess = NULL;
}
::ShowWindow( ShellInfo.hwnd, SW_SHOWNORMAL );
::SetForegroundWindow( ShellInfo.hwnd );
::SetFocus( ShellInfo.hwnd );

// return spawed app handle process
return ShellInfo.hProcess;
}



So make the call something like this:

SpawnApp( "iexplore.exe", "http://www.gamedev.net", false );

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!