Folks,
after long time i am back to vb again. so i forget the basics.
i even tried this searching on google, no luck though.
what i need to know is,
when i click a button in my form, the c:\pic.jpg image should open in ms-paint.
Printable View
Folks,
after long time i am back to vb again. so i forget the basics.
i even tried this searching on google, no luck though.
what i need to know is,
when i click a button in my form, the c:\pic.jpg image should open in ms-paint.
See ShellExecute API...
Good Luck
ShellExecute wil not forcibly open a jpg file with ms.paint.
Il will do so only if ms.paint is the executable associated with jpg extension ....
To Force to ms.paint without any doubt, Shell as to be used instead of ShelleExsecute !
NotePadGuru should be clearer : does he want to open the file with the executable associated with jpg extension on his system or does he want to force the opening with ms.paint ? :ehh:
He said, mspaint it should be.
So the command would be:
If the picturename could include blanks you might wish to enclose it in quotes:Code:Shell "mspaint "+PictureName
'or in case you attemt to wait for the process to finish, you better keep its process ID
Dim pID as Long
pID = Shell("mspaint "+PictureName)
Shell "mspaint " + chr$(34) + PictureName + chr$(34)
hmmm...
Quote:
ShellExecute
HINSTANCE ShellExecute(
HWND hwnd,
LPCTSTR lpOperation,
LPCTSTR lpFile,
LPCTSTR lpParameters,
LPCTSTR lpDirectory,
INT nShowCmd
);
'....
lpFile
Address of a null-terminated string that specifies the file to open or print or the folder to open or explore. The function can open an executable file or a document file. The function can print a document file.
lpParameters
If the lpFile parameter specifies an executable file, lpParameters is an address to a null-terminated string that specifies the parameters to be passed to the application.
If lpFile specifies a document file, lpParameters should be NULL.
[with very sarcastic voice]REEAAAALLLYYYYY!!!![/end sarcastic voice]
You were saying????
I think the Shell statement of VB even makes use of the ShellExecute() api, so both calls should be of the same result. Only with the direct API call you may have to terminate your strings with a chr$(0), as the definition requires a NULL terminated string.
I forgot to mention that also the Shell() function has an optional argument to specify the show-mode of the application started.
http://msdn.microsoft.com/en-us/libr...87(VS.60).aspx
I think you are right WoF in that shell is a wrapper for shell execute, and I do hope you know my sarcasm was pointed at moa. Also, with both you do not have to specify the full path if the program you are activating is in the environment path variable...
Yes, you were quoting moa, so I didn't feel offended, and I hope moa doesn't feel offended either. :)
I tend to use ShellExecute only for operations where I want the default application to handle a certain file, where I don't have to specify the exe, but both functions appear to be equal, except you can specify a default directory in ShellExecute. But I never needed to do this.
You have to supply the open statement as the operation parameter, then the mspaint.exe as the lpFileparameter, and lastly, the filename in lpParamaters
Here is an example on how to open MS Paint specifically for a file :
Just to show it can be done. ShellExecute is best used with default applications, I agree :)Code:Private Sub Command2_Click()
ShellExecute 0&, "open", "mspaint.exe", "C:\Test.png", vbNullString, vbMaximized
End Sub
Hello,
I don't feel offended.
vb5prgrmr quoted me because I said ShellExecute would "not forcibly open a jpg file with ms.paint.
Il will do so only if ms.paint is the executable associated with jpg extension ...."
And he is right : my expression was not precise enough.
Let me correct it that way :
If you do not need to open your file with the program associated with the extension, but want to force it to be opened with MsPaint, the use of Shell (anyway aleady integrated in VB) is easier and quite sufficient" .... :)
Sorry for this lack of precision and a a big applause to vb5prgrmr who (I am sure) just wanted to be more precise and not really "sarcacstic"
first sorry for late reply, my internet connection was disconnected some time for not paying the bill :)
thank you for the suggession. i felt Wof suggession was simple and stick to that.
but still facting an small issue.
This works !
This does not work even though imgFname correctly returns a full path :(Code:Private Sub Command1_Click()
lngErr = Shell("mspaint " + "D:\1.png")
End Sub
here is the error i get http://urlfly.in/6iCode:Public Function execute_file_in_paint(imgFname As String)
lngErr = Shell("mspaint " & """ & imgFname & """)
End Function
Why do you have the extra quotation marks in the function ¿
This works 100% for me :
Code:Option Explicit
Dim lngerr As Long
Public Function execute_file_in_paint(imgFname As String)
lngerr = Shell("mspaint " & imgFname)
End Function
Private Sub Command1_Click()
execute_file_in_paint "C:\test.png"
End Sub
You simply mixed up the number of double-quotes.
try to print the string.
and see what you get. You will find imgFname printet literally because it is within valid quotes. It must beCode:debug.print "mspaint " & """ & imgFname & """
Code:lngerr=Shell("mspaint """ & imgFname & """")
'or
lngerr=Shell("mspaint " & chr$(34) & imgFname & chr$(34))
oh hannne,
let me check !!!
wof thank ill try men.