如何使用此MicroSoft示例来获取短文件名 [英] How can this MicroSoft Example to get short file names be made to

查看:61
本文介绍了如何使用此MicroSoft示例来获取短文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个应该在VB中工作的例子
http://support.microsoft.com/kb/175512/en-us

花了几个小时下载并安装VB Express 2008

有人告诉我这很简单之后,事情就更好了。

这两条指令行不起作用

3.放置一个Common Dialog控件表格。

4.从插入菜单中,选择模块将单个代码模块添加到

项目。

没有共同点工具箱中的Dialog(或CommonDialog)控件将

放在表单上。没有插入菜单,虽然添加模块出现在

项目菜单项上。

我不需要这个代码工作和VB工作(我讨厌过多的

和不方便的复杂性和糟糕的VB组织)我只想要一个小的

程序,它将直接在windows下工作,浏览文件列表并给予

该文件的确切,正确的短(8.3格式)文件名。

This is an example that is supposed to work in VB
http://support.microsoft.com/kb/175512/en-us
After spending a couple of hours downloading and installing VB Express 2008
after someone told me it was easy, the thing doesn''t work any better.
These two instruction lines are not functional
3. Place a Common Dialog control on the form.
4. From the Insert menu, select Module to add a single code module to the
project.
There is no Common Dialog (or CommonDialog) control in the toolbox to put
on the form. There is no Insert menu, although Add Module appears on the
Project menu item.
I don''t need this code to work and for VB to work (I hate the excessive
and inconvenient complexity and bad organization of VB) I just want a small
program that will work directly under windows, browse a file list and give
the exact, correct short (8.3 form) file name for that file.

推荐答案

2008-09-29,Mike1942< Mi******@discussions.microsoft.comwrote:
On 2008-09-29, Mike1942 <Mi******@discussions.microsoft.comwrote:

这是一个应该在VB中工作的例子
http://support.microsoft.com/kb/175512/en-us

花了几个小时下载并安装VB Express 2008

之后,有人告诉我这很简单,那东西再好不过了。

这两条指令行不起作用

3.在表单上放置一个Common Dialog控件。

4.从Insert菜单中,选择Module将单个代码模块添加到

项目。

工具箱中没有通用对话框(或CommonDialog)控件将

放在表单上。没有插入菜单,虽然添加模块出现在

项目菜单项上。

我不需要这个代码工作和VB工作(我讨厌过多的

和不方便的复杂性和糟糕的VB组织)我只想要一个小的

程序,它将直接在windows下工作,浏览文件列表并给予

该文件的确切,正确的短(8.3格式)文件名。
This is an example that is supposed to work in VB
http://support.microsoft.com/kb/175512/en-us
After spending a couple of hours downloading and installing VB Express 2008
after someone told me it was easy, the thing doesn''t work any better.
These two instruction lines are not functional
3. Place a Common Dialog control on the form.
4. From the Insert menu, select Module to add a single code module to the
project.
There is no Common Dialog (or CommonDialog) control in the toolbox to put
on the form. There is no Insert menu, although Add Module appears on the
Project menu item.
I don''t need this code to work and for VB to work (I hate the excessive
and inconvenient complexity and bad organization of VB) I just want a small
program that will work directly under windows, browse a file list and give
the exact, correct short (8.3 form) file name for that file.



这个例子不是为VB.NET编写的。这是VB.NET的一个简单示例:


选项严格开启

选项明确开启


进口系统

导入System.Windows.Forms

导入System.Text


公共类MainForm

继承System.Windows.Forms.Form


私有声明自动函数GetShortPathName Lib" kernel32" (_

ByVal lpszLongPath As String,_

ByVal lpszShortPath As StringBuilder,_

ByVal cchBuffer As Integer)As Integer
< br $>
Public Sub New()

InitializeComponent()

End Sub


''表格覆盖处理清理组件列表。

< System.Diagnostics.DebuggerNonUserCode()_

受保护的覆盖子处理(ByVal处理为布尔值)

尝试

如果处理AndAlso组件IsNot Nothing那么

components.Dispose()

结束如果

最后

MyBase.Dispose(处理)

结束尝试

结束子


''要求Windows窗体设计器

