CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
IBM Rational 系统开发最佳实践工具包 WebSphere MQ 最佳实践 TOP 15
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  VB >  基础类

文本文件的解码程序

楼主panxuejian(大肚鼠)2002-12-24 14:59:39 在 VB / 基础类 提问

小弟近日编了一个[记事本]程序。  
  小弟希望让文本文件与本程序相关联,即执行TXT文件时,打开的是我编写的记事本程序,而不是MS的记事本。  
  往各路大侠拔刀相助!  
  问题点数:100、回复次数:5Top

1 楼dwenj(阿戴)回复于 2002-12-24 15:57:31 得分 5

有shell函数吧。Top

2 楼kjah(黑丁)回复于 2002-12-24 16:45:38 得分 55

如何使你的程序同文件扩展名建立关联?    
   
  如果你的程序是同文件操作有关,比如说你自定义了一个文件类型,用你的程序才    
  能打开它并查看其中的内容。你有没有想过在你的文件同你的程序之间建立关联,    
  这样不必每次都要先启动程序,再打开文件了。用户可直接点选你的文件,而不必    
  每次都要面对一个“打开方式”对话框。其实要做到这一点,只须调用API函数就    
  行了。下面的代码向你演示如何实现这一功能。    
   
   
  首先在窗体的通用声明段中加入下面的代码:    
   
   
  Option   Explicit    
   
  Private   Declare   Function   RegCreateKey   Lib   "advapi32.dll"   Alias   "    
  RegCreateKeyA"   (ByVal   hKey   As   Long,   _    
  ByVal   lpSubKey   As   String,   phkResult   As   Long)   As    
  Long    
  Private   Declare   Function   RegSetValue   Lib   "advapi32.dll"   Alias   "    
  RegSetValueA"   (ByVal   hKey   As   Long,   _    
  ByVal   lpSubKey   As   String,   ByVal   dwType   As   Long,   ByVal    
  lpData   As   String,   ByVal   cbData   As   Long)   As   Long    
   
  '   Return   codes   from   Registration   functions.    
  Const   ERROR_SUCCESS   =   0&    
  Const   ERROR_BADDB   =   1&    
  Const   ERROR_BADKEY   =   2&    
  Const   ERROR_CANTOPEN   =   3&    
  Const   ERROR_CANTREAD   =   4&    
  Const   ERROR_CANTWRITE   =   5&    
  Const   ERROR_OUTOFMEMORY   =   6&    
  Const   ERROR_INVALID_PARAMETER   =   7&    
  Const   ERROR_ACCESS_DENIED   =   8&    
   
  Private   Const   HKEY_CLASSES_ROOT   =   &H80000000    
  Private   Const   MAX_PATH   =   260&    
  Private   Const   REG_SZ   =   1    
   
   
  在窗体的Click事件中加入下面的代码    
  Private   Sub   Form_Click()    
   
  Dim   sKeyName   As   String   'Holds   Key   Name   in   registry.    
  Dim   sKeyValue   As   String   'Holds   Key   Value   in   registry.    
  Dim   ret&   'Holds   error   status   if   any   from   API   calls.    
  Dim   lphKey&   'Holds   created   key   handle   from   RegCreateKey.    
   
  'This   creates   a   Root   entry   called   "MyApp".    
  sKeyName   =   "MyApp"    
  sKeyValue   =   "My   Application"    
  ret&   =   RegCreateKey&(HKEY_CLASSES_ROOT,   sKeyName,   lphKey&)    
  ret&   =   RegSetValue&(lphKey&,   "",   REG_SZ,   sKeyValue,   0&)    
   
  'This   creates   a   Root   entry   called   .BAR   associated   with   "MyApp".    
  sKeyName   =   ".BAR"    
  sKeyValue   =   "MyApp"    
  ret&   =   RegCreateKey&(HKEY_CLASSES_ROOT,   sKeyName,   lphKey&)    
  ret&   =   RegSetValue&(lphKey&,   "",   REG_SZ,   sKeyValue,   0&)    
   
  'This   sets   the   command   line   for   "MyApp".    
  sKeyName   =   "MyApp"    
  sKeyValue   =   "c:mydirmy.exe   %1"    
  ret&   =   RegCreateKey&(HKEY_CLASSES_ROOT,   sKeyName,   lphKey&)    
  ret&   =   RegSetValue&(lphKey&,   "shellopencommand",   REG_SZ,   _    
  sKeyValue,   MAX_PATH)    
  End   Sub    
  按F5运行程序并在窗体上点击一下鼠标,然后退出程序.    
   
   
  从开始菜单中运行REGEDIT,你可在HKEY_CLASSES_ROOT下找到.bar和MyApp两个子    
  项,结构如下所示:    
   
  .bar   =   MyApp    
  MyApp   =   My   Application    
  |    
  --   Shell    
  |    
  --   open    
  |    
  --   command   =   c:mydirmy.exe   %1    
   
  参考:http://expert.csdn.net/Expert/topic/524/524025.xml?temp=.64555Top

3 楼zqfleaf(动力港湾)回复于 2002-12-24 16:56:00 得分 30

1.在新建的from中增加一个button  
    2.增加一个模块,放入以下代码  
  Declare   Function   RegCreateKey&   Lib   "advapi32.DLL"   Alias   "RegCreateKeyA"   (ByVal   hKey&,   ByVal   lpszSubKey$,   lphKey&)  
   
  Declare   Function   RegSetValue&   Lib   "advapi32.DLL"   Alias   "RegSetValueA"   (ByVal   hKey&,   ByVal   lpszSubKey$,   ByVal   fdwType&,   ByVal   lpszValue$,   ByVal   dwLength&)  
                Public   Const   ERROR_SUCCESS   =   0&  
                Public   Const   ERROR_BADDB   =   1&  
                Public   Const   ERROR_BADKEY   =   2&  
                Public   Const   ERROR_CANTOPEN   =   3&  
                Public   Const   ERROR_CANTREAD   =   4&  
                Public   Const   ERROR_CANTWRITE   =   5&  
                Public   Const   ERROR_OUTOFMEMORY   =   6&  
                Public   Const   ERROR_INVALID_PARAMETER   =   7&  
                Public   Const   ERROR_ACCESS_DENIED   =   8&  
                Global   Const   HKEY_CLASSES_ROOT   =   &H80000000  
                Public   Const   MAX_PATH   =   256&  
                Public   Const   REG_SZ   =   1  
   
  3.在from中放入以下代码  
  Private   Const   ERROR_SUCCESS   =   0&  
  Private   Const   ERROR_BADDB   =   1&  
  Private   Const   ERROR_BADKEY   =   2&  
  Private   Const   ERROR_CANTOPEN   =   3&  
  Private   Const   ERROR_CANTREAD   =   4&  
  Private   Const   ERROR_CANTWRITE   =   5&  
  Private   Const   ERROR_OUTOFMEMORY   =   6&  
  Private   Const   ERROR_INVALID_PARAMETER   =   7&  
  Private   Const   ERROR_ACCESS_DENIED   =   8&  
  Private   Const   HKEY_CLASSES_ROOT   =   &H80000000  
  Private   Const   MAX_PATH   =   256&  
  Private   Const   REG_SZ   =   1  
   
  Private   Sub   Command1_Click()  
   
                Dim   sKeyName   As   String   'Holds   Key   Name   in   registry.  
                Dim   sKeyValue   As   String   'Holds   Key   Value   in   registry.  
                Dim   ret&   'Holds   error   status   if   any   from   API   calls.  
                Dim   lphKey&   'Holds   created   key   handle   from   RegCreateKey.  
                '           'This   creates   a   Root   entry   called   "MyApp".  
                sKeyName   =   "MyApp"   '*  
                sKeyValue   =   "My   Application"   '*  
                ret&   =   RegCreateKey&(HKEY_CLASSES_ROOT,   sKeyName,   lphKey&)  
                ret&   =   RegSetValue&(lphKey&,   "",   REG_SZ,   sKeyValue,   0&)  
                '           'This   creates   a   Root   entry   called   .BAR   associated   with   "MyApp".  
                sKeyName   =   ".bar"   '*  
                sKeyValue   =   "MyApp"   '*  
                ret&   =   RegCreateKey&(HKEY_CLASSES_ROOT,   sKeyName,   lphKey&)  
                ret&   =   RegSetValue&(lphKey&,   "",   REG_SZ,   sKeyValue,   0&)  
                '           'This   sets   the   command   line   for   "MyApp".  
                sKeyName   =   "MyApp"   '*  
                sKeyValue   =   "notepad.exe   %1"   '*  
                ret&   =   RegCreateKey&(HKEY_CLASSES_ROOT,   sKeyName,   lphKey&)  
                ret&   =   RegSetValue&(lphKey&,   "shell\open\command",   REG_SZ,   sKeyValue,   MAX_PATH)  
  End   Sub  
  该程序演示如何关连.bar文件到nopad.exe  
  Top

4 楼zyl910(编程的乐趣在于编程控制硬件,与用图形学实现绚丽效果)回复于 2002-12-24 22:53:44 得分 9

http://expert.csdn.net/Expert/topic/524/524025.xml?temp=.64555  
  Top

5 楼Arcan(Arcan)回复于 2002-12-24 23:27:42 得分 1

楼上的几位都说了,如果追求简单,那么在你程序第一次执行的时候将原来的记事本改名成notepad.bak(使用Name命令),然后把你自己的程序拷贝到原来的notepad.exe的位置,并改名成notepad.exe,嘿嘿Top

相关问题

  • 文本文件的解码程序
  • 文本文件的浏览程序
  • 写文本文件,文本文件里不是乱码,但是用程序读出来的是乱码。。
  • 如何用程序控制打印文本文件
  • 一个文本文件用delphi程序怎么把它清空?
  • 如何在程序定时清空文本文件的内容??
  • 怎样在程序中调用文本文件呢?
  • 如何用文本文件保存程序的一些变量??
  • 谁做过dbf文件转文本文件的程序
  • 如何用其他程序打开文本文件

关键词

  • .net
  • 文件
  • 记事本
  • 代码
  • 程序
  • byval
  • 打开
  • const error
  • 下面的代码
  • as long

得分解答快速导航

  • 帖主:panxuejian
  • dwenj
  • kjah
  • zqfleaf
  • zyl910
  • Arcan

相关链接

  • Visual Basic类图书
  • Visual Basic类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
北京创新乐知广告有限公司 版权所有, 京 ICP 证 070598 号
世纪乐知(北京)网络技术有限公司 提供技术支持
Copyright © 2000-2008, CSDN.NET, All Rights Reserved
GongshangLogo