ASE Home Page Products Download Purchase Support About ASE
ChartDirector Support
Forum HomeForum Home   SearchSearch

Message ListMessage List     Post MessagePost Message

  How to insert an icon from internal resource?
Posted by Daniel on May-19-2018 00:21
Hello Peter,

I work in VB6 and I need to insert in a certain xyz Chart a png picture. Usually you prefer to add these images from external files using the CDML facilities but in some cases it is necessary to load them from internal resources. In my case I stored the pictures in VB Resource Editor as Custom resource and I am able to get that png image in a picture control using the Microsoft Windows Acquisition Library v2.0 with a code as below :

Private Sub Form_Load()
    With New WIA.Vector
        .BinaryData = LoadResData(101, "CUSTOM")
        Set Picture1.Picture = .Picture
    End With
End Sub

The question is : how to add in the left side of xAxis a picture (logo) from an internal resource ?  Usually you do this using the addText method :

Call c.addText(200, 400, "<*block*><*img=logo.png*><*block*>").setAlignment(cd.BottomLeft)

But I need something more versatile so that to be able to compile my project without other external resources. Thank you in advance.

Kind Regards,
Daniel

  Re: How to insert an icon from internal resource?
Posted by Peter Kwan on May-20-2018 19:03
Hi Daniel,

The easiest method is to save the resource data to a temporary file, then you can use it in CDML. The performance of the modern Windows file system should make this method fast.

Regards
Peter Kwan

  Re: How to insert an icon from internal resource?
Posted by Daniel on May-21-2018 15:08
Hello Peter,
With other words you suggest that is not possible. Maybe it is not easy to understand that I just need to provide an exe file without any temporary file outside. Does ChartDirector have any other method to load a logo picture apart of CDML used extensively on all examples from documentation? It is hard to believe that such a trivial functionality is missing from one of the best library for charts.

Regards,
Daniel

  Re: How to insert an icon from internal resource?
Posted by Peter Kwan on May-21-2018 22:52
Hi Daniel,

Yes, in the method I propose, you can just distribute an EXE without any file outside. The image can be distributed as an embedded resource in your EXE. So your client only need to download one file, which is the EXE, and can run your program.

In your code, instead of using WIA.Vector, please use:

Dim temp() As Byte
temp = LoadResData(101, "CUSTOM")

'We assume the custom resource is a PNG image
Dim iFileNo As Integer
iFileNo = FreeFile
Open "logo.png" For Binary As #iFileNo
Put #iFileNo, ,temp
Close

Call c.addText(200, 400, "<*block*><*img=logo.png*><*block*>").setAlignment(cd.BottomLeft)

Hope this can help.

Regards
Peter Kwan

  Re: How to insert an icon from internal resource?
Posted by Daniel on May-23-2018 16:19
Attachments:
Hi Peter,

I don't know if you tested before but it doesn't work to me.  As you below, instead of my png logo stored as resource file the chartdirector returns the chart area picture on the left side ... Is it normal ?
logo.PNG

  Re: How to insert an icon from internal resource?
Posted by Peter Kwan on May-23-2018 21:28
Attachments:
Hi Daniel,

Yes, I have tested the code. I have attached my entire VB6 project for your reference. You can compile and run it to see if it works.

The only difference between the code used in my test project and the code posted in by last message is the file name. In my test project, I used the "custom101.png" as the file name (as it is a custom resource with ID 101). In the code I posted, I changed it to "logo.png", because your example code post in the forum is using this filename.

Are you using "logo.png" in your real code or are you using a different filename? Note that the filename used in the "Open" line must match the filename used in the <*img=xxx*> line, and the filename should not be used for other purpose.

If the above still cannot solve the problem, is it possible to create an example that can illustrate the problem (perhaps by modifying my sample code), and attached the VB6 project to help me reproduce the issue?

Regards
Peter Kwan
vb6_res_test.zip
vb6_res_test.zip

2.91 Kb