私有组件As System.ComponentModel.IContainer


''注意:Windows窗体设计器需要以下过程

''可以使用Windows窗体设计器修改它。

''不要使用c修改它ode编辑器。

< System.Diagnostics.DebuggerStepThrough()_

Private Sub InitializeComponent()

Me.openFileDialog = New System.Windows .Forms.OpenFileDialog

Me.btnFileSelect = New System.Windows.Forms.Button

Me.btnCopy = New System.Windows.Forms.Button

Me.txtShortName = New System.Windows.Forms.TextBox

Me.SuspendLayout()

''

''btnFileSelect

''

Me.btnFileSelect.Location = New System.Drawing.Point(338,10)

Me.btnFileSelect.Name =" btnFileSelect" ;

Me.btnFileSelect.Size = New System.Drawing.Size(26,23)

Me.btnFileSelect.TabIndex = 2

Me .btnFileSelect.Text =" ..."

Me.btnFileSelect.UseVisualStyleBackColor = True

''

''btnCopy

''

Me.btnCopy.Location = New System.Drawing.Point(289,36)

Me.btnCopy.Name =" btnCopy" ;

Me.btnCopy.Size = New System.Drawing.Size(75,23)

Me.btnCopy.TabIndex = 3

Me.btnCopy.Text ="复制" ;

Me.btnCopy.UseVisualStyleBackColor = True

''

''txtShortName

''

Me.txtShortName.Location = New System.Drawing.Point(12,12)

Me.txtShortName.Name =" txtShortName"

Me。 txtShortName.Size = New System.Drawing.Size(320,20)

Me.txtShortName.TabIndex = 4

''

'' MainForm

''

Me.AutoScaleDimensions =新的System.Drawing.SizeF(6.0!,13.0!)

Me.AutoScaleMode = System。 Windows.Forms.AutoScaleMode.Font

Me.ClientSize = New System.Drawing.Size(376,71)

Me.Controls.Add(Me.txtShortName)

Me.Controls.Add(Me.btnCopy)

Me.Controls.Add(Me.btnFileSelect)

Me.Name =" MainForm"

Me.StartPosition = System.Windows.Forms.FormStartPosition.Center Scree n

Me.Text =" Select File Name"

Me.ResumeLayout(False)

Me.PerformLayout()


End Sub

Friend WithEvents openFileDialog As System.Windows.Forms.OpenFileDialog

Friend WithEvents btnFileSelect As System.Windows.Forms.Button

Friend WithEvents btnCopy As System.Windows.Forms.Button

Friend WithEvents txtShortName As System.Windows.Forms.TextBox


Private Sub btnFileSelect_Click(ByVal sender As System.Object,ByVal e As System.EventArgs)处理btnFileSelect.Click

如果openFileDialog.ShowDialog(Me)= Windows.Forms.DialogResult.OK那么

Dim longPath As String = openFileDialog.FileName

Dim requiredSize As Integer = GetShortPathName(longPath,Nothing,0)

Dim buffer As New StringBuilder(requiredSize)


Dim result As Integer = GetShortPathName(longPath,buffer,buffer.Capacity)

txtShortName.Text = buffer.ToSt ring()

结束如果

End Sub


Private Sub btnCopy_Click(ByVal sender As System.Object,ByVal e As System .EventArgs)处理btnCopy.Click

Clipboard.SetData(DataFormats.Text,txtShortName.Text)

End Sub

End Class

HTH


-

Tom Shelton

That example was not written for VB.NET. Here is a quick example for VB.NET:

Option Strict On
Option Explicit On

Imports System
Imports System.Windows.Forms
Imports System.Text

Public Class MainForm
Inherits System.Windows.Forms.Form

Private Declare Auto Function GetShortPathName Lib "kernel32" ( _
ByVal lpszLongPath As String, _
ByVal lpszShortPath As StringBuilder, _
ByVal cchBuffer As Integer) As Integer

Public Sub New()
InitializeComponent()
End Sub

''Form overrides dispose to clean up the component list.
<System.Diagnostics.DebuggerNonUserCode()_
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
Try
If disposing AndAlso components IsNot Nothing Then
components.Dispose()
End If
Finally
MyBase.Dispose(disposing)
End Try
End Sub

''Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

''NOTE: The following procedure is required by the Windows Form Designer
''It can be modified using the Windows Form Designer.
''Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()_
Private Sub InitializeComponent()
Me.openFileDialog = New System.Windows.Forms.OpenFileDialog
Me.btnFileSelect = New System.Windows.Forms.Button
Me.btnCopy = New System.Windows.Forms.Button
Me.txtShortName = New System.Windows.Forms.TextBox
Me.SuspendLayout()
''
''btnFileSelect
''
Me.btnFileSelect.Location = New System.Drawing.Point(338, 10)
Me.btnFileSelect.Name = "btnFileSelect"
Me.btnFileSelect.Size = New System.Drawing.Size(26, 23)
Me.btnFileSelect.TabIndex = 2
Me.btnFileSelect.Text = "..."
Me.btnFileSelect.UseVisualStyleBackColor = True
''
''btnCopy
''
Me.btnCopy.Location = New System.Drawing.Point(289, 36)
Me.btnCopy.Name = "btnCopy"
Me.btnCopy.Size = New System.Drawing.Size(75, 23)
Me.btnCopy.TabIndex = 3
Me.btnCopy.Text = "Copy"
Me.btnCopy.UseVisualStyleBackColor = True
''
''txtShortName
''
Me.txtShortName.Location = New System.Drawing.Point(12, 12)
Me.txtShortName.Name = "txtShortName"
Me.txtShortName.Size = New System.Drawing.Size(320, 20)
Me.txtShortName.TabIndex = 4
''
''MainForm
''
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.ClientSize = New System.Drawing.Size(376, 71)
Me.Controls.Add(Me.txtShortName)
Me.Controls.Add(Me.btnCopy)
Me.Controls.Add(Me.btnFileSelect)
Me.Name = "MainForm"
Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScree n
Me.Text = "Select File Name"
Me.ResumeLayout(False)
Me.PerformLayout()

End Sub
Friend WithEvents openFileDialog As System.Windows.Forms.OpenFileDialog
Friend WithEvents btnFileSelect As System.Windows.Forms.Button
Friend WithEvents btnCopy As System.Windows.Forms.Button
Friend WithEvents txtShortName As System.Windows.Forms.TextBox

Private Sub btnFileSelect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFileSelect.Click
If openFileDialog.ShowDialog(Me) = Windows.Forms.DialogResult.OK Then
Dim longPath As String = openFileDialog.FileName
Dim requiredSize As Integer = GetShortPathName(longPath, Nothing, 0)
Dim buffer As New StringBuilder(requiredSize)

Dim result As Integer = GetShortPathName(longPath, buffer, buffer.Capacity)
txtShortName.Text = buffer.ToString()
End If
End Sub

Private Sub btnCopy_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCopy.Click
Clipboard.SetData(DataFormats.Text, txtShortName.Text)
End Sub
End Class

HTH

--
Tom Shelton


显然,你没看到适用于该文章的部分,

清楚地表明该文章与任何.NET版本的

Visual Studio无关。


适用于
。 Microsoft Visual Basic 5.0控件创建版

。 Microsoft Visual Basic 5.0学习版

。 Microsoft Visual Basic 5.0专业版

。 Microsoft Visual Basic 5.0企业版

。 Microsoft Visual Basic 4.0标准版

。 Microsoft Visual Basic 4.0专业版

。 Microsoft Visual Basic 4.0 32位企业版

。 Microsoft Visual Basic 6.0学习版

。 Microsoft Visual Basic 6.0专业版

。 Microsoft Visual Basic 6.0企业版


" Mike1942" < Mi ****** @ discuss.microsoft.com写信息

news:79 ********************** ************ @ microsof t.com ...
Apparently, you didn''t see the "Applies to" section of that article, which
clearly indicates that the article isn''t related to any .NET version of
Visual Studio.

