Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old February 15th, 2006, 12:47 AM
DonaldRennie DonaldRennie is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Feb 2006
Location: South Carolina (Wish I was in Vegas)
Posts: 14 DonaldRennie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 26 m 12 sec
Reputation Power: 0
VB and Windows Media Player

How can I programmically activate Media Player to play a selected audio file using Visual Basic? Thank you.

Reply With Quote
  #2  
Old February 15th, 2006, 09:41 AM
Darius Darius is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Posts: 108 Darius User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 h 16 m 54 sec
Reputation Power: 5
as module add
Code:
'Danke sehr  http://www.vbarchiv.net/vbapi/ShellExecute.php

'lpOperation        The operation to perform on lpFile. This can be one of the following strings, although other options are possible, depending on the file being acted upon:
'"explore"          If lpFile is a path name, open it in a Windows Explorer window.
'"open"             Open lpFile using its associated program. Opening an executable file runs it. This is the default action if none is specified.
'"print"            Print lpFile using its associated program.

'lpFile             The name of the file to open, print, execute, or whatever is specified by lpVerb.

'lpParameters       Additional parameters to use to perform the action. This would typically be additional command-line options to use, especially when running an executable file.


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_HIDE = 0
Private Const SW_MAXIMIZE = 3
Private Const SW_MINIMIZE = 6
Private Const SW_NORMAL = 1
Private Const SW_SHOW = 5
Private Const SW_RESTORE = 9
Private Const SW_SHOWMAXIMIZED = 3
Private Const SW_SHOWMINIMIZED = 2
Private Const SW_SHOWMINNOACTIVE = 7
Private Const SW_SHOWNA = 8
Private Const SW_SHOWNOACTIVATE = 4
Private Const SW_SHOWNORMAL = 1

Private Const ERROR_BAD_FORMAT = 11&
Private Const SE_ERR_ACCESSDENIED = 5
Private Const SE_ERR_ASSOCINCOMPLETE = 27
Private Const SE_ERR_DDEBUSY = 30
Private Const SE_ERR_DDEFAIL = 29
Private Const SE_ERR_DDETIMEOUT = 28
Private Const SE_ERR_DLLNOTFOUND = 32
Private Const SE_ERR_FNF = 2
Private Const SE_ERR_NOASSOC = 31
Private Const SE_ERR_OOM = 8
Private Const SE_ERR_PNF = 3
Private Const SE_ERR_SHARE = 26

Private Declare Function FindExecutable Lib "shell32.dll" Alias "FindExecutableA" _
  (ByVal lpFile As String, ByVal lpDirectory As String, ByVal lpResult As String) As Long
Private Declare Function lstrlen Lib "kernel32.dll" Alias "lstrlenA" _
  (ByVal lpString As Any) As Long

' FindExecutable Konstanen
Private Const ERROR_FILE_NOT_FOUND = 2&
Private Const ERROR_PATH_NOT_FOUND = 3&

Public Sub Execute(HWND As Long, PathName As String, FileName As String)
  Dim Retval As Long
  Dim ASSOCIATEDPROG As String
   ASSOCIATEDPROG = FindAssociatedProg(PathName, FileName)
   MsgBox ASSOCIATEDPROG
  Retval = ShellExecute(HWND, "open", Chr(34) & ASSOCIATEDPROG & Chr(34), _
    Chr(34) & PathName & "\" & FileName & Chr(34), Chr(34) & PathName & Chr(34), SW_SHOWNORMAL)

  Select Case Retval
    Case SE_ERR_NOASSOC
      MsgBox "Datei ist nicht Assizoiert", vbInformation, "Fehler"
      Exit Sub
    Case SE_ERR_PNF
      MsgBox "Pfad wurde nicht gefunden", vbInformation, "Fehler"
      Exit Sub
    Case SE_ERR_FNF
      MsgBox "Datei wurde nicht gefunden", vbInformation, "Fehler"
      Exit Sub
    Case 8, 26, 32, 28, 29, 30, 27, 5, 11 ' alle anderen Fehler
      Exit Sub
  End Select
End Sub

Function FindAssociatedProg(PathName As String, FileName As String) As String
  Dim Retval As Long, Puffer As String
  Puffer = Space(256)
  Retval = FindExecutable(FileName, PathName, Puffer)
  If Retval = 42 Then FindAssociatedProg = Left$(Puffer, lstrlen(Puffer))
End Function


In your program

Execute Me.HWND, File1.Path, File1.FileName

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingVisual Basic Programming > VB and Windows Media Player


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT