Jump to content
Software FX Community

Q: On Export() to format usable in MS Word


Recommended Posts

Hi,

We are using Cfx4032.dll (5.0.14.1) for displaying charts in our application

(C++ VC 7.1, ATL/WTL) -- no problem here.

The new requirement is to export the results in the MS Word format.

I would like to use the Metafile format to place the chart image

to the generated pages. I hope the wmf image would be of the

smalest size. Is it possible to insert the result into the Word

document without storing it into an auxiliary file first?

If the answer is yes, then can this be done without using

the clipboard? The reason is that the clipboard may contain

important information (o.k. we can store the clipboard

content before the export and restore it after).

The final question is related to what CFX doc says:

"When the chart is exported to a Metafile, a Windows Metafile

will be created. Some programs (i.e. MS Word for windows)

can import only "PLACEABLE METAFILES". Chart FX

does not support this format. Please contact Software FX tech

support for conversion tools."

I tried to export to wmf file and it was possible to include it

into the Word document (MS Word 2002). Does it mean that

CFX now produces "PLACEABLE METAFILES" or the

newer Word is able to import the "NON-PLACEABLE

METAFILES"? (We would like to support Word from

the interface version 8 on -- I think it was Word 97 or so.)

Is the placeable/non-placeable related only to storing the

image in auxiliary files, or is it important also

in cases when the physical, intermediate file is not created?

Thanks,

Petr

--

Petr Prikryl (prikrylp at skil dot cz)

Link to post
Share on other sites

Some more questions...

"SoftwareFX Support" wrote:

> The GetPicture method gives you the chart as an OLE Picture object. It

> supports Bitmap and Metafile formats. [...]

Thanks for the hint. I will give it a try.

I have another question related to Export() and possibly related also

to GetPicture(). It is related to situation when the chart should contain

user-painted elements. We paint trend lines when PostPaint events

are detected. Can these be captured by Export() or GetPicture()?

Sorry for asking before trying that (much more complicated).

One more question, that can be related. When I created

the extremely shortened windows application that does not

create a visible application window, but only the invisible

window of ChartFX component as a child of desktop window,

the Export() to wmf was produced correctly, while export

to bmp produces a kind of image as if it was not painted.

When I tried the same in another application where the export

was done _after_ processing the WM_PAINT, the bmp result

was O.K. Could you comment that? The following shows

the core of the not working example (checking removed, simplified):

-----------------------------------------------------------#include

<atlbase.h>

[...]

#import "c:\Program Files\Common Files\Software FX Shared\sfxbar.dll"

#import "c:\Program Files\Common Files\Software FX Shared\Cfx4032.dll"

extern int WINAPI WinMain(HINSTANCE hInstance, [...]

{

CoInitialize(0);

[...]

{

// Create the instance of the Chart FX.

//

ChartfxLib::IChartFXPtr spChartFX;

IClassFactory2 *pFactory2;

LPUNKNOWN pUnk;

CoGetClassObject(__uuidof(ChartfxLib::ChartFX),

CLSCTX_INPROC_SERVER,

0,IID_IClassFactory2,

(LPVOID FAR *) &pFactory2);

hr = pFactory2->CreateInstanceLic(0, 0, IID_IUnknown,

0, // OLESTR("...put your

licence string here..."),

(LPVOID FAR *) &pUnk);

spChartFX = pUnk;

[... do Release(), etc. ...]

// Set demonstration data for the chart.

//

spChartFX->OpenDataEx(ChartfxLib::COD_VALUES, 2, 3);

spChartFX->GetSeries()->GetItem(0)->PutYvalue(0, 500);

[...]

spChartFX->CloseData(ChartfxLib::COD_VALUES);

[...]

// Create the invisible window of the Chart FX.

// Dimensions are set to 400x300.

//

const short cChartID = 9999;

hr =

spChartFX->CreateWnd(reinterpret_cast<long>(GetDesktopWindow()),

cChartID, 0, 0, 400, 300, WS_CHILD);

// Test the export (hardwired file names).

//

unlink("c:\\tmp\\chart.bmp");

unlink("c:\\tmp\\chart.tsv");

unlink("c:\\tmp\\chart.wmf");

hr = spChartFX->Export(ChartfxLib::CHART_BITMAP,

"c:\\tmp\\chart.bmp");

ATLASSERT(SUCCEEDED(hr)); // S_OK returned, but WRONG RESULT!!!

hr = spChartFX->Export(ChartfxLib::CHART_DATA,

"c:\\tmp\\chart.tsv");

ATLASSERT(SUCCEEDED(hr)); // S_OK returned

hr = spChartFX->Export(ChartfxLib::CHART_METAFILE,

"c:\\tmp\\chart.wmf");

ATLASSERT(SUCCEEDED(hr)); // S_FALSE returned

spChartFX = NULL; // Release()

}

[...]

}

----------------------------------------------------

Thanks for your time and experience,

Petr

--

Petr Prikryl (prikrylp at skil dot cz)

Link to post
Share on other sites

"SoftwareFX Support" wrote...

> 1) Yes. Paint events are fired when the chart is either exported or when

