I have these media files and when I double click on any one of them it will launch the appropriate media application to play it so how can I emulate this double click from my program. My program will display a list of all the files and when I click on one of the names in the listbox I want to also double click on the actual file so it will bring up the application to play it
Is there a another way which might be a better way to do this
I'm not sure that is what I am looking for. First, my program wont know what application to shell and second my program won't know how to pass the path of the file to the shelled application. I looking for a way to emulate the effects of double clicking on the file itself so it will launch the app instead of my program shelling it and then having to pass to it the path of the file. The application that will be launched can change from one time to another and it can be different from one PC to another. It will depend on what application users will use to play these files; it would be whatever they choose.
Last edited by On Error Try Again; Aug 18th, 2016 at 11:59 AM.
ShellExecute is what you want. It will use the default application associated with the file extension to open the selected file. You will however need the full path to the file you are intending to launch. Since you are adding the files to a listbox, it sounds like you should also be able to access the file path.
Shell "C:\Program Files\Ahead\Nero ShowTime\ShowTime.exe D:\DVD Movies\Dark Country" and it plays the video
but on my friend's PC the above won't work and he doesn't have Nero anyway and he uses WMP so I changed the above line to this:
Shell "C:\Program Files\Windows Media Player\wmplayer.exe D:\DVD Movies\Dark Country"
but that didn't work so I changed it again to this:
Shell "C:\Program Files\Windows Media Player\wmplayer.exe D:\DVD Movies\Dark Country\VIDEO_TS.IFO"
and that didn't work either but if I double click on VIDEO_TS.IFO it will launch WMP and play the video
Now, on someone else's PC it may not be either Nero nor WMP; it could be some other application that I'm not aware of. So the problem I'm having is knowing what to shell and then like with WMP it may or may not even work doing it using shell but it always works by double clicking on the file
Last edited by On Error Try Again; Aug 18th, 2016 at 12:54 PM.
That's why people are suggesting ShellExecute instead of Shell.
Code:
Option Explicit
Private 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_SHOW = 5
Private Sub Command1_Click()
Dim strPath As String
strPath = "D:\DVD Movies\Dark Country\VIDEO_TS.IFO"
ShellExecute Me.hwnd, "open", strPath, vbNullString, vbNullString, SW_SHOW
End Sub
notice that I only need the name of the folder, 'Dark Country', and not the file name, 'VIDEO_TS.IFO', even though it is 'VIDEO_TS.IFO' that I have to double click on I don't need it in the code. This seems to only work with Nero and not WMP
so I'm still at a lost.
What happens when you double click on an ifo file in explorer? The same should happen using shellexecute.
I rarely play dvd images but I think media player wants you to open the vob file?
There must be some details we aren't getting here. If you can double click on the VIDEO_TS.IFO in windows explorer and it opens and "D:\DVD Movies\Dark Country\VIDEO_TS.IFO" is the proper full path then ShellExecute should work. What does this message box say if you run this code.
Code:
Option Explicit
Private 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_SHOW = 5
Private Sub Command1_Click()
Dim strPath As String
Dim ret As Long
strPath = "D:\DVD Movies\Dark Country\VIDEO_TS.IFO"
ret = ShellExecute(Me.hwnd, "open", strPath, vbNullString, vbNullString, SW_SHOW)
MsgBox ret
End Sub
I get 31 and nothing else happens. Clicking on a VOB file only gets you what is on that file so it wont be the entire video so that is why I click on IFO which tells the media player all the other files needed.
The ShellExecute() function returns the value 31 if there is no association for the specified file type. With that I find it hard to believe that on the machine where you are having this issue that double clicking VIDEO_TS.IFO in windows explorer will launch it.
Yes, it appears the lack of a file association is your problem. Also, just a couple of other FYI pointers.
I typically use zero (rather than one of my own form handles) for the first parameter. This causes the program to be executed without being associated with my program, but that's a personal preference (possibly situation dependent).
I typically, use SW_SHOWNORMAL (rather than SW_SHOW) for the last parameter. That way, if the program is already open but possibly hidden, minimized, or maybe drug off the screen, the SW_SHOWNORMAL (Const SW_SHOWNORMAL = 1) will fix that.
Also, if you wanted, you could actually build your strPath to have the full program-path-program-name and also the file-path-file name such that you'd be assured you'd find the program to open the data file. Done this way, the internal Shell command will probably get it done though. If you do use this approach, it's typically a good idea to surround the program filespec in quotes, and then the data filespec separately in quotes. Also, this has the downside of requiring that the program always be found in the same spot. An upside is that you circumvent any need for file associations.
I use ShellExecute all over the place, and find it to be a bulletproof and fantastic API function.
Regards,
Elroy
Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.
When I installed Nero on my machine it automatically associated itself with all the video file types (.IFO, .VOB, .BUP). If I double click on any .VOB file Nero is launched and it will play only the video data contained in that particular VOB file. If I click on any .IFO file Nero is launched and it will play the entire video from start to finish. Now, when I run my program and I use Shell I cannot include the .IFO file as part of the parameter input string as it will cause Nero to be launched but Nero will not play the video but if I omit the .IFO file name and only include the path to the video as I pointed out in my post #9 it will then play the entire video.
Now, this only works on my machine. On my friend's machine I have to Shell Wmplayer.exe + the path and name of the video I want to play but it doesn't work anyway. When I double click on the .IFO file in his directory it will launch WMP and play the video.
This is all very strange since if I go to the directory I have to double click on the .IFO file but in my code I cannot include it in the path using Shell.
I get nowhere using ShellExecute no matter what I do on my machine and on my friend's machine as well. Only Shell works but only for Nero on my machine. On my friend's machine nothing works from the program; I have to double click the .IFO file to get it to play
So this is the reason I asked if there is a way to automate double clicking and not use any Shell at all
I cannot install Nero on my friend's machine because I have a proprietary version of Nero that came with the Sony DVD player I installed on my machine and it wont work if you dont have that Sony player
Last edited by On Error Try Again; Aug 18th, 2016 at 02:56 PM.
In some projects of mine, I use ShellExecute to try to open a file with registered association, if any. If that API fails, then I launch an "Open With" dialog via run32dll.
On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
It dawns on me that some programs --- and, in particular, some media players --- create their own lpOperation verb, rather than having a default of "Open".
Try replacing the "Open" with a 0& (which would just be a null string). In such a case, Windows will attempt to identify a default verb, using that to open the file.
Quote from MSDN:
lpOperation [in, optional]
Type: LPCTSTR
A pointer to a null-terminated string, referred to in this case as a verb, that specifies the action to be performed. The set of available verbs depends on the particular file or folder. Generally, the actions available from an object's shortcut menu are available verbs. The following verbs are commonly used:
edit - Launches an editor and opens the document for editing. If lpFile is not a document file, the function will fail.
explore - Explores a folder specified by lpFile.
find - Initiates a search beginning in the directory specified by lpDirectory.
open - Opens the item specified by the lpFile parameter. The item can be a file or folder.
print - Prints the file specified by lpFile. If lpFile is not a document file, the function fails.
NULL - The default verb is used, if available. If not, the "open" verb is used. If neither verb is available, the system uses the first verb listed in the registry.
IMHO, the ShellExecute basically IS a double-click, if used in this way. To actually emulate a double-click, what are you going to do? Open a copy of Windows Explorer, somehow navigate to your file, somehow select your file, and then spoof a double-click on the keyboard? ShellExecute is the way to do it.
Good Luck,
Elroy
Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.
Something else that comes to mind. Is there possibly Unicode in your media file name and/or in part of your path/folder name? From what you've said above, that does not appear to be the case. However, there is a ShellExecuteW that could be used in these cases, along with StrPtr to pass in Unicode strings.
I'm just really taking pot-shots though. It appears that Bonnie may have found a good idea to try if nothing else works.
Regards,
Elroy
Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.
hahaha, my gears are still turning, and you got it.
I'm glad, OnError.
Take Care,
Elroy
Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.
It appears when I use Shell or ShellExecute, Nero comes up and plays the same video over again even though I pass it a different name.
Here's what I did
1) Select 'Dark Country' from the listbox. Nero launches and plays 'Dark Country' as expected
2) Later I select 'Gladiator' and again Nero launches and play 'Dark Country' again
3) Select another title and again Nero launches and plays 'Dark Country' again
I know for sure I am always passing a new title in the string but always 'Dark Country' plays
However, if I go the the folders and double click on a different title (it's .IFO file) Nero will play the new video but when I return to my program later and select any title Nero still plays 'Dark Country'. I can't seem to get out of this problem.
Is it possible that somehow using Shell the 'Dark Country' title is still being passed to Nero regardless of which title I select
Using either MsgBox or Debug.Print, show yourself the filespec (path and name) that's being passed into ShellExecute. And do this immediately before the ShellExecute line.
This is just to convince yourself that the correct filespec is being passed in. Also, double-check these filespecs for both the name and path. I don't really use Nero, but maybe, if it can't find the file you specified, it just plays the last file.
Again, just pot-shots.
Elroy
EDIT1: Also, are you completely closing Nero between each song/movie? If not, maybe it's just adding the song/movie to it's queue (or playlist, of whatever it's called).
Last edited by Elroy; Aug 18th, 2016 at 06:31 PM.
Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.
Even if I reboot the PC it still plays 'Dark Country'
Yes, I am absolutely positive I am passing the correct path and file name
If I rename the folder Dark Country to X Dark Country and even if I pass Nero and different title it complains that there is not a valid video file so it appears that no matter what path and title I pass it always goes back to d:\dvd movies\dark country. I scanned the registry and no where is the name Dark Country found and I even renamed the title in Nero's bookmark file from Dark Country (which is the only place I was able to find the title) to Gladiator it still play Dark Country
Yet, if I double click on the file d:\dvd movies\gladiator\video_ts.ifo it will then and only then play Gladiator but if I go back to ny program and use shell again then it goes back and plays 'Dark Country' so this tell me that double clicking on the file is not the same as using Shell to do the double clicking for me
BTW: The command is Play, not Open
Last edited by On Error Try Again; Aug 18th, 2016 at 06:38 PM.
Hmmm, maybe try what Bonnie suggested, or learn to be a daily fan of Dark Country. GTG though. I do hope you get it sorted.
And yeah, I sort of suspected the verb was "play" but it's also almost certainly marked as the default.
Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.
Actually, yes. I've wrapped the smplayer/mplayer into my app for years, but I control where that program is and how it plays my video clips, specifying the smplayer.exe in ShellExecute when I run it. I also like VLC though and have considered switching.
Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.
You could have did that with a shell command as well by simply passing the program path and name along with the file path and name.
That of course is not what you indicated you wanted to do in the OP where you stated that you wanted to simulate a double click which of course would mean shellexecute
The difference is in the one case you tell it which program to use and in the other it works with any file that has an association registered.
If you selected a word doc it would open word, an AVI would open WMP or Showtime depending on your config, .vbp would open VB and so on
If you're so inclined, maybe start a new thread with the problem you're having now, so people don't get confused. You could probably copy-paste most of your post #22 to get it started.
It's also totally puzzling to me as to why that didn't work with ShellExecute. Also, just FYI, that's a well formatted string you're constructing for the batch file.
It's totally strange to me that you can't do something like the following:
Code:
Option Explicit
Private 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
Dim MovieName As String
'
'
Private Sub List1_DblClick()
Dim sShellLine As String
MovieName = List1.List(List1.ListIndex)
' The following string is copy-pasted directly from your post #28.
sShellLine = Chr(34) & "C:\Program Files\Ahead\Nero ShowTime\ShowTime.exe" & Chr(34) & " " & Chr(34) & "D:\DVD Movies\" & MovieName & Chr(34)
ShellExecute 0&, 0&, sShellLine, 0&, 0&, vbNormalFocus
End Sub
I certainly believe that you're having problems, but it just seems that the ShellExecute would do the same thing, and much more efficiently.
Regards,
Elroy
Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.
Can you tell me more about what D: is? Is this a file server or possibly a NAS box? If so, there may be some funny parsing going on. You may need to replace all your single "\" with double "\\".
I'm not sure why, but the ShellExecute isn't finding the file-specification you're passing it.
Regards,
Elroy
Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.
I'm almost tempted to install a copy of Nero and see it myself, but I'm not quite ready to go that far. Maybe others will jump in with some fresh ideas.
Elroy
Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.
Option Explicit
Private 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
Private Const SW_SHOWNORMAL = 1
Private Sub Command1_Click()
ShellExecute Me.hwnd, vbNullString, """F:\Movies\16 Blocks\VIDEO_TS\VIDEO_TS.IFO""", vbNullString, "C:\", SW_SHOWNORMAL
End Sub
Private Sub Command2_Click()
ShellExecute Me.hwnd, vbNullString, """F:\Movies\Comedy\Used Cars\VIDEO_TS\VIDEO_TS.IFO""", vbNullString, "C:\", SW_SHOWNORMAL
End Sub
By default ifo files open with Nero Showtime on my system.
The code works exactly as expected. Button1 launches Showtime and starts the movie 16 blocks, button2 launches showtime and starts the movie used cars.
If I click on the file in explorer and tell it to always open with Media Player then that same code launches media player and starts the correct movie.
I see no issue at all, shellexecute works as expected and launches whatever program is associated with the file type in question.
It does exactly the same thing as if I double click on the file in windows explorer
Do you really need to warp this in quotes. Would this work
"F:\Movies\16 Blocks\VIDEO_TS\VIDEO_TS.IFO"
Either way, I have to believe that when On Error is calling ShellExecute a second time he isn't passing the path he thinks he is. A little code showing how you're attempting that could help resolve the issue.
Private Sub List1_DblClick()
Dim sShellLine As String
Dim ret As Long
MovieName = List1.List(List1.ListIndex) & "\VIDEO_TS.IFO"
MovieName = "D:\DVD Movies\" & MovieName
' Make sure you have what you think you should have
MsgBox MovieName
sShellLine = Chr(34) & MovieName & Chr(34)
ret = ShellExecute(Me.hWnd, 0&, sShellLine, 0&, 0&, vbNormalFocus)
MsgBox ret
End Sub
A return code less than 33 is an error. Greater that 33 is fine.