You are not logged in.

Dear visitor, welcome to Jabaco - Community. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

OlimilO

Intermediate

  • "OlimilO" is male
  • "OlimilO" started this thread

Posts: 277

Date of registration: Jan 18th 2009

Location: Germany

Occupation: software engineer

  • Send private message

1

Wednesday, March 11th 2009, 2:57pm

Resources

Hello Jabaco fans,

there are already a few threads that touch on this subject:

Loadpicture ; create jabaco menu and toolbar ;

I also want to mention maXim's RCC-tool. @maXim Thanks a lot for this nice piece of software :)
from his project I first learned how picture resources can be used in Jabaco.

are you curious ?

read more ...

This post has been edited 3 times, last edit by "OlimilO" (Mar 11th 2009, 5:28pm)


OlimilO

Intermediate

  • "OlimilO" is male
  • "OlimilO" started this thread

Posts: 277

Date of registration: Jan 18th 2009

Location: Germany

Occupation: software engineer

  • Send private message

2

Wednesday, March 11th 2009, 3:32pm

1. basics

let's start:

select the files you want to integrate in your project:

in Jabaco right click on the project-explorer select the menu item "Add File..." or click the button "Add File...". From the drop-down menu select the menu item "Resource". An open-file-dialog appears where you can select your files.

After selecting a file, Jabaco does the following things for you:

* the files immediately will be copied to a new sub direcotry named "Res" below your jabaco-project folder
* for each file an object of type IResource will be created that can be accessed through the static object "Resources" with a dynamically created property with the name of your file

example:

Jabaco Source

1
Picture1.Picture = Resources.MyPicPng


the name will be simplyfied a little bit, points and other non alphanum-characters will be eliminated, just to create a valid property name.
OlimilO has attached the following images:
  • ProjectExplorer.png
  • PropertyEditor.png

This post has been edited 5 times, last edit by "OlimilO" (Mar 11th 2009, 5:25pm)


OlimilO

Intermediate

  • "OlimilO" is male
  • "OlimilO" started this thread

Posts: 277

Date of registration: Jan 18th 2009

Location: Germany

Occupation: software engineer

  • Send private message

3

Wednesday, March 11th 2009, 4:22pm

2. picture resources (pixel based)

I also have bad news: i made bad experiences with pictures of type

*.bmp (windows-bitmaps) and
*.ico (windows-icons)

i did not get them to work. maybe because they are not supported under linux.
But don't bother you

*.png-, *.jpg- and *.gif-files work fine.

imho: the winner of all type of pictures is the png-format

Property Editor:
for a PictureBox control and everywhere where you have a Picture property, you simply can select the image you like in the Property-editor.

Source Code:
in your sourcecode you can use the dynamically created property of the static Resources object (as mentioned above) to assign a picture where it suits for your needs.

Traps:
the CommandButton has a Picture-property. You can select an image for it, and in the Jabaco-IDE you are able to see the picture on the button. But styled buttons in windows are not capable of holding a picture on it. So this does not work under WinXP with styled themes.

maybe als have a short look into the tiny little jabaco project attached

greetings

OlimilO
OlimilO has attached the following file:

This post has been edited 1 times, last edit by "OlimilO" (Mar 11th 2009, 4:59pm)


OlimilO

Intermediate

  • "OlimilO" is male
  • "OlimilO" started this thread

Posts: 277

Date of registration: Jan 18th 2009

Location: Germany

Occupation: software engineer

  • Send private message

4

Sunday, March 15th 2009, 9:24pm

3. Wave audio resources

in VB6 you know the function LoadResData that returns an Array of Bytes and you can use it there like this:

Jabaco Source

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Private m_Wave() As Byte
Private Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" ( _
    ByRef lpSound As Byte, ByVal hModule As Long, ByVal dwFlags As Long) As Long
Private Const SND_MEMORY As Long = &H4
Private Sub Form_Load()
'Function LoadResData(id, type)
'  Mitglied von VB.Global
'  Lädt Daten von verschiedenen möglichen Typen aus einer
'  Ressourcendatei (.RES) und gibt ein Byte-Array zurück.
'Type: "WAVE", id: 101
   m_Wave = LoadResData(101, "WAVE")
End Sub
Private Sub Command1_Click()
    PlaySound m_Wave(0), 0, SND_MEMORY
End Sub


in Jabaco afair, there is no LoadResData-function but it simply can be written like this:

Jabaco Source

1
2
3
Public Function LoadResData(resID As IResource) As InputStream
   Set LoadResData = getClass.getResourceAsStream(resID)
End Function


we can combine it with something like this:

Jabaco Source

1
2
3
4
Public Function GetWavResClip(ResID As IResource) As Clip
   GetWavResClip = AudioSystem.getClip
   GetWavResClip.open(AudioSystem.getAudioInputStream(LoadResData(ResID)))
End Function


we can play it with:

Jabaco Source

1
2
3
4
5
6
Private Sub Command1_Click()
   Dim clip1 As Clip = GetWavResClip(Resources.ChimesWav)
   Dim clip2 As Clip = GetWavResClip(Resources.TadaWav)
   clip1.start
   clip2.start
End Sub


btw: of course the two sounds will be played mixed together in one :D

greetings
OlimilO

This post has been edited 1 times, last edit by "OlimilO" (Mar 15th 2009, 9:32pm)


JasonS

Trainee

  • "JasonS" is male

Posts: 65

Date of registration: Feb 17th 2010

  • Send private message

5

Thursday, October 27th 2011, 11:09pm

LoadResData and GetWavResClip

Hello,

Thank you for these function samples, greatly appriciated! :thumbup: However, I have found that these functions need to empty out its holder variable before loading a resource into them if they are going to be heavily used, in order to avoid heap space/memory leak exceptions:

Jabaco Source

1
2
3
4
5
6
7
8
9
10
Public Function LoadResData(resID As IResource) As InputStream
   Set LoadResData = Nothing
   Set LoadResData = getClass.getResourceAsStream(resID)
End Function

Public Function GetWavResClip(ResID As IResource) As Clip
   Set GetWavResClip = Nothing
   GetWavResClip = AudioSystem.getClip
   GetWavResClip.open(AudioSystem.getAudioInputStream(LoadResData(ResID)))
End Function


-Jason

This post has been edited 1 times, last edit by "JasonS" (Oct 27th 2011, 11:15pm)


Rate this thread
WoltLab Burning Board