|
MFC w/HTML tooltips with embedded English units marks |
Posted by Sal on Jun-16-2016 01:04 |
|
Hi Peter,
I am trying to generate a Custom tooltip when the Mouse move over an image I produced using the DrawArea class methods
I wrote code that returns the World units (X,Y) at the mouse position.
As the Axis where designed, the X axis value is in Decimal Feet, the Y axis value is in Inches
Since the X value format is not descriptive enough, I need to show the X,Y value as:
X = xx' - xx.xxx"
Y = xx.xxx"
format where the single quote is the mark for Feet and the Double quote is the mark for Inches
As long I remove the ' from the Upper formatted string, both values are shown
If ' is there, only the xx value of X shows and nothing else
I have the following code (fragments):
----------
TCHAR xBuf[50];
TCHAR yBuf[50];
// Format the X+Y text for the position point
int iLenX = sprintf_s(xBuf, sizeof(xBuf), "X = %d' - %5.3f"n", iFeet, dInches);
int iLenY = sprintf_s(yBuf, sizeof(yBuf), "Y = %5.3f"n", dY);
// Format the tooltip
int iLen = sprintf_s(imageMap, sizeof(imageMap), "<area shape='rect' coords='%d,%d,%d,%d' title='%s%s'>",
iMinX, iMinY, iMaxX, iMaxY,
xBuf, yBuf);
// commit text to Hot Spot Area
setImageMap(imageMap);
-----------
The problem is the delimiters used after title= interacts with the Marks ' and " contained into xBuf and yBuf strings, producing neither intended results
I tried to swap the title='....' with title=".....", with different results, neither correct
I read about using Escape characters sequence that in theory should help to resolve the issue. So far nothing I tried them but I was not able to produced the intended results
Can you suggest what to do to produce the intended text as shown above?
Thanks
Sal |
Re: MFC w/HTML tooltips with embedded English units marks |
Posted by Sal on Jun-16-2016 01:14 |
|
Peter,
I forgot to add the work around I produced to confirm that the code is nominally working
// temporary work around (the Mark ' was replaced by Ft)
iLenX = sprintf_s(xBuf, sizeof(xBuf), "X = %d Ft %5.3f"n", iFeet, dInches);
When I use the above both X + Y formatted strings are produced (using title='....')
Thanks
Sal |
Re: MFC w/HTML tooltips with embedded English units marks |
Posted by Sal on Jun-16-2016 05:49 |
|
Peter,
eventually I came across what I needed to solve the issue...
All I have to do is to replace the line about xBuf with the following:
iLenX = sprintf_s(xBuf, sizeof(xBuf), "X = %d' - %5.3f"n", iFeet, dInches);
which escapes the ' character to a format that uses the decimal value of that character
FYI: I tried to use before
"
but this would print " instead of '
Can you explain why the " did not work (in place of ') ?
All I read make me believe that this was what I should have used
I hope this can be of help to others
Thanks |
Re: MFC w/HTML tooltips with embedded English units marks |
Posted by Sal on Jun-16-2016 05:53 |
|
Peter,
Sorry, The browser substituted my escape sequence with a character, once I viewed the message
I was trying to illustrate that the scape sequence I used was
&_quot_;
without the underscore characters |
Re: MFC w/HTML tooltips with embedded English units marks |
Posted by Sal on Jun-16-2016 21:16 |
|
Peter,
This is the line I had to change
iLenX = sprintf_s(xBuf, sizeof(xBuf), "X = %d' - %5.3f"n", iFeet, dInches);
sorry for the confusion in reporting the issue |
Re: MFC w/HTML tooltips with embedded English units marks |
Posted by Sal on Jun-16-2016 21:19 |
|
Sorry guys,
The Browser hided again what I was trying to report:
Imagine that the mark character is replaced by _&_#39_;
without the underscores |
Re: MFC w/HTML tooltips with embedded English units marks |
Posted by Peter Kwan on Jun-17-2016 00:21 |
|
Hi Sal,
I assume the actual code you are using is as follows:
int iLenX = sprintf_s(xBuf, sizeof(xBuf), "X = %d' - %5.3f\"\n", iFeet, dInches);
I started from the MFC "Hello World" sample code, and inserted your exact code, and it works normally in my case. I have attached my test code and the resulting screen shot for your reference.
To try the test code, please open the MFC Hello World project, which should be just a simple bar chart. Then replace the "BOOL CHelloworldDlg::OnInitDialog()" method with the code as in the attached file. (I use a file attachment for the code to make sure the browser does not make the HTML escape code and the backslash character disappear.)
If the above still does not solve the problem, is it possible to modify the Hello World sample code to create an example that I can try? This can help me to trouble-shoot the problem.
Regards
Peter Kwan
test.txt |
---|
BOOL CHelloworldDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// *** code automatically generated by VC++ MFC AppWizard ***
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
//
// Draw Chart and set to CChartViewer
//
// The data for the bar chart
double data[] = {85, 156, 179.5, 211, 123};
// The labels for the bar chart
const char *labels[] = {"Mon", "Tue", "Wed", "Thu", "Fri"};
StringArray labelsArray(labels, sizeof(labels)/sizeof(labels[0]));
// Create a XYChart object of size 250 x 250 pixels
XYChart *c = new XYChart(250, 250);
// Set the plotarea at (30, 20) and of size 200 x 200 pixels
c->setPlotArea(30, 20, 200, 200);
// Add a bar chart layer using the given data
c->addBarLayer(DoubleArray(data, sizeof(data)/sizeof(data[0])));
// Set the labels on the x axis.
c->xAxis()->setLabels(labelsArray);
// Output the chart
m_ChartViewer.setChart(c);
int iFeet = 10;
double dInches = 5.3;
double dY = 1.3;
int iMinX = 30;
int iMaxX = 230;
int iMinY = 20;
int iMaxY = 220;
char imageMap[1000];
char xBuf[50];
char yBuf[50];
// Format the X+Y text for the position point
int iLenX = sprintf_s(xBuf, sizeof(xBuf), "X = %d' - %5.3f\\"\\n", iFeet, dInches);
int iLenY = sprintf_s(yBuf, sizeof(yBuf), "Y = %5.3f\\"\\n", dY);
// Format the tooltip
int iLen = sprintf_s(imageMap, sizeof(imageMap), "<area shape='rect' coords='%d,%d,%d,%d' title='%s%s'>",
iMinX, iMinY, iMaxX, iMaxY, xBuf, yBuf);
// commit text to Hot Spot Area
m_ChartViewer.setImageMap(imageMap);
// In this sample project, we do not need to chart object any more, so we
// delete it now.
delete c;
return TRUE;
} |
|
| |
|