|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
How to access related documents in VB through source code?Hi, friends,
In our VB app, we need to add some documents into Related Document folder of VB IDE, such as .res files, .wav files. But, then, how to access those related documents from VB forms/modules? Any sample code or reference paper? Thanks a lot. "Andrew" <And***@discussions.microsoft.com> wrote in message I'm afraid you're going to find that related files aren't as robust as news:2FF681FD-F87A-49ED-BCB8-7A52D85A28ED@microsoft.com... > In our VB app, we need to add some documents into Related Document folder > of > VB IDE, such as .res files, .wav files. But, then, how to access those > related documents from VB forms/modules? > > Any sample code or reference paper? Thanks a lot. you're hoping they'd be. The concept of related files is mainly for project management and allows the VB IDE to display these files in the project explorer and give them the benefits of such, like easy access to source code operations. As far as your code is concerned, though, those files are nothing special (except for one resource file). You'd still need to read the ..wav file from disk if you make it a related file (and you may have to manually add it to your setup package; I'm not sure if the P&D Wizard knows about related files). In order to embed things like wave files into your program you'd need to add them to your resource file as a custom resource and then use the resource functions to pull them out. "In order to embed things like wave files into your program you'd need to add
them to your resource file as a custom resource and then use the resource functions to pull them out." Could you talk more about "resource functions to pull them out"? Any sample source code or reference papers? Thanks. Show quoteHide quote "Jeff Johnson [MVP: VB]" wrote: > > "Andrew" <And***@discussions.microsoft.com> wrote in message > news:2FF681FD-F87A-49ED-BCB8-7A52D85A28ED@microsoft.com... > > > In our VB app, we need to add some documents into Related Document folder > > of > > VB IDE, such as .res files, .wav files. But, then, how to access those > > related documents from VB forms/modules? > > > > Any sample code or reference paper? Thanks a lot. > > I'm afraid you're going to find that related files aren't as robust as > you're hoping they'd be. The concept of related files is mainly for project > management and allows the VB IDE to display these files in the project > explorer and give them the benefits of such, like easy access to source code > operations. As far as your code is concerned, though, those files are > nothing special (except for one resource file). You'd still need to read the > ..wav file from disk if you make it a related file (and you may have to > manually add it to your setup package; I'm not sure if the P&D Wizard knows > about related files). > > In order to embed things like wave files into your program you'd need to add > them to your resource file as a custom resource and then use the resource > functions to pull them out. > > > "Andrew" <And***@discussions.microsoft.com> wrote in message LoadResData()news:1F06118C-73CA-4B9A-8FCE-F4A9F3BA260B@microsoft.com... > "In order to embed things like wave files into your program you'd need to > add > them to your resource file as a custom resource and then use the resource > functions to pull them out." > > Could you talk more about "resource functions to pull them out"? > Any sample source code or reference papers? Thanks. You could search this group for that keyword (http://groups.google.com/advanced_search) or check the Web. I believe I used it to play a .wav file and I got the code from Karl Peterson's site (http://vb.mvps.org). It never worked in the IDE (GPF) but it worked fine in the compiled app. Check out LoadResData, LoadResPicture & LoadResString
Here's some code to play a Wav file in a Custom Resource: Private Declare Function sndPlaySound _ Lib "winmm.dll" Alias "sndPlaySoundA" ( _ ByVal lpszSoundName As String, _ ByVal uFlags As Long _ ) As Long Private Const SND_ASYNC = &H1 Private Const SND_NODEFAULT = &H2 Private Const SND_MEMORY = &H4 Private Sub Form_Load() Dim Ret As Long Dim SoundBuffer As String SoundBuffer = StrConv(LoadResData(101, "CUSTOM"), vbUnicode) Ret = sndPlaySound(SoundBuffer, SND_ASYNC Or SND_NODEFAULT Or SND_MEMORY) End Sub Show quoteHide quote "Andrew" <And***@discussions.microsoft.com> wrote in message news:1F06118C-73CA-4B9A-8FCE-F4A9F3BA260B@microsoft.com... > "In order to embed things like wave files into your program you'd need to add > them to your resource file as a custom resource and then use the resource > functions to pull them out." > > Could you talk more about "resource functions to pull them out"? Any sample > source code or reference papers? Thanks. > > > > "Jeff Johnson [MVP: VB]" wrote: > > > > > "Andrew" <And***@discussions.microsoft.com> wrote in message > > news:2FF681FD-F87A-49ED-BCB8-7A52D85A28ED@microsoft.com... > > > > > In our VB app, we need to add some documents into Related Document folder > > > of > > > VB IDE, such as .res files, .wav files. But, then, how to access those > > > related documents from VB forms/modules? > > > > > > Any sample code or reference paper? Thanks a lot. > > > > I'm afraid you're going to find that related files aren't as robust as > > you're hoping they'd be. The concept of related files is mainly for project > > management and allows the VB IDE to display these files in the project > > explorer and give them the benefits of such, like easy access to source code > > operations. As far as your code is concerned, though, those files are > > nothing special (except for one resource file). You'd still need to read the > > ..wav file from disk if you make it a related file (and you may have to > > manually add it to your setup package; I'm not sure if the P&D Wizard knows > > about related files). > > > > In order to embed things like wave files into your program you'd need to add > > them to your resource file as a custom resource and then use the resource > > functions to pull them out. > > > > > >
Show quote
Hide quote
"Norm Cook" <normcookNOSPAM@cableone.net> wrote in message Grrr! It drive me nuts when I see somebody use sndPlaySound to play a sound news:11liio2ga0f431f@corp.supernews.com... > Check out LoadResData, LoadResPicture & LoadResString > Here's some code to play a Wav file in a Custom Resource: > > Private Declare Function sndPlaySound _ > Lib "winmm.dll" Alias "sndPlaySoundA" ( _ > ByVal lpszSoundName As String, _ > ByVal uFlags As Long _ > ) As Long > Private Const SND_ASYNC = &H1 > Private Const SND_NODEFAULT = &H2 > Private Const SND_MEMORY = &H4 > > Private Sub Form_Load() > Dim Ret As Long > Dim SoundBuffer As String > SoundBuffer = StrConv(LoadResData(101, "CUSTOM"), vbUnicode) > Ret = sndPlaySound(SoundBuffer, SND_ASYNC Or SND_NODEFAULT Or SND_MEMORY) > End Sub from a resource. This can fail under Win2000, WinXP, and Win2003. It works for some .wav files added as a resource, but not for others. That makes sndPlaySound extremely unreliable. If you've never had problems with this under those versions of Windows, consider yourself very lucky. You should be using the PlaySound function. For one, it directly supports playing a sound resource. There's no need to explicitly load the resource data and do that conversion to a unicode string (which is what causes the problems with sndPlaySound). The only caveat is that the sound won't play when running your program within VB. That should hardly be a major issue as, presumably, beta versions are compiled to an EXE and tested. Here's your example re-written to use PlaySound. One thing you must do is change the resource type to "WAVE". -----BEGIN CODE Option Explicit Private Declare Function PlaySound Lib "WINMM.DLL" Alias "PlaySoundA" (ByVal lpszName As Any, ByVal hModule As Long, ByVal dwFlags As Long) As Long Private Const SND_ASYNC = &H1 Private Const SND_NODEFAULT = &H2 Private Const SND_RESOURCE = &H40004 Private Sub Form_Click() Call PlaySound(101&, App.hInstance, SND_ASYNC Or SND_RESOURCE Or SND_NODEFAULT) End Sub -----END CODE Compile to an EXE, run it, and click the form. If it doesn't play, make sure you've change the resource type to "WAVE", recompile, and try it again. Also notice that the resource ID must be a Long. -- Mike Microsoft MVP Visual Basic Hmmm, works here (win2k sp4)
At any rate, I was mainly trying to show the LoadResData usage Sorry if I drove you nuts. Show quoteHide quote "MikeD" <nob***@nowhere.edu> wrote in message news:%23XP3x7o1FHA.164@TK2MSFTNGP10.phx.gbl... > > "Norm Cook" <normcookNOSPAM@cableone.net> wrote in message > news:11liio2ga0f431f@corp.supernews.com... > > Check out LoadResData, LoadResPicture & LoadResString > > Here's some code to play a Wav file in a Custom Resource: > > > > Private Declare Function sndPlaySound _ > > Lib "winmm.dll" Alias "sndPlaySoundA" ( _ > > ByVal lpszSoundName As String, _ > > ByVal uFlags As Long _ > > ) As Long > > Private Const SND_ASYNC = &H1 > > Private Const SND_NODEFAULT = &H2 > > Private Const SND_MEMORY = &H4 > > > > Private Sub Form_Load() > > Dim Ret As Long > > Dim SoundBuffer As String > > SoundBuffer = StrConv(LoadResData(101, "CUSTOM"), vbUnicode) > > Ret = sndPlaySound(SoundBuffer, SND_ASYNC Or SND_NODEFAULT Or SND_MEMORY) > > End Sub > > Grrr! It drive me nuts when I see somebody use sndPlaySound to play a sound > from a resource. This can fail under Win2000, WinXP, and Win2003. It works > for some .wav files added as a resource, but not for others. That makes > sndPlaySound extremely unreliable. If you've never had problems with this > under those versions of Windows, consider yourself very lucky. > > You should be using the PlaySound function. For one, it directly supports > playing a sound resource. There's no need to explicitly load the resource > data and do that conversion to a unicode string (which is what causes the > problems with sndPlaySound). The only caveat is that the sound won't play > when running your program within VB. That should hardly be a major issue as, > presumably, beta versions are compiled to an EXE and tested. > > Here's your example re-written to use PlaySound. One thing you must do is > change the resource type to "WAVE". > > -----BEGIN CODE > Option Explicit > > Private Declare Function PlaySound Lib "WINMM.DLL" Alias "PlaySoundA" (ByVal > lpszName As Any, ByVal hModule As Long, ByVal dwFlags As Long) As Long > > Private Const SND_ASYNC = &H1 > Private Const SND_NODEFAULT = &H2 > Private Const SND_RESOURCE = &H40004 > > Private Sub Form_Click() > > Call PlaySound(101&, App.hInstance, SND_ASYNC Or SND_RESOURCE Or > SND_NODEFAULT) > > End Sub > -----END CODE > > Compile to an EXE, run it, and click the form. If it doesn't play, make sure > you've change the resource type to "WAVE", recompile, and try it again. > Also notice that the resource ID must be a Long. > > > -- > Mike > Microsoft MVP Visual Basic > >
Intergating Multiple VB6.0 Projects into one: Project Grouping
Parsing UNIX text files Return an error code/message from a VB6 app Extract ole object using vb from access db Is this possible ? Lost_Focus event of controls doesn't fire Intercept the Min/Max button Press Error 453: Can't find DLL entry point (VB6) Launching App Order of forms |
|||||||||||||||||||||||