Jump to content
Software FX Community

Problems getting Legend box to display properly in a metafile


Recommended Posts

Hi,

I'm having problems getting the legendbox to show up correctly when I export it to a metafile via the paint method.

picture of the problem:

Code for values and drawing:

for( int j = 0; j < ~coldefs; j++ ){

for( int k =0; k < ~grp_values; k++ ){

chart_fx->GetSeries()->GetItem( j )->PutYvalue( k, report_values[j][k].GetNumeric() );

}

}

chart_fx->CloseData( COD_VALUES );

if( dbview->GetFlags( DBVIEW_GRAPH_MASK ) != DBVIEW_GRAPH_PIE ){

frep_( i, ~grp_values ){

cstring str;

scale ? chart_fx->GetAxis()->GetItem( AXIS_X )->PutLabel( i, (char*)scale->GetShortName( i, str ) ) : chart_fx->GetAxis()->GetItem( AXIS_X )- >PutLabel( i, (char*)(LPCSTR)grp_values[i].GetString());

}

}

else{

frep_( i, ~grp_values ){

cstring str;

scale ? chart_fx->PutLegend( i, (char*)scale->GetShortName( i, str ) ) : chart_fx->PutLegend( i, (char*)(LPCSTR)grp_values[i].GetString());

}

chart_fx->PutLegendBox( 1 );

chart_fx->GetLegendBoxObj()->PutVisible( VARIANT_TRUE );

chart_fx->GetLegendBoxObj()->PutDocked( TGFP_BOTTOM );

chart_fx->GetLegendBoxObj()->PutBorderStyle( (BarWndBorderStyle)BORDER_FLAT );

}

frep_( i, ~coldefs ){

chart_fx->GetSeries()->GetItem( i )->PutLegend( (char*)(LPCSTR)coldefs[i]->GetColName() );

}

chart_fx->PutSerLegBox( 1 );

chart_fx->GetSerLegBoxObj()->PutVisible( VARIANT_TRUE );

chart_fx->GetSerLegBoxObj()->PutDocked( TGFP_RIGHT );

chart_fx->GetSerLegBoxObj()->PutBorderStyle( (BarWndBorderStyle)BORDER_NONE );

CMetaFileDC mf_dc;

mf_dc.CreateEnhanced( &CWindowDC( NULL ), NULL, NULL, NULL );

long val = chart_fx->Paint( (long)mf_dc.GetSafeHdc(), 0, 0, size.cx, size.cy, CPAINT_PRINT, 0 );

HENHMETAFILE metafile = mf_dc.CloseEnhanced();

All the data seems to be in the metafile but the borders of the metafile aren't correct. I can readjust the borders manually by editing the picture in word and clicking on the reset picutre boundary button and then I get:

Which is what I'd expect in the first place. What am I doing wrong?

Thanks.

-Mac

Link to post
Share on other sites

sorry the paint method should have CPAINT_BKGND.....but problem still persists with it like that

"Mac Dyer" <Mac@simxtech.com> wrote in message news:4ZIPrjbXCHA.1492@webserver1.softwarefx.com...

Hi,

I'm having problems getting the legendbox to show up correctly when I export it to a metafile via the paint method.

picture of the problem:

Code for values and drawing:

for( int j = 0; j < ~coldefs; j++ ){

for( int k =0; k < ~grp_values; k++ ){

chart_fx->GetSeries()->GetItem( j )->PutYvalue( k, report_values[j][k].GetNumeric() );

}

}

chart_fx->CloseData( COD_VALUES );

if( dbview->GetFlags( DBVIEW_GRAPH_MASK ) != DBVIEW_GRAPH_PIE ){

frep_( i, ~grp_values ){

cstring str;

scale ? chart_fx->GetAxis()->GetItem( AXIS_X )->PutLabel( i, (char*)scale->GetShortName( i, str ) ) : chart_fx->GetAxis()->GetItem( AXIS_X )- >PutLabel( i, (char*)(LPCSTR)grp_values[i].GetString());

}

}

else{

frep_( i, ~grp_values ){

cstring str;

scale ? chart_fx->PutLegend( i, (char*)scale->GetShortName( i, str ) ) : chart_fx->PutLegend( i, (char*)(LPCSTR)grp_values[i].GetString());

}

chart_fx->PutLegendBox( 1 );

chart_fx->GetLegendBoxObj()->PutVisible( VARIANT_TRUE );

chart_fx->GetLegendBoxObj()->PutDocked( TGFP_BOTTOM );

chart_fx->GetLegendBoxObj()->PutBorderStyle( (BarWndBorderStyle)BORDER_FLAT );

}

frep_( i, ~coldefs ){

chart_fx->GetSeries()->GetItem( i )->PutLegend( (char*)(LPCSTR)coldefs[i]->GetColName() );

}

chart_fx->PutSerLegBox( 1 );

chart_fx->GetSerLegBoxObj()->PutVisible( VARIANT_TRUE );

chart_fx->GetSerLegBoxObj()->PutDocked( TGFP_RIGHT );

