Log in

View Full Version : How to open the BUY-webpage from your game?


lakibuk
08-03-2003, 07:53 AM
I am implementing a "Get full version"-button in my game (fullscreen).
Currently i am using
ShellExecute(NULL, "open", "iexplore", "http://www.buy.com", NULL, SW_SHOWNORMAL);
but this is making troubles.
How is it done better?

Scorpio
08-03-2003, 11:15 AM
Here's some old code I have used in the past. I removed some of the error-checking and character-stripping code to keep it short.

(hopefully the formatting will look decent when you paste it into your editor)

--------------------------
// ----------------------------------------------------------------------- //
//
// ROUTINE: Utils_BrowseWeb
//
// PURPOSE: Browses the given web page using the default browser
//
// ----------------------------------------------------------------------- //

BOOL Utils_BrowseWeb(char* sPage)
{
if (!Utils_BrowseWebFormal(sPage))
{
char sExec[256];
wsprintf(sExec, "start %s", sPage);
UINT uRet = WinExec(sExec, SW_SHOWNORMAL);
if (uRet < 32) return(FALSE);
}

return(TRUE);
}

BOOL Utils_BrowseWebFormal(char* sPage)
{
// Declare local variables...

char sExe[_MAX_PATH];
char sLaunch[_MAX_PATH];
long maxpath = _MAX_PATH;

STARTUPINFO startInfo;
PROCESS_INFORMATION processInfo;


// Get the default browser from the registry...

long lRet = RegQueryValue(HKEY_CLASSES_ROOT, "http\\shell\\open\\command", sExe, &maxpath);


// TODO: Remove '-' and '/' characters from sExe string...


// Setup the launch path and filename and launch the process...

wsprintf(sLaunch, "%s %s", sExe, sPage);

memset(&startInfo, 0, sizeof(STARTUPINFO));
startInfo.cb = sizeof(STARTUPINFO);

BOOL bRet = CreateProcess(NULL, sLaunch, NULL, NULL, FALSE, 0, NULL, NULL, &startInfo, &processInfo);


// All done...

return(bRet);
}

--------------------

Hope this helps...
-Scorpio

oNyx
08-03-2003, 11:49 AM
start www.dexterity.com

Works nice... you can try it:

<win>+'R' and then type "start www.whatsoever.com" in the box.

Scorpio
08-03-2003, 12:09 PM
Originally posted by oNyx
start www.dexterity.com

Works nice... you can try it:

<win>+'R' and then type "start www.whatsoever.com" in the box.

Yeah, the above code I posted does the same thing if the "formal" version fails:

char sExec[256];
wsprintf(sExec, "start %s", sPage);
UINT uRet = WinExec(sExec, SW_SHOWNORMAL);
if (uRet < 32) return(FALSE);

I think I originally got the "formal" version code from a Microsoft posting...I remember there being a reason to query the registry...but I don't remember what oddball case it was supposed to handle. I haven't had any problems with it tho.
-Scorpio

patrox
08-03-2003, 12:55 PM
Originally posted by lakibuk
I am implementing a "Get full version"-button in my game (fullscreen).
Currently i am using
ShellExecute(NULL, "open", "iexplore", "http://www.buy.com", NULL, SW_SHOWNORMAL);
but this is making troubles.
How is it done better?


Replace by
ShellExecute(NULL, "open", "http://www.buy.com" ,"", NULL, SW_SHOWNORMAL);


so if the person uses netscape or whateverm, it launches the default webbrowser.

pat.

Joe
08-03-2003, 02:33 PM
Works with any browser...

#define WEBAPPSTOGO "http://webappstogo.com"
ShellExecute (NULL,NULL, __TEXT(WEBAPPSTOGO), NULL, NULL, SW_SHOW);

lakibuk
08-04-2003, 12:04 AM
The problem is: after opening the website with ShellExecute() the game pops up again,after i switch to another entry in the windows task bar. I don't know why this happens.

LordKronos
08-04-2003, 03:20 AM
I'm not positive, but I think I know what you are saying. One thing that I think will help is if you minimize your window before calling ShellExecute.

lakibuk
08-04-2003, 05:14 AM
Thanks,tried that but the effects stay the same.
Another problem: the opened browser window has the same dimensions as my game (640x480). Maybe i will simply quit the game when BUY NOW is pushed. Don't know how to do it right.

damocles
08-05-2003, 05:01 AM
I had the same problem. I could never get it to behave properly when the user clicked the buy button. In the end I too opted for a simple quit the game approach after the web page is called.

aspiral
08-05-2003, 05:51 AM
about the browser-maximizing stuff:

you can use a "SendMessage (hWndBrowser, WM_MAXIMIZE)". Play with the WS_XYZ styles, i don't know if there are other,better ones instead of WS_MAXIMIZE. You'll get the HWND from the CreateProcess/ShellExecute calls.(well, you get a HINSTANCE but you can get HWND from there).


WM_ACTIVATEAPP / WA_ACTIVE / WA_CLICKACTIVE / WA_INACTIVE are the best friends. you can use them for alt-tab issues (restoring DD surfaces), intercepting screensaver, pausing the game-loop while the game-window is not in foreground etc..
So, when the user presses "Buy Now!", i think the CreateProcess() call should cause your app to get a WM_ACTIVATEAPP->WM_INACTIVE message, where you can do all your stuff like restoring desktop resolution and
minimizing your window, maximizing the browser etc.


i haven't tested all that and haven't done any windows stuff in a long time, but i think it should work :) .

Punchey
08-05-2003, 10:17 AM
If you want more info and somewhat more control over your ShellExecute call, try ShellExecuteEx.

zoombapup
08-05-2003, 10:28 AM
What I'd advise people to do, is to grab the current screen res/colour/whatever settings on app startup, then simply restore these whenever you need to shell out or on exit.

That way you simply return to thier chosen desktop res when you minimize or exit.

Minimizing your app during "buy now" is a good idea, maybe even exiting is a good call if youre likely to want to over-write anything with an installer/new download.

Phil.

ApeZone
08-05-2003, 03:54 PM
You need to minimize your game before calling your ShellExecute.

ShowWindow(hMainWindow,SW_MINIMIZE);
ShellExecute(0, "open", datafile, 0, path, SW_SHOWNORMAL);

lakibuk
08-06-2003, 01:14 AM
I am minimizing my window.
Problem seems to be here:
I use WM_ACTIVATE to reactivate my application (after alt+tab etc).
Seems to fire if i click some task in the task bar.
Wrong place/message for reactivating my application?

case WM_ACTIVATE:
if (LOWORD(wParam)==WA_ACTIVE
|| LOWORD(wParam)==WA_CLICKACTIVE) {

... // Set screen mode
... // Restore surfaces

}

LordKronos
08-06-2003, 02:52 AM
Heres the code that's worked for me so far
case WM_NCACTIVATE:
case WM_ACTIVATEAPP:
window->m_active = wParam != 0;

if (window->m_fullscreen && window->m_active)
ChangeDisplaySettings(&window->dmScreenSettings,CDS_FULLSCREEN);

if (window->m_fullscreen && !window->m_active)
{
ShowWindow(hWnd, SW_MINIMIZE);
ChangeDisplaySettings(NULL,0);
};
return 0;

lakibuk
08-06-2003, 02:53 AM
In case anyone cares:
Found the solution.
Now i react to WM_ACTIVATEAPP instead of WM_ACTIVATE.

Diodor
08-06-2003, 03:07 AM
This seems to work for me:

ShellExecute (NULL, "open", "register.url", "", NULL, SW_MAXIMIZE);