如何实现使用程序启动机器里安装的PHOTOSHOP?
想在自己程序中加个功能,点击后自动启动PHOTOSHOP,最好是把某个PICTURE中的图片导入到PHOTOSHOP中
[解决办法]
先打开注册表,看看PhotoShop在注册表中启动文件信息存放位置。然后用程序访问注册表此位置内容,得到启动文件信息,再使用WinExec之类的API启动它。注意:PhotoShop各个版本不同,则注册表的内容也不同,有必要的话统统需要检查。例如我这里的CS版注册信息是:
[HKEY_LOCAL_MACHINE\SOFTWARE\Adobe\Photoshop\8.0]
"ApplicationPath "= "C:\\Program Files\\Adobe\\Photoshop CS\\ "
而启动文件是Photoshop.exe,这样就可以找到,并启动它了。
[解决办法]
' 以下代码在窗体中,请在窗体中加入一个 CommandButton (Command1)
Option Explicit
Private Declare Function RegOpenKeyEx Lib "advapi32.dll " Alias "RegOpenKeyExA " (ByVal hKey As Long, ByVal lpSubKey As String, ByVal ulOptions As Long, ByVal samDesired As Long, phkResult As Long) As Long
Private Declare Function RegCloseKey Lib "advapi32.dll " (ByVal hKey As Long) As Long
Private Declare Function RegQueryValueEx Lib "advapi32.dll " Alias "RegQueryValueExA " (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, lpData As Any, lpcbData As Long) As Long
Private Const KEY_ALL_ACCESS = &HF003F 'Permission for all types of access.
Private Const KEY_QUERY_VALUE = &H1 'Permission to query subkey data.
Private Const HKEY_LOCAL_MACHINE = &H80000002
Private Const REG_SZ = 1 'A string terminated by a null character.
Private Const REG_EXPAND_SZ = 2 'A null-terminated string which contains unexpanded environment variables.
' 启动 Photoshop 并打开传入的图像文件
Public Sub StartPhotoshop(Optional ByVal ImageFile As String)
Const RegKey_PS As String = "Software\Microsoft\Windows\CurrentVersion\App Paths\Photoshop.exe "
Dim sFile As String
If RegKeyExists(HKEY_LOCAL_MACHINE, RegKey_PS) Then
sFile = ReadRegString(HKEY_LOCAL_MACHINE, RegKey_PS, vbNullString)
If Len(sFile) > 0 Then
If Len(ImageFile) > 0 Then
ImageFile = " " " " & ImageFile & " " " "
End If
Shell sFile & " " & ImageFile, vbNormalFocus
End If
Else
MsgBox "没有安装 Photoshop ", vbInformation, App.Title
End If
End Sub
Private Function RegKeyExists(ByVal Key As Long, ByVal SubKey As String) As Boolean
Dim hKey As Long
If RegOpenKeyEx(Key, SubKey, 0, KEY_QUERY_VALUE, hKey) = 0 Then
RegKeyExists = True
RegCloseKey hKey
End If
End Function
Private Function ReadRegString(ByVal Key As Long, ByVal SubKey As String, ByVal ValueName As String, Optional ByVal Default As String) As String
Dim hKey As Long
Dim lLen As Long
Dim lType As Long
Dim sTmp As String
ReadRegString = Default
If RegOpenKeyEx(Key, SubKey, 0, KEY_ALL_ACCESS, hKey) = 0 Then
If RegQueryValueEx(hKey, ValueName, 0, lType, ByVal 0&, lLen) = 0 Then
If lType = REG_SZ Or lType = REG_EXPAND_SZ Then
sTmp = Space(lLen)
If RegQueryValueEx(hKey, ValueName, 0, lType, ByVal sTmp, lLen) = 0 Then
ReadRegString = Left(sTmp, lLen - 1)
End If
End If
End If
RegCloseKey hKey
End If
End Function
' 测试
Private Sub Command1_Click()
StartPhotoshop "C:\WINDOWS\Web\Wallpaper\peace.jpg "
End Sub