chart_fx->GetSerLegBoxObj()->PutBorderStyle( (BarWndBorderStyle)BORDER_NONE );

CMetaFileDC mf_dc;

mf_dc.CreateEnhanced( &CWindowDC( NULL ), NULL, NULL, NULL );

long val = chart_fx->Paint( (long)mf_dc.GetSafeHdc(), 0, 0, size.cx, size.cy, CPAINT_PRINT, 0 );

HENHMETAFILE metafile = mf_dc.CloseEnhanced();

All the data seems to be in the metafile but the borders of the metafile aren't correct. I can readjust the borders manually by editing the picture in word and clicking on the reset picutre boundary button and then I get:

Which is what I'd expect in the first place. What am I doing wrong?

Thanks.

-Mac

Link to post
Share on other sites

Sorry, the first picture I inserted was incorrect: the bottome half of the legendbox docked on the bottom of the picture should be cut off.  I think it was because I edited the picture that I pasted for what I expected to see, which changed the appearance of the first one because they were actually the same file.

Hopefully this will show up incorrectl

Image 1 PCTOTLOSS grouped by OCCURDATE

"Mac Dyer" <Mac@simxtech.com> wrote in message news:4ZIPrjbXCHA.1492@webserver1.softwarefx.com...

Hi,

I'm having problems getting the legendbox to show up correctly when I export it to a metafile via the paint method.

picture of the problem:

Code for values and drawing:

for( int j = 0; j < ~coldefs; j++ ){

for( int k =0; k < ~grp_values; k++ ){

chart_fx->GetSeries()->GetItem( j )->PutYvalue( k, report_values[j][k].GetNumeric() );

}

}

chart_fx->CloseData( COD_VALUES );

if( dbview->GetFlags( DBVIEW_GRAPH_MASK ) != DBVIEW_GRAPH_PIE ){

frep_( i, ~grp_values ){

cstring str;

scale ? chart_fx->GetAxis()->GetItem( AXIS_X )->PutLabel( i, (char*)scale->GetShortName( i, str ) ) : chart_fx->GetAxis()->GetItem( AXIS_X )- >PutLabel( i, (char*)(LPCSTR)grp_values[i].GetString());

}

}

else{

frep_( i, ~grp_values ){

cstring str;

scale ? chart_fx->PutLegend( i, (char*)scale->GetShortName( i, str ) ) : chart_fx->PutLegend( i, (char*)(LPCSTR)grp_values[i].GetString());

}

chart_fx->PutLegendBox( 1 );

chart_fx->GetLegendBoxObj()->PutVisible( VARIANT_TRUE );

chart_fx->GetLegendBoxObj()->PutDocked( TGFP_BOTTOM );

chart_fx->GetLegendBoxObj()->PutBorderStyle( (BarWndBorderStyle)BORDER_FLAT );

}

frep_( i, ~coldefs ){

chart_fx->GetSeries()->GetItem( i )->PutLegend( (char*)(LPCSTR)coldefs[i]->GetColName() );

}

chart_fx->PutSerLegBox( 1 );

chart_fx->GetSerLegBoxObj()->PutVisible( VARIANT_TRUE );

chart_fx->GetSerLegBoxObj()->PutDocked( TGFP_RIGHT );

chart_fx->GetSerLegBoxObj()->PutBorderStyle( (BarWndBorderStyle)BORDER_NONE );

CMetaFileDC mf_dc;

mf_dc.CreateEnhanced( &CWindowDC( NULL ), NULL, NULL, NULL );

long val = chart_fx->Paint( (long)mf_dc.GetSafeHdc(), 0, 0, size.cx, size.cy, CPAINT_PRINT, 0 );

HENHMETAFILE metafile = mf_dc.CloseEnhanced();

All the data seems to be in the metafile but the borders of the metafile aren't correct. I can readjust the borders manually by editing the picture in word and clicking on the reset picutre boundary button and then I get:

Which is what I'd expect in the first place. What am I doing wrong?

Thanks.

-Mac

Link to post
Share on other sites

I am using the Paint function to generate the chartfx file:

CMetaFileDC mf_dc;

mf_dc.CreateEnhanced( &CWindowDC( NULL ), NULL, NULL, NULL );

long val = chart_fx->Paint( (long)mf_dc.GetSafeHdc(), 0, 0, size.cx, size.cy, CPAINT_PRINT, 0 );

HENHMETAFILE metafile = mf_dc.CloseEnhanced();

This metafile is then written into a RTF file:

int CRPicture::GetBuffer( byte *&ret_buffer )

{

int size = 0;

ReleaseBuffer();

if( hEMF ){

size = ::GetEnhMetaFileBits( hEMF, 0, NULL );

temp_buffer = (byte*)malloc( size );

ret_buffer = temp_buffer;

::GetEnhMetaFileBits( hEMF, size, temp_buffer );

}

return size;

}

//ACTUAL WRITING OF METAFILE DATA TO A RTF FILE

