|
-
January 16th, 2010, 12:13 PM
#1
[RESOLVED] Help me with shell execute
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.
"Don't Bring A Knife To A Gun Fight"
-
January 16th, 2010, 01:57 PM
#2
Re: Help me with shell execute
See ShellExecute API...
Good Luck
-
January 16th, 2010, 03:01 PM
#3
Re: Help me with shell execute
 Originally Posted by NotepadGuru
what i need to know is,
when i click a button in my form, the c:\pic.jpg image should open in ms-paint.
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 ?
-
January 16th, 2010, 04:43 PM
#4
Re: Help me with shell execute
He said, mspaint it should be.
So the command would be:
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)
If the picturename could include blanks you might wish to enclose it in quotes:
Shell "mspaint " + chr$(34) + PictureName + chr$(34)
-
January 16th, 2010, 08:09 PM
#5
Re: Help me with shell execute
hmmm...
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????
-
January 17th, 2010, 10:56 AM
#6
Re: Help me with shell execute
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
-
January 18th, 2010, 12:53 AM
#7
Re: Help me with shell execute
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...
-
January 18th, 2010, 07:23 AM
#8
Re: Help me with shell execute
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.
-
January 18th, 2010, 08:45 AM
#9
Re: Help me with shell execute
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 :
Code:
Private Sub Command2_Click()
ShellExecute 0&, "open", "mspaint.exe", "C:\Test.png", vbNullString, vbMaximized
End Sub
Just to show it can be done. ShellExecute is best used with default applications, I agree
Last edited by HanneSThEGreaT; January 18th, 2010 at 08:47 AM.
-
January 18th, 2010, 09:39 AM
#10
Re: Help me with shell execute
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"
Last edited by moa; January 18th, 2010 at 09:42 AM.
-
February 3rd, 2010, 09:17 AM
#11
Re: Help me with shell execute
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 !
Code:
Private Sub Command1_Click()
lngErr = Shell("mspaint " + "D:\1.png")
End Sub
This does not work even though imgFname correctly returns a full path 
Code:
Public Function execute_file_in_paint(imgFname As String)
lngErr = Shell("mspaint " & """ & imgFname & """)
End Function
here is the error i get http://urlfly.in/6i
Last edited by NotepadGuru; February 3rd, 2010 at 09:21 AM.
"Don't Bring A Knife To A Gun Fight"
-
February 3rd, 2010, 09:23 AM
#12
Re: Help me with shell execute
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
-
February 3rd, 2010, 09:53 AM
#13
Re: Help me with shell execute
You simply mixed up the number of double-quotes.
try to print the string.
Code:
debug.print "mspaint " & """ & imgFname & """
and see what you get. You will find imgFname printet literally because it is within valid quotes. It must be
Code:
lngerr=Shell("mspaint """ & imgFname & """")
'or
lngerr=Shell("mspaint " & chr$(34) & imgFname & chr$(34))
-
February 3rd, 2010, 09:55 AM
#14
Re: Help me with shell execute
oh hannne,
let me check !!!
wof thank ill try men.
"Don't Bring A Knife To A Gun Fight"
-
February 3rd, 2010, 11:59 AM
#15
Re: Help me with shell execute
 Originally Posted by HanneSThEGreaT
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
hannie,
i dont type the path really, i come from a variable only dynamically
"Don't Bring A Knife To A Gun Fight"
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|