我自己保存一个存盘文件,然后,我想用我的程序打开这个文件
在"打开方式"里我选择了这个文件但是,却不知道怎么打开.
高手请指导我呀.
谢谢了

解决方案 »

  1.   

    需要改注册表。
    到HKEY_CLASSES_ROOT里看看记事本(.txt)是怎么做的就知道了。
    改完注册表后,实际上是在系统里注册了你的这种文件类型,会发现该文件的图标已经变成了你的程序的图标,双击就可以打开了。
    就像双击.txt用记事本打开一样。
      

  2.   

    这时系统会将文件名作为参数传递到你的程序中,在程序中可以通过command$常量来访问传递近来的参数。
      

  3.   

    好用呀,谢谢楼上的大侠.
    同时,想再请教您关于command$这个常量您在哪里查到的?
    还有其它的常量么?
      

  4.   

    又有问题了,那个command$出错了
    如果选择打开方式,再选择程序来打开可以使用 command$="c:\work\1.class"
    但是,如果选择"总是用这个程序打开",然后通过双击打开文件,那么就出错了,
    此时command$="c:\work\1AB28~1.CLA.它不再是正常的文件名了,好像跟文件的扩展名有关.
    这个问题该怎么解决??
      

  5.   

    而且如果文件夹名字超过8位也会被缩短,用"~1"来取代.
    好像回到了dos时代
    文件名8位,扩展名3位
      

  6.   

    Command 函数
          返回命令行的参数部分,该命令行用于装入 Microsoft Visual Basic 或 Visual Basic 开发的可执行程序。语法Command说明当从命令行装入 Visual Basic 时,/cmd 之后的命令行的任何部分作为命令行的参数传递给程序。下面的示例中,cmdlineargs 代表 Command 函数返回的参数信息。VB /cmd cmdlineargs对于使用 Visual Basic 开发并编译为 .exe 文件的应用程序,Command 返回出现在命令行中应用程序名之后的任何参数。例如:MyApp cmdlineargs想知道如何在正在使用的应用程序的用户界面中改变命令行参数,请搜寻关于“命令行参数”的帮助。
      

  7.   

    ' 用这个函数获得文件完整路径和文件名。GetFullPathName
    The GetFullPathName function retrieves the full path and filename of a specified file. DWORD GetFullPathName(
      LPCTSTR lpFileName,  // pointer to name of file to find path for
      DWORD nBufferLength, // size, in characters, of path buffer
      LPTSTR lpBuffer,     // pointer to path buffer
      LPTSTR *lpFilePart   // pointer to filename in path
    );
     
    Parameters
    lpFileName 
    Pointer to a null-terminated string that specifies a valid filename. This string can use either short (the 8.3 form) or long filenames. 
    nBufferLength 
    Specifies the size, in characters, of the buffer for the drive and path. 
    lpBuffer 
    Pointer to a buffer that contains the null-terminated string for the name of the drive and path. 
    lpFilePart 
    Pointer to a variable that receives the address (in lpBuffer) of the final filename component in the path. 
    Return Values
    If the GetFullPathName function succeeds, the return value is the length, in characters, of the string copied to lpBuffer, not including the terminating null character. If the lpBuffer buffer is too small, the return value is the size of the buffer, in characters, required to hold the path. If the function fails, the return value is zero. To get extended error information, call GetLastError. Res
    The GetFullPathName function merges the name of the current drive and directory with the specified filename to determine the full path and filename of the specified file. It also calculates the address of the filename portion of the full path and filename. This function does not verify that the resulting path and filename are valid or that they refer to an existing file on the associated volume. 
      

  8.   

    楼上不会是想做一个基于jdk的Java编辑器吧?
      

  9.   

    re:goodname008(卢培培,充电中......) 
     这个都让您猜到了,真佩服.....
     不过我只是为了自己写代码方便,加一些自己喜欢的功能.
      

  10.   

    楼上的大哥,您说的第一个command()函数,并没有解决"文件名过长"的问题,关于第二个,也许您写的是java程序,但是我想用vb做.
    谢谢您的回复
      

  11.   

    我把我的代码留下,大家看看吧:str1 = Right(Command$, 6)
    str1 = Left(str1, 5)
    'str1是文件的扩展名
    MsgBox Command$If str1 <> "class" Then
    MsgBox "错误的文件类型"
    Exit Sub
    End If'str是文件的盘符+路径+文件名(不包括扩展名)
    str = Mid(Command$, 2, Len(Command$) - 8)
    'str2是文件的盘符+路径
    str2 = str
    Do While (Right(str2, 1) <> "\" And Len(str2) > 0)
    str2 = Left(str2, Len(str2) - 1)
    LoopChDir str2
    ChDrive Left(str2, 3)MsgBox "java " + Mid(str, Len(str2) + 1)Shell "java " + Mid(str, Len(str2) + 1)
      

  12.   

    不是不是,第二个是API函数,VB可以调用的。
    可以用GetFullPathName获得文件的完整路径和文件名。
    啰嗦一句:写Java程序用JBuilder可能觉得太大,太复杂,推荐一下JCreator。
    JCreator是个不错的编辑器,最高版本可能是3.0,不错。   :)
      

  13.   

    GetFullPathName VB声明 
    Declare Function GetFullPathName& Lib "kernel32" Alias "GetFullPathNameA" (ByVal lpFileName As String, ByVal nBufferLength As Long, ByVal lpBuffer As String, lpFilePart As Long) 
    说明 
    获取指定文件的完整路径名 
    返回值 
    Long,装载到lpBuffer中的字符数量(排除空中止字符)。如缓冲区的长度不足以容下完整的路径,则返回值就是要求的缓冲区大小。零表示失败。会设置GetLastError 
    参数表 
    参数 类型及说明 
    lpFileName String,指定文件名(长文件名或8.3格式的DOS文件名) 
    nBufferLength Long,lpBuffer字串的长度 
    lpBuffer String,指定一个预先定义好的字串,用于装载目标文件的驱动器及路径名称。如存在长文件名,那么这个参数保存的就肯定是长文件名 
    lpFilePart Long,指定一个长整数变量,用于装载文件名起始的地方。参考注解 
    注解 
    lpFilePart参数在vb里很难使用。它的问题在于:尽管windows在这个Long值中装载lpBuffer字串中的地址,用它表示路径信息文件名部分的起始处。但非常不幸,由vb创建的、传递给api的ANSI字串缓冲区也会使用这个地址。等这个函数返回的时候,vb已将返回的(lpBuffer)字串复制回它的内部Unicode字串缓冲区,所以lpFilePart地址已没有任何意义。因此,我们面临两种选择。首先,可以简单的不使用lpFilePart信息(忽略windows装载在参数中的值)。其次,可以将lpBuffer参数变成一个字节数组(lpFilePart As Byte——将数组的第一个元素作为参数传递)
     
    其他 
    在vb的api文本查看器中复制的声明为:Declare Function GetFullPathName Lib "kernel32" Alias "GetFullPathNameA" (ByVal lpFileName As String, ByVal nBufferLength As Long, ByVal lpBuffer As String, ByVal lpFilePart As String) As Long 
      

  14.   

    免费源代码任你选************************************
    *  http://sky300.com:88/hongsong/  *
    ************************************里面有你想要得冬冬哦!不看会后悔的哦!
      

  15.   

    能不能给个关于GetFullPathName的例子,我用了,但是总是出错
      

  16.   

    //能不能给个关于GetFullPathName的例子,我用了,但是总是出错
    【VB声明】
      Private Declare Function GetFullPathName Lib "kernel32" Alias "GetFullPathNameA" (ByVal lpFileName As String, ByVal nBufferLength As Long, ByVal lpBuffer As String, ByVal lpFilePart As String) As Long【别名】
      GetFullPathNameA【说明】
      获取指定文件的完整路径名 【返回值】
      Long,装载到lpBuffer中的字符数量(排除空中止字符)。如缓冲区的长度不足以容下完整的路径,则返回值就是要求的缓冲区大小。零表示失败。会设置GetLastError 【备注】
      在vb的api文本查看器中复制的声明为:Declare
      Function GetFullPathName Lib "kernel32" Alias "GetFullPathNameA"
      (ByVal lpFileName As String, ByVal nBufferLength As Long, ByVal lpBuffer As String, ByVal
      lpFilePart As String) As Long【参数表】
      lpFileName -----  String,指定文件名(长文件名或8.3格式的DOS文件名)
      nBufferLength --  Long,lpBuffer字串的长度
      lpBuffer -------  String,指定一个预先定义好的字串,用于装载目标文件的驱动器及路径名称。如存在长文件名,那么这个参数保存的就肯定是长文件名
      lpFilePart -----  Long,指定一个长整数变量,用于装载文件名起始的地方。参考注解例子:
    Private Declare Function GetFullPathName Lib "kernel32" Alias "GetFullPathNameA" (ByVal lpFileName As String, ByVal nBufferLength As Long, ByVal lpBuffer As String, ByVal lpFilePart As String) As Long
    Private Sub Form_Load()
         Dim Buffer As String, Ret As Long
        'create a buffer
        Buffer = Space(255)
        'copy the current directory to the buffer and append 'myfile.ext'
        Ret = GetFullPathName("myfile.ext", 255, Buffer, "")
        'remove the unnecessary chr$(0)'s
        Buffer = Left(Buffer, Ret)
        'show the result
        MsgBox Buffer
    End Sub