Click here to Skip to main content
15,896,118 members
Articles / Programming Languages / C#

C# SDI/MDI Application Wizards

Rate me:
Please Sign up or sign in to vote.
3.50/5 (28 votes)
30 Nov 20038 min read 227.1K   2.7K   60  
Useful project templates for C# document-centric applications
In this article, I'll show what is brought in the zip files, how to install the application wizard, the meaning of SDI/MDI and how it was built
using System;
using System.IO;
using Microsoft.Win32;

namespace SDIMDIwizardinstaller
{
	/// <summary>
	/// Summary description for Class1.
	/// </summary>
	class Class1
	{
		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		[STAThread]
		static void Main(string[] args)
		{

			// installation sequence
			// 1- get VC# install dir (regkey)
			// 2- copy template files in the VC# subfolder for files
			// 3- copy vsz files in the VC# subfolder for project wizards
			// 4- add two entries in the VC# vsdir file so that the IDE sees them

			// check out cmdline (type 2002 for VC#2002, none or everything else for VC#2003)
			bool bIsFor2002 = args.GetLength(0)>0 && args[0] == "2002";

			// 1- regkey
			RegistryKey k;
			if (bIsFor2002)
				k = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"Software\Microsoft\VisualStudio\7.0", true);
			else
				k = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"Software\Microsoft\VisualStudio\7.1", true);
			String szWizardDir = (String) k.GetValue("InstallDir") + @"..\..\VC#\";

			if ( !Directory.Exists(szWizardDir) )
			{
				System.Console.WriteLine("Make sure to install VC# first");
				return;
			}

			// 2- template files
			String szSrcDir = AppDomain.CurrentDomain.BaseDirectory;
			RecurseCopyFiles(szSrcDir + @"\CSharpSDIWiz", szWizardDir + @"VC#Wizards\CSharpSDIWiz");
			RecurseCopyFiles(szSrcDir + @"\CSharpMDIWiz", szWizardDir + @"VC#Wizards\CSharpMDIWiz");

			// 3- vsz files
			if (bIsFor2002) // VC# 2002
			{
				File.Copy(szSrcDir + @"\CSharpSDI_VS2002.vsz", szWizardDir + @"CSharpProjects\CSharpSDI.vsz",true);
				File.Copy(szSrcDir + @"\CSharpMDI_VS2002.vsz", szWizardDir + @"CSharpProjects\CSharpMDI.vsz",true);
			}
			else // VC# 2003
			{
				File.Copy(szSrcDir + @"\CSharpSDI_VS2003.vsz", szWizardDir + @"CSharpProjects\CSharpSDI.vsz",true);
				File.Copy(szSrcDir + @"\CSharpMDI_VS2003.vsz", szWizardDir + @"CSharpProjects\CSharpMDI.vsz",true);
			}

			// 4- update vsdir file (append 2 entries if they don't exist yet)
			bool bAlreadyInstalled = false;
			using (StreamReader sr = new StreamReader( szWizardDir + @"CSharpProjects\CSharp.vsdir" )) 
            {
                String line;
                while ((line = sr.ReadLine()) != null) 
                {
					if (line.IndexOf("CSharpSDI.vsz") > -1)
					{
						bAlreadyInstalled = true;
						break;
					}
                }
				sr.Close();

				if (!bAlreadyInstalled)
				{
					using (StreamWriter sw = File.AppendText( szWizardDir + @"CSharpProjects\CSharp.vsdir" )) 
					{
						sw.WriteLine("CSharpSDI.vsz|{FAE04EC1-301F-11d3-BF4B-00C04F79EFBC}|SDI Application|11|Builds a Windows single document interface (SDI) application|{FAE04EC1-301F-11d3-BF4B-00C04F79EFBC}|4554| |SDIApplication");
						sw.WriteLine("CSharpMDI.vsz|{FAE04EC1-301F-11d3-BF4B-00C04F79EFBC}|MDI Application|12|Builds a Windows single document interface (MDI) application|{FAE04EC1-301F-11d3-BF4B-00C04F79EFBC}|4554| |MDIApplication");
					}
				}
            }

		}

		static void RecurseCopyFiles(String szSrcDir, String szDestDir)
		{
			if ( !Directory.Exists(szDestDir) )
				Directory.CreateDirectory(szDestDir);

			string [] fileEntries = Directory.GetFiles(szSrcDir);
			foreach(string fileName in fileEntries)
				File.Copy(fileName, szDestDir + fileName.Substring(fileName.LastIndexOf('\\')),true);

			// recurse
			string [] subdirectoryEntries = Directory.GetDirectories(szSrcDir + @"\");
			foreach(string subdirectory in subdirectoryEntries)
			{
				String szSrcNextDir = subdirectory;
				String szDestNextDir = szDestDir + subdirectory.Substring(subdirectory.LastIndexOf('\\'));
				RecurseCopyFiles(szSrcNextDir, szDestNextDir);
			}

		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.


Written By
France France
Addicted to reverse engineering. At work, I am developing business intelligence software in a team of smart people (independent software vendor).

Need a fast Excel generation component? Try xlsgen.

Comments and Discussions