APPLIES TO
. Microsoft Visual Basic 5.0 Control Creation Edition
. Microsoft Visual Basic 5.0 Learning Edition
. Microsoft Visual Basic 5.0 Professional Edition
. Microsoft Visual Basic 5.0 Enterprise Edition
. Microsoft Visual Basic 4.0 Standard Edition
. Microsoft Visual Basic 4.0 Professional Edition
. Microsoft Visual Basic 4.0 32-Bit Enterprise Edition
. Microsoft Visual Basic 6.0 Learning Edition
. Microsoft Visual Basic 6.0 Professional Edition
. Microsoft Visual Basic 6.0 Enterprise Edition


"Mike1942" <Mi******@discussions.microsoft.comwrote in message
news:79**********************************@microsof t.com...

这是一个应该在VB中工作的例子
http://support.microsoft.com/kb/175512/en -us

花了几个小时下载并安装VB Express

2008

有人告诉我这很简单,这件事情做得不够好。

这两条指令行不起作用

3.在表格上放置一个Common Dialog控件。

4.从插入菜单中,选择模块将单个代码模块添加到

项目。

工具箱中没有通用对话框(或CommonDialog)控件在表格上加上

。没有插入菜单,虽然添加模块出现在

项目菜单项上。

我不需要这个代码工作和VB工作(我讨厌过多的

和不方便的复杂性和糟糕的VB组织)我只想要一个

小的

程序直接在windows下运行,浏览一个文件列表并给出

该文件的确切,正确的短(8.3格式)文件名。
This is an example that is supposed to work in VB
http://support.microsoft.com/kb/175512/en-us
After spending a couple of hours downloading and installing VB Express
2008
after someone told me it was easy, the thing doesn''t work any better.
These two instruction lines are not functional
3. Place a Common Dialog control on the form.
4. From the Insert menu, select Module to add a single code module to the
project.
There is no Common Dialog (or CommonDialog) control in the toolbox to put
on the form. There is no Insert menu, although Add Module appears on the
Project menu item.
I don''t need this code to work and for VB to work (I hate the excessive
and inconvenient complexity and bad organization of VB) I just want a
small
program that will work directly under windows, browse a file list and give
the exact, correct short (8.3 form) file name for that file.



" Mike1942" < Mi ****** @ discuss.microsoft.com写信息

news:79 ********************** ************ @ microsof t.com ...
"Mike1942" <Mi******@discussions.microsoft.comwrote in message
news:79**********************************@microsof t.com...

我不需要这个代码工作和VB工作(我讨厌过多的

和不方便的复杂性和糟糕的VB组织)
I don''t need this code to work and for VB to work (I hate the excessive
and inconvenient complexity and bad organization of VB)



实际上,你只是晚了几年。该文中的代码旨在通过VB6在VB4中运行
。那是产品的时候。成为别的东西

并失去了很多RAD功能...更不用说失去它的能力

来编译Win32代码和超过1/2的代码" VBcentric"调试

功能..


我同意你的不方便的复杂性和糟糕的组织声明。

更多证明新的说法并不总是意味着更好......只是习惯了等待很长一段时间来启动IDE和你创建的任何应用程序。他们

一旦火焰燃烧就会更快启动,但直到那时,它才是猪。


如果你为了爱好而编写程序或者只是想完成一些工作而不用

处理大量的额外*垃圾*这只适用于网络应用(.Net in

产品名称是一个死的方式,尝试在某个地方的

网站上找到VB6的副本。它会节省你几个小时的开发时间,应用程序将会像你在dotNet中创建的任何东西一样可靠......加上,他们会加载

并且运行得更快......特别是如果你没有10ghz的PC和20g的

ram ....它不会是免费的,虽然...... MS没有''我必须免费赠送给客户吗?b $ b让人们使用它,就像他们使用dotNet一样。


什么是成本,它会支付对于自己很快并为你节省很多

挫折。


如果/当你找到VB6时,请前往microsoft.public.vb小组进行

帮助...这里有近5,000,000行代码可以插入和b $ b播放 (这只是一个网站!)


代码:4,983,574。线
http://www.planetsourcecode.com /vb/default.asp?lngWId=1

他们/做/有.Net代码,C#,B#和其他所有内容都堆放在一起,

,但只有他们用VB6做的样本的十分之一......谁知道是否有任何一个

是否有效。


代码:587,016。行
http://www.planetsourcecode.com /vb/d....asp?lngWId=10


这篇关于如何使用此MicroSoft示例来获取短文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