Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Shell command doesn't work on jpg files

Status
Not open for further replies.

Helen1greece

Technical User
Jun 4, 2003
85
GR
Shell command doesn't work on jpg files. How can I open jpg files through VB?
 
The easy way is to put a picturebox on your form and then set the properties of the picturebox in the properties window...

autosize=true
picture= YOUR JPG FILE

click run
 
With shell you should use the application that opens the file ......

Private Sub Form_Load()
Shell "C:\Program Files\Accessories\MSPAINT.EXE f:\b.jpg"
End Sub
 
Another thing you can do is use a form to display the picture by setting the form's picture property...
 
The Shell function will only launch an executable although you can usually specify the file as a command line parameter. The ShellExecute API can open or a print a file in its registered application and avoids having to know whether a particular executable exists on the PC or its path.

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

Const SW_MAXIMIZE = 3 'Maximize the opened window
Const SW_MINIMIZE = 6 'Minimize the opened window
Const SW_SHOWNORMAL = 1 'Show the opened window and activate it (as usual)

Then to open a jpg file, call it as follows:

ShellExecute Me.hwnd, "open", "x:\path\xyz.jpg", _
vbNullString, vbNullString, SW_SHOWNORMAL

Paul Bent
Northwind IT Systems
 
I just want to open in order to see it.I don't need to run mspaint.Is it possible to do it?
 

You've got to open it in some application. Use internet explorer if you want to view it read only

Private Sub Form_Load()
Shell "C:\Program Files\Internet Explorer\Iexplore.exe f:\b.jpg"
End Sub
 

Picture1.Picture = LoadPicture("C:\SomePicture.jpg")
 
I want to do open the jpg file like it opens when I double click on it. Is it possible to do something like that?
 
Are you wanting to be able to edit the image or just view it?
If you just want to view it then the sugestions made by CCLINT and vbrocks are what you need to do.
I would suggest creating a form (frmPicture for example) and call that form from your existing form when you want to show a picture.

Private Sub List1_DblClick()
frmPicture.Picture = LoadPicture("c:\mypicture.jpg")
frmpicture.show
End Sub

Hope it helps

Greg Palmer

----------------------------------------
Any feed back is appreciated.
 
When I use Run from Start Menu and typing photo's pathname the photo opens with the program of windows for viewing photos. Why I can't acomplish that with sourc code on VB?
 
You can. The code was posted by paulbent already!
This will open with the same registered program.
 
The code which paulbent posted, doesn't work.Can somebody check it if it's right and give it to me again with an example of a button?
 
The code works just fine for me...
You didn't mention what is happening when you use it.

1. Drop the first part of the code into a public module.
2, Put the second part into the code window of a form as a sub proceedure (or place it also in the module as add an argument for a form variable, passing the form object to it)

The proceedure should have an argument (string) to accept a file path and name.

Replace the "x:\path\xyz.jpg" with the file variable name.

Call it by passing a file name to it.

 
Anyway to print this file after it is open and then close it??? A jpeg that is. I need to open the jpeg, print it, and close
 
I realize what Paulbent wrote
I tried using his code from above dropping the top portion into a module

I get the error:
Variable not defined:
and it highlights "SW_SHOWNORMAL"

Any suggestions
 
The constants used by ShellExecute are

Public Const SW_HIDE = 0 ' = vbHide
Public Const SW_SHOWNORMAL = 1 ' = vbNormal
Public Const SW_SHOWMINIMIZED = 2 ' = vbMinimizeFocus
Public Const SW_SHOWMAXIMIZED = 3 ' = vbMaximizedFocus
Public Const SW_SHOWNOACTIVATE = 4 ' = vbNormalNoFocus
Public Const SW_MINIMIZE = 6 ' = vbMinimizedNofocus
 
I have the following in the public module:
Option Explicit
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

Const SW_MAXIMIZE = 3 'Maximize the opened window
Const SW_MINIMIZE = 6 'Minimize the opened window
Const SW_SHOWNORMAL = 1 'Show the opened window and activate it (as usual)

Is this correct??
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top