•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the Visual Basic 4 / 5 / 6 section within the Software Development category of DaniWeb, a massive community of 392,060 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,240 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Visual Basic 4 / 5 / 6 advertiser:
Views: 3336 | Replies: 10
![]() |
•
•
Join Date: May 2005
Posts: 27
Reputation:
Rep Power: 4
Solved Threads: 0
I know pictures can be added to picture boxes and backgrounds by using the "Properties" and adding something to "Picture". But I want to know how I can actually get the program to display an animation or picture say, after inputting something into an inputbox, or say after a particular msgbox has been clicked "ok" and then for the picture or animation to show up...Something within the code itself I'm figuring, something that will be triggered after the user has begun the program and started doing stuff, not by clicking a button specifically. Can anyone understand me and better yet help me out?
Hi again..
Sounds like you want to play a video or animation - such as an mpeg or avi or so on.. the trigger event isn't the difficult bit, it's how to play it that might be...
There's several ways to do what you want. The easy way is to use the mediaplayer activex control that comes with DirectX. This is different to the one that media player upgrades install (wmp.dll), which is not as flexible for us VB types. In your Windows/system folder (or system32 if you're on win2K or XP) look for the file msdxm.ocx. If it's not there, go to Microsoft's web site and download and install DirectX. If it is, on VB go to Project -> Components; in the list find Windows Media Player and tick it, and click Apply & Close.
On your control toolbar you should now see the 'old' media player icon (like a clapperboard) Click this, and add it to your form. If you drag it out to a reasonable size, you'll see it is actually a mediaplayer with a display area and controls. You can remove the controls by setting the ShowControls property to false; you might want to play with these properties to get what you want.
Now to control it programmatically, you need to open a file, and then play it.
For a quick demo add a command button and paste this code:
You'll get a more instant response if you load the file at some time before you want to play it.
(see http://www.bitstorm.org/gates/ for this video clip :cheesy: )
Hope this helps
Alan
Sounds like you want to play a video or animation - such as an mpeg or avi or so on.. the trigger event isn't the difficult bit, it's how to play it that might be...
There's several ways to do what you want. The easy way is to use the mediaplayer activex control that comes with DirectX. This is different to the one that media player upgrades install (wmp.dll), which is not as flexible for us VB types. In your Windows/system folder (or system32 if you're on win2K or XP) look for the file msdxm.ocx. If it's not there, go to Microsoft's web site and download and install DirectX. If it is, on VB go to Project -> Components; in the list find Windows Media Player and tick it, and click Apply & Close.
On your control toolbar you should now see the 'old' media player icon (like a clapperboard) Click this, and add it to your form. If you drag it out to a reasonable size, you'll see it is actually a mediaplayer with a display area and controls. You can remove the controls by setting the ShowControls property to false; you might want to play with these properties to get what you want.
Now to control it programmatically, you need to open a file, and then play it.
For a quick demo add a command button and paste this code:
Private Sub Command1_Click() MediaPlayer1.FileName = "c:\creamedgates.mpeg" MediaPlayer1.play End Sub
You'll get a more instant response if you load the file at some time before you want to play it.
(see http://www.bitstorm.org/gates/ for this video clip :cheesy: )
Hope this helps
Alan
for just pictures, you can add textbox or variable values to the picture object to load a new picture if you use the correct format.
image1.picture =loadpicture("c:\vbrox.bmp")
image1.picture =loadpicture(text1.text)
image1.picture =loadpicture(strImage) .: We may acquire liberty, but it is never recovered if it is lost :.
irc://irc.rizon.net/#itf
irc://irc.rizon.net/#itf
OK so if I'd read your original post properly... for loading a still image into an image control jwshepherds code will work fine. But back to the movies!
Now if you had to change the object name, you might have used the new mediaplayer. No problem if it works for you in your application.
Getting the path right is something you need to be aware of when developing in VB, and it's best to explicitly set it. Two useful things are the App.Path property which returns the path of the application as a string... just type in the 'immediate' window of your VB editor:
Hit enter and you should see:
C:\Program Files\Microsoft Visual Studio\VB98\MyApp
or similar. The other useful thing is the ChDir command, which sets the current directory. The 'current directory' is where VB will look for any file you specify without the full path. You'll probably want to use the directory the app runs out of for any associated files, so you can use the following statement to change the directory to the application's:
You can also use the App.Path property together with a filename like these examples:
Note that the backslash has to be provided as the path doesn't include this. Beware of hard-coding paths into your program- if the user installs it somewhere else, they'll get an error when the app tries to load the file; so the method shown above is good practice.
cheers
Alan
Now if you had to change the object name, you might have used the new mediaplayer. No problem if it works for you in your application.
Getting the path right is something you need to be aware of when developing in VB, and it's best to explicitly set it. Two useful things are the App.Path property which returns the path of the application as a string... just type in the 'immediate' window of your VB editor:
print app.path
C:\Program Files\Microsoft Visual Studio\VB98\MyApp
or similar. The other useful thing is the ChDir command, which sets the current directory. The 'current directory' is where VB will look for any file you specify without the full path. You'll probably want to use the directory the app runs out of for any associated files, so you can use the following statement to change the directory to the application's:
'change directory to the application's ChDir App.Path 'load the file mediaplayer1.filename="intro.mpg"
mediaplayer1.filename=app.path & "\intro.mpg" 'when the files dir is a sub-dir of the application's mediaplayer1.filename=app.path & "\music\background.mp3"
cheers
Alan
•
•
Join Date: May 2005
Posts: 27
Reputation:
Rep Power: 4
Solved Threads: 0
No, the user get not control whatsoever. Heh... ok now here's the new problem. I get evrything done like you said, but when I run it, I get another runtime error:
"Run-Time Error '438':
Object doesn't support this property or method."
I got that with your previous tips as well. Then to debug it it highlights :
WindowsMediaPlayer1.FileName = App.Path & "\car.mpg"
which is the file I am trying to play. I actually moved the car.mpg file into my vb directory that was shown. hehe coz I didn't know how to change it in this... "VB editor". Whats that? I just opened a form and askde the program to "Print App.Path" from a command button.
"Run-Time Error '438':
Object doesn't support this property or method."
I got that with your previous tips as well. Then to debug it it highlights :
WindowsMediaPlayer1.FileName = App.Path & "\car.mpg"
which is the file I am trying to play. I actually moved the car.mpg file into my vb directory that was shown. hehe coz I didn't know how to change it in this... "VB editor". Whats that? I just opened a form and askde the program to "Print App.Path" from a command button.
Right. Sounds like you're using the 'wrong' mediaplayer. That explains the previous error you got as well! That's why I went on about msdxm.ocx; if you followed what I said in the very first reply you should be able to find this file (From Project menu -> components, click the browse button and look in either Windows/System or Windows/System32 for the file msdxm.ocx or msdxmp.ocx. When you've found it click 'open'. You may have two 'Windows Media Player' entries in the components list now. You need to select the one that, when highlighted, gives a line similar to:
c:\windows\system\msdxm.ocx
in the frame below the components list. When you check it and click Apply, it should look like a little film clapperboard in the object panel on the left of your screen. When you add it to your form, it's default name will be 'MediaPlayer1' This has loads more properties than the WMP.DLL one, which calls itself WindowsMediaPlayer1.
What version of VB are you using?
By the Editor I meant the VB IDE- the project design screen; if you don't have a window called 'immediate' then click View on the menu and then Immediate and it should appear. You can use this to test VB commands, and also get your program to print diagnostic info to it using statements like 'debug.print <variable>'.
Let me know how you get on.
Cheers
Alan
c:\windows\system\msdxm.ocx
in the frame below the components list. When you check it and click Apply, it should look like a little film clapperboard in the object panel on the left of your screen. When you add it to your form, it's default name will be 'MediaPlayer1' This has loads more properties than the WMP.DLL one, which calls itself WindowsMediaPlayer1.
What version of VB are you using?
By the Editor I meant the VB IDE- the project design screen; if you don't have a window called 'immediate' then click View on the menu and then Immediate and it should appear. You can use this to test VB commands, and also get your program to print diagnostic info to it using statements like 'debug.print <variable>'.
Let me know how you get on.
Cheers
Alan
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb Visual Basic 4 / 5 / 6 Marketplace
Similar Threads
- adding pictures?!! (ASP.NET)
Other Threads in the Visual Basic 4 / 5 / 6 Forum
- Previous Thread: Adodb=adodc???
- Next Thread: Command Prompt and Visual Basic


Linear Mode