Play sound from resource
If you want to play sounds in your program, but don't want to ship extra .wav files and make sure there in the right path, or you don't want people ripping off your stored .wav files, you can play sounds from a resource file built in to your .exe file. Although Windows resources have a "WAVE" type, Visual Basic doesn't support it. The answer: use a binary resource and play the sound from memory!
AI
สรุปโดย AI: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.
ซอร์สโค้ด
'Declare a byte array to put the sound in Dim Sound() as Byte 'Load the binary resource into the byte array '101 is the resource identifier of your sound '"CUSTOM" is the resource type to use (CUSTOM is 'the default for binary) ' 'LoadResData automatically redims the variable 'so it's the right size Sound = LoadResData(101, "CUSTOM") 'Play the sound Call PlaySoundMem(VarPtr(Sound(0)), 0, SND_NOWAIT Or SND_NODEFAULT Or SND_MEMORY Or SND_ASYNC Or SND_NOSTOP) 'Clean up memory 'You wouldn't do this right away if you want to 'play the sound over and over Redim Sound(0)
ความคิดเห็นดั้งเดิม (3)
กู้คืนจาก Wayback Machine