Jump to content
Software FX Community

help! preview works, print fails


User (Legacy)

Recommended Posts

Greetings.

I've been working through this newsgroup for hints about printing my charts.

I control the reports in my program. Text and other drawn objects (boxes,

bitmaps, etc.) work fine, both printed and previewed. My app is developed in

VC++ and uses MFC. I'm using the following code to print a chart. When

previewing, the chart prints fine. When I go to the printer, I get a

application error and my program terminates. I've tried to set the

coordinates into the printer DC like suggested in the screen/printer

conversion, but it doesn't seem to help. Also, please look at my

CreateControl function. I found no examples of how to instantiate the object

on the page. This seemed to work for me. If I set the window property to

WS_VISIBLE, then weirdness ensued. Setting the property to WS_VISIBLE, and

using and IDC_CHART value from another dialog box that uses the chart object

seems to work fine. Suggestions would be helpful.

Thanks in advance,

Michael

// code...

// at this point, I have a printer DC (pDC) and a CRect object based on

printer coordinates.

m_ChartFX.CreateControl(__uuidof(ChartFX), "", WS_DISABLED, rect,

pDC->GetWindow(), IDC_CHART1,NULL);

m_pChartFX = m_ChartFX.GetControlUnknown();

if (m_bPreview)

{

CDC *sdc;

sdc = AfxGetMainWnd()->GetDC(); // Screen DC

int xScrRes = sdc->GetDeviceCaps(LOGPIXELSX); // Screen resolution (X)

int yScrRes = sdc->GetDeviceCaps(LOGPIXELSY) / 3; // Screen resolution (Y)

int xPrnRes = pDC->GetDeviceCaps(LOGPIXELSX); // Printer resolution (X)

int yPrnRes = pDC->GetDeviceCaps(LOGPIXELSY) / 3; // Printer resolution (Y)

int nPrnWidth = pDC->GetDeviceCaps(HORZRES); // Page size (X)

int nPrnHeight = pDC->GetDeviceCaps(VERTRES) / 3; // Page size (Y)

AfxGetMainWnd()->ReleaseDC(sdc);

pDC->SaveDC(); // Save settings

// Maps to equivalent SCREN resolution

pDC->SetMapMode(MM_ANISOTROPIC);

pDC->SetWindowExt(MulDiv(nPrnWidth,xScrRes,xPrnRes),MulDiv(nPrnHeight,yScrRe

s,yPrnRes));

pDC->SetViewportExt(nPrnWidth,nPrnHeight);

m_pChartFX->Paint((long)pDC->m_hDC,

MulDiv(rect.left,xScrRes,xPrnRes),

MulDiv(rect.top,yScrRes,yPrnRes),

MulDiv(rect.right,xScrRes,xPrnRes),

MulDiv(rect.bottom,yScrRes,yPrnRes),

(CfxChartPaint) 0,0);

pDC->RestoreDC(-1); // Restore settings

}

else

{

// the example I found in this newsgroup went right to the Paint fn, that

failed, I tried to map the coordinates to ensure they were set properly,

that failed, I read in one posting that the MapMode should be MM_TEXT, that

failed. I used different coordinates for the print boundaries, that

failed -- I'm lost!

int yPrnRes = pDC->GetDeviceCaps(LOGPIXELSY) / 3;

int nPrnWidth = pDC->GetDeviceCaps(HORZRES);

int nPrnHeight = pDC->GetDeviceCaps(VERTRES) / 3;

pDC->SaveDC(); // Save settings

pDC->SetMapMode(MM_TEXT);

m_pChartFX->Paint((long)pDC->m_hDC,

rect.left,

rect.top,

rect.right,

rect.bottom,

(CfxChartPaint) CPAINT_PRINT,0);

pDC->RestoreDC(-1); // Restore settings

}

Link to comment
Share on other sites

The code in KB article Q1381013. Drawing the chart into an MFC preview

window (from which you took the code for preview) works fine for me in both

print and print preview AS IS in an MFC application created from the

scratch. No other code was added.

Notice that this code is to be put in the OnPrint function NOT in OnDraw.

Attached is the MFC Application.

>Also, please look at my CreateControl function. I found no examples of how

to instantiate the object ...

This code indeed takes a control in a DIALOG and uses it. If you want to

create one from scratch, you can do so by doing:

m_ChartFX.CreateControl(__uuidof(ChartFX), NULL, WS_VISIBLE, rc, this,

IDC_CHART1,NULL,NULL,NULL /* LICENSE STRING SHOULD GO HERE */ );

This is the CCfxDynamic.cpp sample provided.

Notice that this creates a chart WINDOW. You can make it invissible if you

want (by removing WS_VISIBLE from the previous call). It is important to

notice that if the chart is not created at design-time, the license

information is not going to be stored and therefore, the program is not

going to work when deployed. This is explained in KB article "Q1381002.

Using Chart FX 98 in VC++ without MFC".

Here is how:

IClassFactory2 *pFactory2;

LPUNKNOWN pUnk;

HRESULT hr;

if (SUCCEEDED(hr =

CoGetClassObject(__uuidof(ChartFX),CLSCTX_INPROC_SERVER,NULL,IID_IClassFacto

ry2,(LPVOID FAR *) &pFactory2))) {

hr = pFactory2->CreateInstanceLic(NULL,NULL,IID_IUnknown,_bstr_t(L"<Your

License String Goes Here>"),(LPVOID FAR *) &pUnk);

if (SUCCEEDED(hr)) {

m_pChartFX = pUnk;

pUnk->Release();

}

pFactory2->Release();

}

The sample program I sent you includes this code. Simply add your license

string to run it. You can obtain your License String by running : "Start ->

All Programs -> Chart FX Client Server -> About Chart FX Client Server".

--

FP

Software FX

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...