Some of you may know the standard shell function:
Code: Select all
Shell ("C:\Games\Halo\Halo.exe")
To start off we're going to create a new project. Go ahead and stretch the form out to a comfortable length. Now this is the important part. Go to Project>References... Scroll down to Adobe Photoshop 9.0 (or your version number) Object Library and select the checkbox then hit Ok. Now Ctrl+S and save your form as "Main.frm" or whatever name you prefer. Then go to File>Save Project and save your project as "Photoshop.vpb" or again, as whatever you want but remember, organization is essential.
Now gee Blake, what the hell did I just do? Adding a reference to your project will have visual studio add an autocomplete list after typing in strings that can be filled further. For example, when you type in "Command1.", it shows the possible completions. It will now do the same for the reference you added. References are a library type, such as ".dll, .olb, .tlb" that define an application's external/internal actions.
So know if you type in "Photoshop." then you should see everything possible with this application. Now, we're not going to use 'Photoshop.' as our code statements because when our program compiles with that, it will refer to the reference to locate the application, which could be different depending on where someone has installed it. So create a command button and enter the following code for it:
Code: Select all
On Error Resume Next
Set PhotApp = GetObject(, "Photoshop.Application")
So now that "PhotApp" is set to the Class ID of Photoshop, you might be wondering why I made you set a reference earlier. Well that is for your own experimenting. For example, let's start off with this, type in "Photoshop." and view the list that appears, select "Application" and add another period for the next list to come up and this time select "Visible" then add a space and type in "= False". Your statement should look like this:
Code: Select all
Photoshop.Application.Visible = False
Code: Select all
Private Sub Command1_Click()
Set PhotApp = GetObject(, "Photoshop.Application")
Photoshop.Application.Visible = False
End Sub
Code: Select all
PhotApp.Application.Visible = False
Now go back to your visual form and add another command button, label them accordingly. This one is going to show/load the Application. By doing this, we will instead use the "CreateObject" statement. Since CreateObject will start a new instance of the program if it is not running, we must also add a statement. And by the way, there's no comma for the CreateObject statement because the ClassName is the first property. So you're whole code should look like this
Code: Select all
Private Sub Command1_Click()
On Error Resume Next
Set PhotApp = GetObject(, "Photoshop.Application")
Photoshop.Application.Visible = False
End Sub
Private Sub Command2_Click()
On Error Resume Next
Set PhotApp = CreateObject("Photoshop.Application")
Photoshop.Application.Visible = True
End Sub
Click the show/load button, whichever you labeled accordingly. Photoshop should load. Go ahead and click the other command button. Boom! Photoshop is hidden, even from Window's taskbar. Now click the show/load button again, the application should reappear. Cool, eh?
The rest of things work the same as this and testing your own ways of doing things. For a good statement that will load a file in Photoshop, I wrote:
Code: Select all
Private Sub Openfile_Click()
On Error GoTo Error1
cmdlg.Flags = cdlOFNHideReadOnly
With cmdlg
.DialogTitle = "Open"
.CancelError = False
.Filter = "All Files (*.*)|*.*|"
.ShowOpen
If Len(.FileName) = 0 Then
Exit Sub
End If
End With
Load.Text = cmdlg.FileName
Photoshop.Application.Load (Load)
If Photoshop.ActiveDocument.FullName = Load Then
MsgBox "Sucessfully opened " + Load, , "Complete"
Exit Sub
End If
Error1:
MsgBox "Not a valid Photoshop format", vbCritical, "Error"
End Sub
Download from Navy Leaf
EDIT: P.S. Please give feedback too