{

ostream os;

CRPicture *r; ------>object the holds onto metafile data in the form of a HENHMETAFILE

if( !r->GetMetaFile() ) return false;

os << "{\\pict ";

os << "\\emfblip";

byte *pbBuf = NULL;

int size = r->GetBuffer( pbBuf );

if( !pbBuf ) return false;

// Write the header info

os << hex;

int k = 0;

frep_(i, size ){

static char *hex="0123456789ABCDEF";

if( !( k & 255 ) ) os << '\r';

int uga = pbBuf[i]&0xff;

os << hex[ uga >> 4 ] << hex[ uga&0xf ];

k++;

}

os<<dec;

r->ReleaseBuffer();

os << "}";

return true;

}

"SoftwareFX Support" <support@softwarefx.com> wrote in message news:dpTE9#0XCHA.976@webserver1.softwarefx.com...

The metafile itself seems to be cut here, I can tell because I can not see the border of the legend box all the way, how exactly are you generating this metafile ? how are you then displaying it ?

--

FP

Software FX, Inc.

Link to post
Share on other sites

What exactly do you mean by this? Can I still use the same procedure to fill out the metafile, but instead of having it inserted into a word document....save it as an .emf file?  Or do you me to use a whole different way to generate the picture of the chart?

//how I generate metafile because I don't want to and sometimes can't have a main window to create the ChartFX window

CMetaFileDC mf_dc;

mf_dc.CreateEnhanced( &CWindowDC( NULL ), NULL, NULL, NULL );

long val = chart_fx->Paint( (long)mf_dc.GetSafeHdc(), 0, 0, size.cx, size.cy, CPAINT_PRINT, 0 );

HENHMETAFILE metafile = mf_dc.CloseEnhanced();

"SoftwareFX Support" <support@softwarefx.com> wrote in message news:B#aoQu1XCHA.3136@webserver1.softwarefx.com...

Please try the following:

Instead of creating the Metafile in memory, create an actual file and then open it using the standard windows Image Viewer. Is it still cut off ?

--

FP

Software FX, Inc.

Link to post
Share on other sites

Ok I did some testing...... if I use the GetPicture after creating and sizing the window and then saving this metafile to disk the result is correct......but for some reason on everyone else's computer except for mine( not sure why as of yet...still looking into it ).  I have included( hopefully) 2 files good,emf and bad.emf and also an rtf file generated by our program that should show these 2 files in MS word. What does this mean?

"SoftwareFX Support" <support@softwarefx.com> wrote in message news:B#aoQu1XCHA.3136@webserver1.softwarefx.com...

Please try the following:

Instead of creating the Metafile in memory, create an actual file and then open it using the standard windows Image Viewer. Is it still cut off ?

--

FP

Software FX, Inc.

Link to post
Share on other sites

ok first off the "good" picture I generated by creating the chartfx window and calling the GetPicture method.....the bad picture was created without creating a window at all and using ChartFX's Paint method to draw into a metafile context to generate the HENHMETAFILE.

as far as things not showing up on my computer 1) If I use the same method to generate the "good" picture on my computer...the legend doesn't show up at all. The "bad" way of generating the file produces the same result on all computers....at least as far as I've seen. I have no idea why this occurs, but I'd rather get the graphs to show up on the other computers correctly.

I've included the result of the "good" way on my computer:

HWND hnd = AfxGetMainWnd()->m_hWnd;

HRESULT hr = chart_fx->CreateWnd( (long)hnd, IDC_CHART, 0, 0, size.cx, size.cy, WS_CHILD );

if( SUCCEEDED( hr ) ){

chart_fx->UpdateSizeNow();

hr = chart_fx->GetSerLegBoxObj()->SizeToFit();

IPictureDisp *pic_disp = chart_fx->GetPicture( CHART_METAFILE );

if( pic_disp ){

CComPtr<IPicture> pict = NULL;

HRESULT hr = pic_disp->QueryInterface( IID_IPicture, (void**)&pict );

if( SUCCEEDED( hr ) ){

HENHMETAFILE handle;

hr = pict->get_Handle( (OLE_HANDLE*)&handle );

if( handle ){

graph->GetPicture()->SetMetaFile( handle );

CopyEnhMetaFile( handle, "C:\\a.emf" );

}

}

}

}

"SoftwareFX Support" <support@softwarefx.com> wrote in message news:q4NXGXxYCHA.3136@webserver1.softwarefx.com...

I see the files, but I don't understand what the problem is now ? the files named "good" looks good, and so does the RTF document picture that refers to it.

So are you saying that these files look good in some computers and not in others ?

--

FP

Software FX, Inc.

Link to post
Share on other sites

any ideas why when I use the Paint method the legend is not drawn properly??  

"SoftwareFX Support" <support@softwarefx.com> wrote in message news:q4NXGXxYCHA.3136@webserver1.softwarefx.com...

I see the files, but I don't understand what the problem is now ? the files named "good" looks good, and so does the RTF document picture that refers to it.

So are you saying that these files look good in some computers and not in others ?

--

FP

Software FX, Inc.

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...