积极答复者
字的文件格式打开文件

问题
-
有一个Form,里面有两个textbox,一个richtextbox,一个PictureBox和可以播放音频的控件。然后我保存这些资料的时候生成一个*.muradil这个样一个文件格式的文件。如果有安装过我自己做的软件的电脑,可以双击刚才保存的文件直接打开,当然打开的时候用我自己做的软件打开。现在肯定知道我的意思了。呵呵。。。太麻烦你了。谢谢你
就像word ,word的扩展名是.doc,我们保存的时候有一个*.doc的文件出现。我们需要的时候双击那个*.doc的文件就能打开你以前保存过的文件。当然这个里面包含很多信息,比如图片文字等。谢谢你。谢谢你这么详细这么认真的讲解。谢谢。。。。
呵呵 。。。。。等你的消息。我的邮箱是muradil0903@126.com
答案
-
Code Snippet
'保存
Dim fs As New FileStream(FILE_NAME, FileMode.Create)Dim w As New BinaryWriter(fs)
Dim imgByte() As Byte
Dim strByte() As Byte'把图像数据存到数组
Dim Ms As MemoryStream = New MemoryStream()
PictureBox1.Image.Save(Ms, System.Drawing.Imaging.ImageFormat.Jpeg)
ReDim imgByte(Ms.Length)
Ms.Position = 0
Ms.Read(imgByte, 0, Convert.ToInt32(Ms.Length))Ms.Close()
'把文字数据存到数组
strByte = System.Text.Encoding.UTF8.GetBytes(TextBox1.Text)'图片大小
w.Write(imgByte.Length)
'文字大小
w.Write(strByte.Length)
'保存图片
w.Write(imgByte)
'保存文字
w.Write(strByte)w.Close()
fs.Close() -
Code Snippet
'打开
Dim fs As New FileStream(FILE_NAME, FileMode.Open, FileAccess.Read)Dim r As New BinaryReader(fs)
'图片大小
Dim intImgLength = r.ReadInt32()
'文字大小
Dim intStrLength = r.ReadInt32()
'图片
Dim imgByte() As Byte = r.ReadBytes(intImgLength)
'文字
Dim strByte() As Byte = r.ReadBytes(intStrLength)'显示图片
Dim Ms As MemoryStream = New MemoryStream()
Ms.Write(imgByte, 0, imgByte.Length)
PictureBox1.Image = Image.FromStream(Ms)
'显示文字
TextBox1.Text = System.Text.Encoding.UTF8.GetString(strByte)r.Close()
fs.Close()
全部回复
-
将以下内容放入记事本,保存为"xxx.reg"。注意红色标记部分,应该改成你想要的图标路径!
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\.test]
@="测试文件"[HKEY_CLASSES_ROOT\.test\DefaultIcon]
@="c:\\test.ico"[HKEY_CLASSES_ROOT\.test\OpenWithList]
[HKEY_CLASSES_ROOT\.test\OpenWithList\notepad.exe]
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.test]
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.test\OpenWithList]
"a"="xxx.exe"
"MRUList"="a"[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.test\OpenWithProgids]
"test_auto_file"=hex(0):xxx.exe是我自己写的程序。
我用这个自定义文件格式已经定义好了,但是就是实现不了文件的保存,打开。谢谢。。。 -
Code Snippet
'保存
Dim fs As New FileStream(FILE_NAME, FileMode.Create)Dim w As New BinaryWriter(fs)
Dim imgByte() As Byte
Dim strByte() As Byte'把图像数据存到数组
Dim Ms As MemoryStream = New MemoryStream()
PictureBox1.Image.Save(Ms, System.Drawing.Imaging.ImageFormat.Jpeg)
ReDim imgByte(Ms.Length)
Ms.Position = 0
Ms.Read(imgByte, 0, Convert.ToInt32(Ms.Length))Ms.Close()
'把文字数据存到数组
strByte = System.Text.Encoding.UTF8.GetBytes(TextBox1.Text)'图片大小
w.Write(imgByte.Length)
'文字大小
w.Write(strByte.Length)
'保存图片
w.Write(imgByte)
'保存文字
w.Write(strByte)w.Close()
fs.Close() -
Code Snippet
'打开
Dim fs As New FileStream(FILE_NAME, FileMode.Open, FileAccess.Read)Dim r As New BinaryReader(fs)
'图片大小
Dim intImgLength = r.ReadInt32()
'文字大小
Dim intStrLength = r.ReadInt32()
'图片
Dim imgByte() As Byte = r.ReadBytes(intImgLength)
'文字
Dim strByte() As Byte = r.ReadBytes(intStrLength)'显示图片
Dim Ms As MemoryStream = New MemoryStream()
Ms.Write(imgByte, 0, imgByte.Length)
PictureBox1.Image = Image.FromStream(Ms)
'显示文字
TextBox1.Text = System.Text.Encoding.UTF8.GetString(strByte)r.Close()
fs.Close() -
在线等你的回复。。。。