you

> use the GetPicture method.

Then can the observed problem with not-correct bitmap be a bug?

See the core of the code below.

> 2) Are you using Chart FX DLL or OCX ?

I am using the DLL. The code used to demonstrate the problem

with not correctly exporting the bitmap (and correctly exporting

the wmf and tsv) looks like the following (simplified):

-----------------------------------------------------------

[...]

#import "c:\Program Files\Common Files\Software FX Shared\sfxbar.dll"

#import "c:\Program Files\Common Files\Software FX Shared\Cfx4032.dll"

extern int WINAPI WinMain(HINSTANCE hInstance, [...]

{

CoInitialize(0);

[...]

{

// Create the instance of the Chart FX.

//

ChartfxLib::IChartFXPtr spChartFX;

IClassFactory2 *pFactory2;

LPUNKNOWN pUnk;

CoGetClassObject(__uuidof(ChartfxLib::ChartFX),

CLSCTX_INPROC_SERVER,

0,IID_IClassFactory2,

(LPVOID FAR *) &pFactory2);

hr = pFactory2->CreateInstanceLic(0, 0, IID_IUnknown,

0, // OLESTR("...put your

licence string here..."),

(LPVOID FAR *) &pUnk);

spChartFX = pUnk;

[... do Release(), etc. ...]

// Set demonstration data for the chart.

//

spChartFX->OpenDataEx(ChartfxLib::COD_VALUES, 2, 3);

spChartFX->GetSeries()->GetItem(0)->PutYvalue(0, 500);

[...]

spChartFX->CloseData(ChartfxLib::COD_VALUES);

[...]

// Create the invisible window of the Chart FX.

// Dimensions are set to 400x300.

//

const short cChartID = 9999;

hr =

spChartFX->CreateWnd(reinterpret_cast<long>(GetDesktopWindow()),

cChartID, 0, 0, 400, 300, WS_CHILD);

// Test the export (hardwired file names).

//

unlink("c:\\tmp\\chart.bmp");

unlink("c:\\tmp\\chart.tsv");

unlink("c:\\tmp\\chart.wmf");

hr = spChartFX->Export(ChartfxLib::CHART_BITMAP,

"c:\\tmp\\chart.bmp");

ATLASSERT(SUCCEEDED(hr)); // S_OK returned, but WRONG RESULT!!!

hr = spChartFX->Export(ChartfxLib::CHART_DATA,

"c:\\tmp\\chart.tsv");

ATLASSERT(SUCCEEDED(hr)); // S_OK returned

hr = spChartFX->Export(ChartfxLib::CHART_METAFILE,

"c:\\tmp\\chart.wmf");

ATLASSERT(SUCCEEDED(hr)); // S_FALSE returned

spChartFX = NULL; // Release()

}

[...]

}

----------------------------------------------------

Regards,

Petr

--

Petr Prikryl (prikrylp at skil dot cz)

Link to post
Share on other sites

What does: "Then can the observed problem with not-correct bitmap be a bug?" 

means ? What is "not-correct" means ? Can you attach the bitmap ?

Is CreateWnd returning SUCCESS ? The casting:

reinterpret_cast<long>(GetDesktopWindow()) may be incorrect depending on

what GetDesktopWindow are you using, if it is the one from MFC, this casting

will be incorrect as you need the HANDLE to the window not the pointer to

the MFC's CWnd object.

--

FP

Software FX

Link to post
Share on other sites

Hi,

To clarify the problems, I do attach full source of the testing application

with tests for success/failure of operations... (about 5 KB,

one ImgExport.cpp file, about 100 lines, compiled from command line).

The attached zip file contains also the batch file compile.bat that calls

cl.exe to obtain the ImgExport.exe.

When running the example, the chart.bmp, chart.tsv, and chart.wmf

are produced in the working directory. The files--as produced on

my computer--are also included in the zip archive.

"SoftwareFX Support" wrote...

> What does: "Then can the observed problem with not-correct bitmap be a

bug?"

> means ? What is "not-correct" means ? Can you attach the bitmap ?

See above. The bitmap seems to be technically correct (can be loaded

into a bitmap editor), but it has only 4x4 pixels (102 bytes).

> Is CreateWnd returning SUCCESS ? The casting:

> reinterpret_cast<long>(GetDesktopWindow()) may be incorrect depending on

> what GetDesktopWindow are you using, if it is the one from MFC, this

casting

> will be incorrect as you need the HANDLE to the window not the pointer to

> the MFC's CWnd object.

The source should make it clear. No MFC was used -- plain Win32.

Thanks,

Petr

--

Petr Prikryl (prikrylp at skil dot cz)

Link to post
Share on other sites
  • 6 months later...

"SoftwareFX Support" wrote...

> The GetPicture method gives you the chart as an OLE Picture object.

> It supports Bitmap and Metafile formats.

>

> You can then insert this object into your document, this method

> does NOT use the clipboard or a file.

Just to make sure... The OLE Picture object can be displayed

in the Word document only when the Cfx OLE Server is used, or not?

The problem is that ChartFX Client Server is used in app clients of

our application and we do not limit the number of our application

clients within the organization. In other words, we like the Cfx's

royalty-free license. We cannot use the Cfx OLE Server, which

has other licensing.

Is there any way to export to Word without using file or clipboard

still not to be forced to use the Cfx OLE Server?

Thanks for the information,

Petr

--

Petr Prikryl (prikrylp at skil dot cz)

Link to post
Share on other sites

> The OLE Picture object can be displayed

> in the Word document only when the Cfx OLE Server is used, or not?

The GetPicture method gives you the chart as a picture (Bitmap or Metafile)

this format does NOT require the Chart FX Office Add-In to be viewed. It is

a standard picture.

--

FP

Software FX

Link to post
Share on other sites

"SoftwareFX Support" wrote on inserting ChartFX picture into Word...

Petr Prikryl asked...

> > The OLE Picture object can be displayed

> > in the Word document only when the Cfx OLE Server is used, or not?

>

> The GetPicture method gives you the chart as a picture (Bitmap or

Metafile)

> this format does NOT require the Chart FX Office Add-In to be viewed. It

is

> a standard picture.

Well, I finally succeeded to Export() the image into the generated Word

document (you can download the sample application with C++ sources as

http://www.skil.cz/ExportWord/ExportWord1.zip).

However, I am still unsuccessful with inserting the result of GetPicture()

into the Word document (the goal is to avoid storing the image into

file first and also to avoid using clipboard). Now I understand that I get

IPictureDisp interface pointer and that it a kind of standard object

from the automation point of view. But I have no experience with

how such object can be inserted to Word (using what collections,

methods, properties).

Is there any sample that shows that?

Thanks for your time and experience,

Petr

--

Petr Prikryl (prikrylp at skil dot cz)

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...