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

Message ListMessage List     Post MessagePost Message

  Background picture will disappear when I use OPENFILENAME.(MFC)
Posted by Tony on Mar-18-2015 11:44
Attachments:
Hi,


I want to design a chart with my background picture using MFC.
But the background picture will disappear when I use OPENFILENAME API to load/save a
file.
What can I do to prevent disappearance of the picture happened?

Sample code as below:





BOOL CMFCApplication12Dlg::OnInitDialog()
{
   .
   .
   .

SetTimer(1, 100, NULL);

return TRUE;
}



void CMFCApplication12Dlg::OnTimer(UINT_PTR nIDEvent)
{
const char *labelsY[] = { "0.0", "0.1", "0.2", "0.3", "0.4", "0.5", "0.6" };
const char *labelsX[] = { "0.0", "0.1", "0.2", "0.3", "0.4", "0.5", "0.6", "0.7" };
XYChart *c = new XYChart(350, 350);


PlotArea *plotarea = c->setPlotArea(45, 35, 300, 300, 0xffffff, -1, -1, c-
>dashLineColor(0x000000,
0x000000), c->dashLineColor(0x000000, 0x000000));

char myImage[1024];
sprintf_s(myImage, "<*img=CIE1931.png,width=%d,height=%d*>", plotarea-
>getWidth(),
plotarea->getHeight()); //Read background picture CIE1931.png

c->addText(plotarea->getLeftX() - 2, plotarea->getTopY() - 1, myImage)
->setZOrder(Chart::PlotAreaZ);


int pattern1[] = { 0xb0b0f0, 0xe0e0ff };


c->yAxis()->setTitle("y");

c->yAxis()->setLabels(StringArray(labelsY, (int)(sizeof(labelsY) / sizeof(labelsY[0]
))));
c->yAxis()->setLabelStep(1);

c->xAxis()->setLabels(StringArray(labelsX, (int)(sizeof(labelsX) /
sizeof(labelsX[0]
))));

c->xAxis()->setTitle("x");
c->xAxis()->setLabelStep(1);

m_Picture.setChart(c);

CDialogEx::OnTimer(nIDEvent);
}



void CMFCApplication12Dlg::OnBnClickedLoad() //OPENFILENAME Test
{
OPENFILENAME OpenFileName;
WCHAR filter[128] = L"SPS files(*.sps)\\0*.sps\\0";
WCHAR filename[200] = L"SPS";

memset(&OpenFileName, 0, sizeof(OpenFileName));

OpenFileName.lStructSize = sizeof(OPENFILENAME);
OpenFileName.hwndOwner = m_hWnd;
OpenFileName.hInstance = AfxGetInstanceHandle();
OpenFileName.lpstrFilter = filter;
OpenFileName.lpstrDefExt = filter;

OpenFileName.nMaxFile = sizeof(filename);
OpenFileName.lpstrFile = filename; //It will disappear the picture bg.
OpenFileName.nFilterIndex = 1;
OpenFileName.Flags = OFN_EXPLORER | OFN_HIDEREADONLY | OFN_READONLY;

if (!GetOpenFileName(&OpenFileName)) //Open File frame //It will disappear the
picture bg.
return;
}
Sample exe(Please add chartdir51.dll).rar
Sample exe(Please add chartdir51.dll).rar

235.05 Kb

  Re: Background picture will disappear when I use OPENFILENAME.(MFC)
Posted by Peter Kwan on Mar-19-2015 04:45
Hi Tony,

I suspect it is because your code does not specify where is the background picture. Your
code just use "CIE1931.png", but which directory is the file in? If you do not specify the
directory, the operating system will use the "current working directory". May be initial
"current working directory" happens to contain the image, so it works. The OPENFILENAME
may change the "current working directory", so it no longer contains the background image,
and so the image cannot be found.

If this is the cause of the problem, to solve the problem, please use the full path name, not
just the filename.

Hope this can help.

Regards
Peter Kwan

  Re: Background picture will disappear when I use OPENFILENAME.(MFC)
Posted by Tony on Apr-24-2017 15:21

This problem can be solve by using the full path name,
but the background picture disappear when use Chinese path name.
How can I solve Chinese path name problem?

  Re: Background picture will disappear when I use OPENFILENAME.(MFC)
Posted by Peter Kwan on Apr-25-2017 00:51
Hi Tony,

Please try the followings:

- Please use ChartDirector version 6 (in case you are still using an older version of ChartDirector)

- Ensure the filename is encoded in UTF8. If you are not sure what encoding you are using, please try to use "wide character" (wchar_t), then use WCHARtoUTF8 to convert it to UTF8 inline. For example:

wchar_t *myText = ......; // some text in wchar_t

c->addText(x, y, WCHARtoUTF8(myText));

Regards
Peter Kwan

  Re: Background picture will disappear when I use OPENFILENAME.(MFC)
Posted by Tony on Apr-25-2017 19:48
I try the code as below:

-------------------------
WCHAR StrPath[128] = { 0 };

.
.
.
  lstrcpy(StrPath, L"<*img=");
  lstrcat(StrPath, L"中文字");//Chinese name folder
  lstrcat(StrPath, L"\\CIE1976.png");//Read background picture CIE1976.png

  lstrcat(StrPath, L",width=422,height=368*>");


c->addText(plotarea->getLeftX() - 2, plotarea->getTopY() - 1,
  WCHARtoUTF8(StrPath))->setZOrder(Chart::PlotAreaZ);

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


But the background picture still disappear when use Chinese folder name.

Please refer to the sample project:


https://drive.google.com/file/d/0ByY-wYRGky73aldBN1NXaHRqLWM/view?usp=sharing

  Re: Background picture will disappear when I use OPENFILENAME.(MFC)
Posted by Peter Kwan on Apr-26-2017 05:14
Hi Tony,

Sorry for this problem. I have tested myself and can reproduce the issue. The international character support for pathnames was broken for pathnames in CDML.

We have just produced a patched DLL that should solve this problem. The patched DLL can be downloaded from:

http://www.advsofteng.com/chartdir60p6.zip

I have tried the above DLL myself, and it works when running your test project in my computer.

Please kindly let me know if this new DLL can solve the problem.

Regards
Peter Kwan

  Re: Background picture will disappear when I use OPENFILENAME.(MFC)
Posted by Tony on Apr-26-2017 10:16
It OK!
Thank you!