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

Message ListMessage List     Post MessagePost Message

  Drawing MFC icons on a chart
Posted by David Wilson on Sep-21-2019 04:33
Many thanks for your past help.

Our MFC application uses icons.
These are compiled resources, they do not exist as independent image files.
They are loaded using

HICON handle = CWinApp::LoadIcon(UINT nIDresource);

They are drawn using

CDC::DrawIcon(int x, int y, HICON handle);

I would like to draw these icons to a DrawArea (specifically, I would like to add these icons to an XYChart via its DrawArea after makeChart() has been called).

There doesn't seem to be any interface to do this.  In the ChartDirector sample code, the only way I could find to add images is from image files, via DrawArea::load() or CDML embedding.

Is there any way I can draw an icon at a specified XY location on a DrawArea without involving a file on disk? Scaling would be icing on the cake.

Many thanks,
Dave Wilson

  Re: Drawing MFC icons on a chart
Posted by Peter Kwan on Sep-22-2019 17:25
Hi David,

Please upgrade to ChartDirector for C++ 6.3. It supports using resources as images. All MFC/Qt sample code in ChartDirector for C++ 6.3 have been modified to load images from resources instead of files. See:

https://www.advsofteng.com/release63.html

For "scaling", do you mean you want the image to resize? MFC resources does not support "scalable images" in the sense of vector graphics. You can always resize raster images. If the image is small, and you increase its size, it will look blurred. If the image is big, and you decrease its size, it will look as good as it can be at the smaller size.

Note that an icon format supports multiple images of different sizes (16x16, 32x32, 64x64, etc) in a single icon file. When you display an icon, the system will pick the image that matches the require resolution. For many icons, the smaller icon image is different from the larger icon image. They may look similar, but the smaller icon image is not a resize of the large icon image.

The image formats (PNG, JPG, BMP) does not support multiple images in the same file. To achieve something similar to the icon, you would need to create multiple images of different sizes, and your code would need to decide which image to load. Alternative, you may use a large image, and ask ChartDirector to resize it before use. The CDML supports resizing with the width and height attributes. For ChartDirector API that uses images but does not support resizing, you can use the following method:

(a) Create a DrawArea and use DrawArea::load to load the large image resource into the DrawArea.

(b) Use DrawArea::resize to resize the image.

(c) Use BaseChart::setResource to register the DrawArea as in-memory resource.

You can then use the in-memory resource in the chart just like a normal resource.

Hope this can help.

Regards
Peter Kwan

  Re: Drawing MFC icons on a chart
Posted by David Wilson on Sep-24-2019 01:03
Thanks for you quick reply.

I'm still at an impasse though.

I'm working with MFC in Visual Studio.
What I have to work with are a bunch of bitmap resources in the local executable.

As far as I can tell, there are DrawArea image loading commands PNG, GIF, JPG and WMP images, but nothing for BMP.

Given a bitmap resource ID (e.g. IDB_FEEDER), I would like to load the bitmap into a DrawArea.  I can't figure out how to do this.

  Re: Drawing MFC icons on a chart
Posted by Peter Kwan on Sep-24-2019 12:52
Hi David,

Instead of bitmap resources, can you add the images to your executable as PNG resources? Apart from much small size due to PNG image compression, PNG resources supports transparency while bitmap resources does not support transparency. You can use Windows Paint of any graphics editor to load the BMP and save it as PNG.

In Visual Studio, you can go to resources view, and "Add Resource" to the executable. The "Add Resource" will list out some resource types such as icons, bitmaps, cursors, menu, etc.. These are resources that can be directly created and edited with Visual Studio. However, you can always add resources that you created somewhere else, such as a PNG image created with Windows Paint. Just press the "Import" button and import the PNG file as resource. The mfcdemo sample project that comes with ChartDirector are using PNG resources. You may use it as a reference.

If you must use BMP resources (eg. if the resources are in a DLL/EXE not under your control), you can use the syntax:

@//xyz.dll/bitmap/abc.bmp

In the above, xyz.dll is the DLL to load the resource from. The abc.bmp is the name of the BMP resource. If your resource do not have a name, it can be accessed using its ordinal number. Usually, the header file will contain a macro for the ordinal. For your case, the IDB_FEEDER is likely the macro for the ordinal. In this case, the path can be constructed like:

// construct the resource path from the macro
char path[1000];
sprintf(path, "@//xyz.dll/bitmap/%d", IDB_FEEDER);

(Note that we cannot directly include the macro inside the path text string, because the compiler will not expand the macro if it is in a text string.)

If you would like the resource to be loaded from the EXE that you compiled (in which case, it is suggest you use PNG resources instead), but you still want to use BMP resources, you can use the same syntax as above, but replace "xyz.dll" with the name of your executable. An example is:

// Get the running exe path
wchar_t exe_path[10000];
GetModuleFileName(NULL, exe_path, 10000);

char path[1000];
sprintf(path, "@//%s/bitmap/%d", (char*)WCHARtoUTF8(exe_path), IDB_FEEDER);

Hope this can help.

Regards
Peter Kwan


hausfrauen porno tube