private 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 getshortpathname lib "kernel32" alias "getshortpathnamea" (byval lpszlongpath as string, byval lpszshortpath as string, byval cchbuffer as long) as long private declare function setwindowpos lib "user32" (byval hwnd as long, byval hwndinsertafter as long, byval x as long, byval y as long, byval cx as long, byval cy as long, byval wflags as long) as long private function shortname(lname as string) as string '取得短文件名 dim s as string, i as long i = 512 s = space$(i) getshortpathname lname, s, i shortname = left$(s, instr(1, s, vbnullchar) - 1) end function
private function playmci(cmd as string, optional returnstr as string) as long '播放mci dim s as string s = space$(256) playmci = mcisendstring(cmd, s, 256, 0) returnstr = left$(s, instr(1, s, vbnullchar) - 1) end function
private function showvideo(strfilename as string, hwd as long, x as long, y as long, w as long, h as long) as long dim i as long, s as string if dir(strfilename, vbhidden or vbreadonly or vbsystem) = vbnullstring or strfilename = vbnullstring then exit function i = playmci("open """ & shortname(strfilename) & """ alias song parent " & hwd & " style " & ws_child & " wait") if i <> 0 then exit function i = playmci("status song window handle wait", s) if i <> 0 then goto fail i = val(s) if i = 0 then goto fail setwindowpos i, 0, x, y, w, h, 0 playmci "play song" showvideo = i '若成功返回视频窗口的句柄 exit function fail: playmci "close song" end function
private sub cmdplay_click() i=showvideo("h:/1.wmv", me.hwnd, 0, 0, 100, 100) '返回的这个句柄,很有用的,可用于移动窗口位置,或subclass它,加上弹出菜单,响应鼠标动作等 if i <> 0 then cmdplay.enabled = false cmdstop.enabled = true end if end sub private sub cmdstop_click() playmci "close song" cmdplay.enabled = true cmdstop.enabled = false end sub
private sub form_load() me.scalemode = 3 cmdplay.enabled = true cmdstop.enabled = false cmdplay.caption = "播放" cmdstop.caption = "停止" end sub private sub form_unload(cancel as integer) playmci "close song" end sub