Vs2005 A simple log tool for making--4. File type Registration

Source: Internet
Author: User

The reusable class registered by the file type is in the project Filetypereg, and the class actually used is tsysregeist in the MyLog3 (that is, the main program) project.

File type registration, in effect, writes some relevant data to the Registry's HKEY_CLASSES_ROOT entry: First, create a subkey under HKEY_CLASSES_ROOT, which is the suffix name, such as ". ML3". It has a default value, such as "Ml3_filetype". This means that the relevant data for the ". ML3" file type is stored in the "Ml3_filetype" subkey under HKEY_CLASSES_ROOT.

  

  
The contents of the "Ml3_filetype" subkey are as follows:

  

  

Where the value below the shell and open is empty. Therefore, the important attributes are the following three:
1. The file type description, which is the default value "MyLog3 log File" under "Ml3_filetype".
2. The icon path, which is the default value "F: Desktop Mylog3ml3.ico" under "DefaultIcon".
3. Startup parameters, that is, the default value "F: Desktop MyLog3MyLog3.exe" "%1" under Command. It means that whenever the. ML3 type of file is run, the program "F: Desktop MyLog3MyLog3.exe" is invoked, the command-line argument passed is "filename", and filename refers to the full path of the ML3 file. Note that the path is included with "", so that there is no error when there is a space in the filename. (For example: The file name is "F:ab CD.ML3", If not "", then the command line arguments received are 2: F:ab and CD.ML3. )

  
First, you need a class that records this information and looks at the class Filetypereginfo in the project Filetypereg:



Public   class Filetypereginfo
... {
/**/ /// The name of the target type file extension
         Public stringExtendname; //". XCF"
        /**/ /// target file type description
         Public stringDescription;//"xcodefactory project file"
        /**/ /// the icon associated with the target type file
         Public stringIcopath;
/**/ /// Open the target type file application
         Public stringExePath;
PublicFiletypereginfo ()
...{
}
PublicFiletypereginfo (stringExtendname)
...{
this. Extendname = extendname;
}
}

  

Second, you need a class that actually performs a registry write operation, looking at the class Filetyperegister in the project Filetypereg:
  



Public   class Filetyperegister
... {
//registering the file type to the system requires passing the Filetypereginfo object
         Public Static voidRegisterfiletype (Filetypereginfo reginfo)
...{
//
        }
//To remove a file type from the system, you need to pass the suffix name, such as. txt
         Public Static voidDelfiletypereg (stringextendname)
...{
//
        }
//returns the registration information in the related file type system
         Public Staticfiletypereginfo Getfiletypereginfo (stringextendname)
...{
//
        }
//update file type information
         Public Static BOOLUpdatefiletypereginfo (Filetypereginfo reginfo)
...{
//
        }
//checks whether the specified file type has been registered
         Public Static BOOLfiletyperegistered (stringExtendname)
...{
//
        }
}

  

Add Registration Registerfiletype (Filetypereginfo reginfo):



Public   Static   void Registerfiletype (Filetypereginfo reginfo)
... {
if(filetyperegistered (reginfo.extendname))
...{
return;
}

//Xcf_filetype
            stringRelationName=regInfo.ExtendName.Substring (1, RegInfo.ExtendName.Length- 1). ToUpper ()+ "_filetype";

//specifies the associated information for the. xcf file in Xcf_filetype
RegistryKey Filetypekey=Registry.ClassesRoot.CreateSubKey (reginfo.extendname);//create an item. XCF
Filetypekey.setvalue ("", relationname);//Add a default value of Xcf_filetype to the. XCF
Filetypekey.close ();

RegistryKey Relationkey=Registry.ClassesRoot.CreateSubKey (relationname);//Create Item Xcf_filetype
Relationkey.setvalue ("", reginfo.description);//Write default value file type description

RegistryKey Iconkey=Relationkey.createsubkey ("DefaultIcon");//Add Item, Icon path
Iconkey.setvalue ("", Reginfo.icopath);

RegistryKey Shellkey=Relationkey.createsubkey ("Shell");
RegistryKey Openkey=Shellkey.createsubkey ("Open");
RegistryKey Commandkey=Openkey.createsubkey ("Command");
Commandkey.setvalue ("", Reginfo.exepath+ "'%1 '"); //let the application know which file is open

Relationkey.close ();
}
  


First, determine if you have already registered and exit if you have registered. Then get the name of the stored information relationname, and create the corresponding subkey DefaultIcon, Shell, Open, Command, write the appropriate data. This involves the operation of the registry, where the functions are not clear to see the Object Browser in the vs2005.
Then there are updates, deletions, and other operations, the principle is the same, the value of the registry to modify.

In the MyLog3 project, the class that actually performs the file type registration is tsysregeist:
  



Public   Static   void addregeist () // registers the file type. ML3
         ... {
Filetypereginfo Filereg= NewFiletypereginfo (". ML3");
Filereg.description= "MyLog3 log File";
Filereg.exepath=Application.startuppath+ @"MyLog3.exe";
Filereg.icopath=Application.startuppath+ @"Ml3.ico";

if(filetyperegister.filetyperegistered (filereg.extendname))
...{
Filetyperegister.updatefiletypereginfo (Filereg);
}
Else
...{
Filetyperegister.registerfiletype (Filereg);
}
}

Public   Static   void delregeist () // deletes a file type from the system. ML3 Association
         ... {
Filetyperegister.delfiletypereg (". ML3");
}

You can perform additions or deletions as soon as the application is started and the appropriate method is invoked.

Next, data structure check.
ie.2008-04-08



<

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.