我在VB中调用PPVIEW32.exe播放powerpoint文件,但当powerpoint文件存放在program file文件夹时就会读取不了powerpoint文件.
我反复试过十几次了,得出一人结论:只有powerpoint文件存放在名字有空格文件夹中时PPVIEW32.exe就不能读取powerpoint文件.例如:
powerpoint文件存放Documents and Settings文件夹时,PPVIEW32.exe就不能读取powerpoint文件,因为Documents and Settings文件夹的名字有空格。但放在windows文件夹时就能读取。
但是我们的VB打包安装后都是存放在program file文件夹中的,所以不能解决这个问题。请大家帮忙,谢谢!!!!!!!!!
我反复试过十几次了,得出一人结论:只有powerpoint文件存放在名字有空格文件夹中时PPVIEW32.exe就不能读取powerpoint文件.例如:
powerpoint文件存放Documents and Settings文件夹时,PPVIEW32.exe就不能读取powerpoint文件,因为Documents and Settings文件夹的名字有空格。但放在windows文件夹时就能读取。
但是我们的VB打包安装后都是存放在program file文件夹中的,所以不能解决这个问题。请大家帮忙,谢谢!!!!!!!!!
2.调用时最好不要用shell,而是用ShellExecute,可以识别长文件名,例子如下:
模块中:
Public Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Public Declare Function GetShortPathName Lib "kernel32" Alias "GetShortPathNameA" (ByVal lpszLongPath As String, ByVal lpszShortPath As String, ByVal cchBuffer As Long) As Long
程序中:
Private Sub Command1_Click()
ShellExecute Me.hwnd, "open", "C:\Program Files\12345.pps", vbnulls, vbnulls, 0
End Sub
在xp下面运行通过3.在上面例子的模块中,有一个没有用到的api:GetShortPathName,把它也放进去,是因为考虑到你可能有需要一定要用PPVIEW32.exe来装载powerpoint文件,那么它可以帮你忙,你上面说的不能读取的情况,其实就是因为长文件名引起的,把它转换为短名就可以了,两种方法比较的示例代码如下:
模块中:
Public Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Public Declare Function GetShortPathName Lib "kernel32" Alias "GetShortPathNameA" (ByVal lpszLongPath As String, ByVal lpszShortPath As String, ByVal cchBuffer As Long) As Long程序中:
Private Sub Command1_Click()
ShellExecute Me.hwnd, "open", "C:\Program Files\12345.pps", vbnulls, vbnulls, 0
End SubPrivate Sub Command2_Click()
Dim rc As Long
Dim ppShortPath As String
Dim fileshortpath As String
Const PATH_LEN& = 164'get the short filename
ppShortPath = String$(PATH_LEN + 1, 0)
rc = GetShortPathName("D:\Program Files\Microsoft Office\Office\Xlators\PPVIEW32.EXE", ppShortPath, PATH_LEN)
ppShortPath = Left$(ppShortPath, rc)fileshortpath = String$(PATH_LEN + 1, 0)
rc = GetShortPathName("C:\Program Files\12345.ppt", fileshortpath, PATH_LEN)
fileshortpath = Left$(fileshortpath, rc)
Print ppShortPath + " " + fileshortpathShell ppShortPath + " " + fileshortpath, vbNormalFocus
End Sub上例中,ppt和pps文件都放在C:\Program Files下,PPVIEW32.EXE
放在D:\Program Files\Microsoft Office\Office\Xlators下。。
喜欢用哪种你看情况吧