用vb 写了个 小软件如何给它添加背景音乐(midi)呢?偶想 直接生成 单个 exe文件 就像现在很多的 keygen一样。

解决方案 »

  1.   

    播放背景音乐   声明:    Declare Function MCISendString& Lib ″MMSYSTEM″ (ByVal LPSTRCOMMAND$, ByVal LPSTRRETURNSTR As Any, ByVal WRETURNLEN%, ByVal HCALLBACK%)   开始播放:    R% = MCISendString&(″OPEN EXAMPLE.MID TYPE SEQUENCER ALIAS NN″, 0&, 0, 0)    R% = MCISendString&(″PLAY NN FROM 0″, 0&, 0, 0)    R% = MCISendString&(″CLOSE ANIMATION″, 0&, 0, 0)   停止:   R% = MCISendString&(″OPEN EXAMPLE.MID TYPE SEQUENCER ALIAS NN″, 0&, 0, 0)    R% = MCISendString&(″STOP NN″, 0&, 0, 0)   R% = MCISendString&(″CLOSE ANIMATION″, 0&, 0, 0)   其中EXAMPLE.MID 为播放的文件,NN为自定义名称标志。
      

  2.   

    'This project needs a Common Dialog box, named 'CDBox'
    '  (To add the Common Dialog Box to your tools menu, go to Project->Components (or press CTRL-T)
    '   and select Microsoft Common Dialog control)
    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
    Dim Alias As String
    Private Sub Form_Load()    Const PlayTime = 10
        'Set the common dialog box' title
        CDBox.DialogTitle = "Choose your midi-file"
        'Set the filter
        CDBox.Filter = "Midi-files (*.mid)|*.mid"
        'Show the 'Open File'-dialog
        CDBox.ShowOpen
        'Extract an alias from the file
        Alias = Left$(CDBox.FileTitle, Len(CDBox.FileTitle) - 4)    'play midi
        R% = mciSendString("OPEN " + CDBox.filename + " TYPE SEQUENCER ALIAS " + Alias, 0&, 0, 0)
        R% = mciSendString("PLAY " + Alias + " FROM 0", 0&, 0, 0)
        R% = mciSendString("CLOSE ANIMATION", 0&, 0, 0)    'play midi for 10 secs
        t = Timer
        Do: DoEvents: Loop Until Timer > t + PlayTime    'stop midi and close it
        R% = mciSendString("OPEN " + CDBox.filename + " TYPE SEQUENCER ALIAS " + Alias, 0&, 0, 0)
        R% = mciSendString&("STOP " + Alias, 0&, 0, 0)
        R% = mciSendString&("CLOSE ANIMATION", 0&, 0, 0)
    End Sub
      

  3.   

    懒得写了...
    给我EMAIL:
    我给你一个控件吧,原是我打包好专门为播放背景音乐而做的...
    [email protected]
    注明:背景音乐
      

  4.   

    Public Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long
      

  5.   

    怎么能在程序中加入背景音乐 MIDI的 只要一个可执行文件 就象直接播放资源里的WAV那样 不要另释放文件那种
      

  6.   

    调用MediaPlayer的控件播放不就可以了
      

  7.   

    '这是我去年给自己写的五子棋添加的背景音乐源代码:'声明部分
    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 Sub Form_Load()
     mciSendString "open D:\WZQ\mp3.mid alias myMIDI", vbNullString, 0, 0
        mciSendString "play myMIDI", vbNullString, 0, 0
    End Sub
      

  8.   

    msdn 上没说 支持 midi 啊“可以被存储为自定义资源的公用数据类型有声音 (.wav) 和视频 (.avi) 文件。”
      

  9.   


    偶想 直接生成 单个 exe文件 关键是要生成 单个的exe 文件 ,作为资源导入,如何读取?请高人解答
      

  10.   

    我的那个是音乐文件作为一个单独的文件与EXE文件放在同一文件夹下才能用:)