473,395 Members | 2,151 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes and contribute your articles to a community of 473,395 developers and data experts.

Run AVI Files inside a Picture Box

Ali Rizwan
925 512MB
Hi all,
Following Code will allow you to run any AVI file in a Picture Box.
Comment and Rate it!

API Declarations

Expand|Select|Wrap|Line Numbers
  1. Const WS_CHILD = &H40000000                    
  2.  
  3. Private Declare Function mciSendString Lib "winmm.dll" Alias _                    
  4.     "mciSendStringA" (ByVal lpstrCommand As String, _                    
  5.     ByVal lpstrReturnString As String, ByVal uReturnLength As Long, _                    
  6.     ByVal hwndCallback As Long) As Long                    
  7.  
  8. Private Declare Function mciGetErrorString Lib "winmm.dll" Alias _                    
  9.     "mciGetErrorStringA" (ByVal dwError As Long, _                    
  10.     ByVal lpstrBuffer As String, ByVal uLength As Long) As Long                    
  11.  
  12. Private Declare Function GetShortPathName Lib "kernel32.dll" Alias _                    
  13.     "GetShortPathNameA" (ByVal lpszLongPath As String, _                    
  14.     ByVal lpszShortPath As String, ByVal cchBuffer As Long) As Long
Module CODE

Expand|Select|Wrap|Line Numbers
  1. ' FileName is a string containing the full path of the file.                    
  2. ' Window is the PictureBox in which you want that the movie                    
  3. ' is played; the movie is automatically resized to the picture box                    
  4.  
  5. Sub PlayAVIPictureBox(FileName As String, ByVal Window As PictureBox)                    
  6.     Dim RetVal As Long                    
  7.     Dim CommandString As String                    
  8.     Dim ShortFileName As String * 260                    
  9.     Dim deviceIsOpen As Boolean                    
  10.  
  11.     ' Retrieve short file name format                    
  12.     RetVal = GetShortPathName(FileName, ShortFileName, Len(ShortFileName))                    
  13.     FileName = Left$(ShortFileName, RetVal)                    
  14.  
  15.     ' Open the device                    
  16.     CommandString = "Open " & FileName & " type AVIVideo alias AVIFile parent " & _
  17.                        CStr(Window.hWnd)                    & " style " & CStr(WS_CHILD)                    
  18.     RetVal = mciSendString(CommandString, vbNullString, 0, 0&)                    
  19.     If RetVal Then GoTo error                    
  20.         ' remember that the device is now open                    
  21.         deviceIsOpen = True                    
  22.         ' Resize the movie to PictureBox size                    
  23.         CommandString = "put AVIFile window at 0 0 " & CStr _                    
  24.         (Window.ScaleWidth / Screen.TwipsPerPixelX) & " " & _                    
  25.         CStr(Window.ScaleHeight / Screen.TwipsPerPixelY)                    
  26.         RetVal = mciSendString(CommandString, vbNullString, 0, 0&)                    
  27.     If RetVal <> 0 Then GoTo error                    
  28.  
  29.     ' Play the file                    
  30.     CommandString = "Play AVIFile wait"                    
  31.     RetVal = mciSendString(CommandString, vbNullString, 0, 0&)                    
  32.     If RetVal <> 0 Then GoTo error                    
  33.  
  34.     ' Close the device                    
  35.     CommandString = "Close AVIFile"                    
  36.     RetVal = mciSendString(CommandString, vbNullString, 0, 0&)                    
  37.     If RetVal <> 0 Then GoTo error                    
  38.  
  39.     Exit Sub                    
  40.  
  41. error:                    
  42.     ' An error occurred.                    
  43.     ' Get the error description                    
  44.     Dim ErrorString As String                    
  45.     ErrorString = Space$(256)                    
  46.     mciGetErrorString RetVal, ErrorString, Len(ErrorString)                    
  47.     ErrorString = Left$(ErrorString, InStr(ErrorString, vbNullChar) - 1)                    
  48.  
  49.     ' close the device if necessary                    
  50.     If deviceIsOpen Then                    
  51.         CommandString = "Close AVIFile"                    
  52.         mciSendString CommandString, vbNullString, 0, 0&                    
  53.     End If                    
  54.  
  55.     ' raise a custom error, with the proper description                    
  56.     Err.Raise 999, , ErrorString                    
  57.  
  58. End Sub 

Using in a Form

Expand|Select|Wrap|Line Numbers
  1. 'Create a Form with a PictureBox and a Command Button
  2. Option Explicit
  3.  
  4. Private Sub Command1_Click()
  5.     PlayAVIPictureBox "c:\winnt\clock.avi", Picture1
  6. End Sub
Regards
>> ALI <<
Feb 25 '08 #1
2 12688
This is amazing,very good
Mar 29 '08 #2
Plater
7,872 Expert 4TB
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?
Jul 30 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

7
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 ...
4
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...
2
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...
51
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...
6
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...
1
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...
13
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...
7
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...
4
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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...
0
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
0
BarryA
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...
1
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...
0
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...
0
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...
0
tracyyun
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...
0
agi2029
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,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.