如何在 Windows操作系统中改变文件打开方式
Private Sub Command1_Click()
Dim hKey As Long
Dim MyReturn As Long
Dim MyData As String
MyReturn = OSRegOpenKey(HKEY_CLASSES_ROOT, ".exc", hKey)
MyReturn = RegQueryStringValue(hKey, "", MyData)
MyReturn = OSRegOpenKey(HKEY_CLASSES_ROOT, MyData + "/shell/open/command", hKey)
MyReturn = RegSetStringValue(hKey, "", "c:/visio.exe 1%", False)
If MyReturn Then
MsgBox "改变文件打开方式成功!", vbInformation, "请注意"
Else
MsgBox "改变文件打开方式失败!", vbExclamation, "请注意"
End If
OSRegCloseKey (hKey)
End Sub
6、按F5运行程序,在简体中文Windows95/NT/98、VB5.0/6.0环境中调试通过。
㈡利用Delphi编程
1、在Delphi3.0 IDE中,新建工程Project1,在Form1上添加按钮Button1。
2、在uses子句中添加Registry。
3、双击Button1,编写Click事件代码。
procedure TForm1.Button1Click(Sender: TObject);
var
MyRegistry : TRegINIFile;
Return:string;
begin
try
MyRegistry := TRegINIFile.Create('');
MyRegistry.RootKey := HKEY_CLASSES_ROOT;
Return:=MyRegistry.ReadString ('.gid','','No! Not Found the Key!');
MyRegistry.WriteString(Return,'','这只是一个演示!');
MyRegistry.WriteString(Return+'/DefaultIcon','','c:/visio.exe,1');
MyRegistry.WriteString(Return+'/shell/open/command','','c:/visio.exe %1');
finally
MyRegistry.Free;
end;
ShowMessage('改变文件打开方式成功!');
end;
4、按F9运行程序,在简体中文Windows95/NT/98、Delphi3.0/4.0环境中调试通过。