file types

I created a game that can save/load games. I even edited the file types tab in the setup program to show an icon for these games. The problem is that i need it to open the game when the user clicks on the game instead of opening it from the program.

Right now, if someone double clicks on the name of their game, it opens the program, but just to the main menu.

Is there any way that i can make it load the game instead of just starting the program?

[515 byte] By [kevdog114] at [2008-1-7]
# 1

Hi, kevdog114,

Could you please give us more details of your game application?

First, how do you save the state of the game? To a file?

Second, where does the name of user's game locate? A file, a shortcut or in the menu?

I am a little confused, please tell us more about what you are going to achieve.

Regards

YuGuo–MSFT at 2007-10-2 > top of Msdn Tech,Windows Forms,ClickOnce and Setup & Deployment Projects...
# 2

I save all declared variables in a text file separated by "}{" and ","(commas) to separate list entries. This information is saved in a text file with the extension changed to match the name of the game.

The files can be saved anywhere (I use an open file dialog box), but the primary location is in a "Saved Games" folder in the application folder.

When the user starts the game, A main menu box asks the user what to do (start new game, load saved game. etc..)

If user starts new game: Then a series of inputboxes get information about the user (name, etc...) and those values are placed in a series of publicly declared variables on the main game form.

If user loads saved game: The main game form appears and the filename selected by the user is opened as the main form opens and the form retrieves all of the saved game data from the file ( a basic text file; again with a different extension)

But if the user opens a saved game from viewing it with Internet Explorer (or some other way of getting to the game file other than from the my actual game, this happens:

The target for each of these saved games is set to start the game from the main menu(main form) (specified in the setup program).

Problem:

It only opens the main form, It doesn't open the file or anything. Is there any way that the form_load event can detect this and get the filename of the saved game and load it?

kevdog114 at 2007-10-2 > top of Msdn Tech,Windows Forms,ClickOnce and Setup & Deployment Projects...
# 3

Hi, kevdog114,

Are you trying to start the game when the user clicks the saved file?

That will relate to register file types in Windows.

First, you should register your File Type into Registry

Code Snippet

string keyName;

string keyValue;

keyName = "Your App";

keyValue = "Your Application";

RegistryKey key;

key = Registry.ClassesRoot.CreateSubKey(keyName);

key.SetValue("", keyValue);

key = key.CreateSubKey("shell");

key = key.CreateSubKey("open");

key = key.CreateSubKey("command");

key.SetValue("", "c:\\temp\\yourapp.exe %1");

keyName = ".game";

keyValue = "Your App";

key = Registry.ClassesRoot.CreateSubKey(keyName);

key.SetValue("", keyValue);

key.Close();

Second, your application should receive the parameter

In your Program.cs

Code Snippet

static void Main(string[] args)

{

Application.EnableVisualStyles(); // You should do more parameter validation here

Application.SetCompatibleTextRenderingDefault(false);

if (args.Length > 0)

{

Application.Run(new Form1(args[0]));

}

else

{

Application.Run(new Form1());

}

}

In your form, add

Code Snippet

public Form1(string saveFile)

{

//To parse the file

}

Hopes this helps,

Regards

YuGuo–MSFT at 2007-10-2 > top of Msdn Tech,Windows Forms,ClickOnce and Setup & Deployment Projects...