Hi all,
Following Code will allow you to run any AVI file in a Picture Box.
Comment and Rate it!
API Declarations - Const WS_CHILD = &H40000000
-
-
Private Declare Function mciSendString Lib "winmm.dll" Alias _
-
"mciSendStringA" (ByVal lpstrCommand As String, _
-
ByVal lpstrReturnString As String, ByVal uReturnLength As Long, _
-
ByVal hwndCallback As Long) As Long
-
-
Private Declare Function mciGetErrorString Lib "winmm.dll" Alias _
-
"mciGetErrorStringA" (ByVal dwError As Long, _
-
ByVal lpstrBuffer As String, ByVal uLength As Long) As Long
-
-
Private Declare Function GetShortPathName Lib "kernel32.dll" Alias _
-
"GetShortPathNameA" (ByVal lpszLongPath As String, _
-
ByVal lpszShortPath As String, ByVal cchBuffer As Long) As Long
Module CODE - ' FileName is a string containing the full path of the file.
-
' Window is the PictureBox in which you want that the movie
-
' is played; the movie is automatically resized to the picture box
-
-
Sub PlayAVIPictureBox(FileName As String, ByVal Window As PictureBox)
-
Dim RetVal As Long
-
Dim CommandString As String
-
Dim ShortFileName As String * 260
-
Dim deviceIsOpen As Boolean
-
-
' Retrieve short file name format
-
RetVal = GetShortPathName(FileName, ShortFileName, Len(ShortFileName))
-
FileName = Left$(ShortFileName, RetVal)
-
-
' Open the device
-
CommandString = "Open " & FileName & " type AVIVideo alias AVIFile parent " & _
-
CStr(Window.hWnd) & " style " & CStr(WS_CHILD)
-
RetVal = mciSendString(CommandString, vbNullString, 0, 0&)
-
If RetVal Then GoTo error
-
' remember that the device is now open
-
deviceIsOpen = True
-
' Resize the movie to PictureBox size
-
CommandString = "put AVIFile window at 0 0 " & CStr _
-
(Window.ScaleWidth / Screen.TwipsPerPixelX) & " " & _
-
CStr(Window.ScaleHeight / Screen.TwipsPerPixelY)
-
RetVal = mciSendString(CommandString, vbNullString, 0, 0&)
-
If RetVal <> 0 Then GoTo error
-
-
' Play the file
-
CommandString = "Play AVIFile wait"
-
RetVal = mciSendString(CommandString, vbNullString, 0, 0&)
-
If RetVal <> 0 Then GoTo error
-
-
' Close the device
-
CommandString = "Close AVIFile"
-
RetVal = mciSendString(CommandString, vbNullString, 0, 0&)
-
If RetVal <> 0 Then GoTo error
-
-
Exit Sub
-
-
error:
-
' An error occurred.
-
' Get the error description
-
Dim ErrorString As String
-
ErrorString = Space$(256)
-
mciGetErrorString RetVal, ErrorString, Len(ErrorString)
-
ErrorString = Left$(ErrorString, InStr(ErrorString, vbNullChar) - 1)
-
-
' close the device if necessary
-
If deviceIsOpen Then
-
CommandString = "Close AVIFile"
-
mciSendString CommandString, vbNullString, 0, 0&
-
End If
-
-
' raise a custom error, with the proper description
-
Err.Raise 999, , ErrorString
-
-
End Sub
Using in a Form - 'Create a Form with a PictureBox and a Command Button
-
Option Explicit
-
-
Private Sub Command1_Click()
-
PlayAVIPictureBox "c:\winnt\clock.avi", Picture1
-
End Sub
Regards
>> ALI <<
2 12688
This is amazing,very good
Maybe it is because I am not using VB6, but using this code elsewhere, while technically "working" is a little queezy.
If I move the window that the picturebox is on, the video doesn't stay with it.
Like if i move the window 10 pixels to the right, the left 10 pixels on the video will be gone (as if the video was drawn on a laayer BEHIND the gui window and that layer doesn't move with the gui window)
Any thoughts?
Sign in to post your reply or Sign up for a free account.
Similar topics
by: MAK |
last post by:
Hello everyone,
I know how to add images and icons etc to dll file.
What I would like to know is there is a way to add those icons on the forms
during the run time from the dll or to reference it ...
|
by: Chris |
last post by:
Hi,
I am trying to set the position of a picture inside a picturebox with the
folowing code:
pctOutput.Picture = LoadPicture(App.Path & "\picture.bmp", ,
, , )
I didn't know what to fill...
|
by: Lin Ma |
last post by:
I have a asp web page with a link point to a file which depend on the
database information.
Sometime is a picture file sometime a word and some time is a PDF file.
For picture file, when user...
|
by: Harlan Messinger |
last post by:
Are files referenced in LONGDESC attributes supposed to be pure text; can or
should they have either block or inline HTML tags; can or should they be set
up as a fully W3C compliant web page (with...
|
by: Nutshell |
last post by:
Hi,
I created a web page which contains table. I use table cells to display a
picture using <img src>. The problem is that some pictures are not being
fully displayed, only a quarter of the left...
|
by: news.microsoft.com |
last post by:
Hello and first of all thank you for your time.
I am currently developing an ASP.net web page, which has data stored in SQL
Server. It is a web page for a State Agent and my problem is:
I need...
|
by: Daniel Walzenbach |
last post by:
Hi,
Imagine the following situation: I have an asp.net
application which allows uploading files to a SQL Server
2000 database (Files are stored as type "images"). As a
next step I would like to...
|
by: Jean Christophe Avard |
last post by:
Hi! I am designing an application wich comes with image file. These images
are copyrighted and they have to be accessible only from within the
application. At first, I tought I was going to store...
|
by: remya1000 |
last post by:
i'm using VB.Net Application program.
i'm creating 64 button dynamically during run time. and from database i'm getting the description, font color, back color and picture path. and if the picture...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |