|
If u tell me your email address i can send the most recent version including property persistence.
|
|
|
|
|
Can anyone tell me how to save the graph to Bitmap Image
|
|
|
|
|
Try this (Use WriteWindowToDIB( LPTSTR szFile, CWnd *pWnd ))
HANDLE DDBToDIB( CBitmap& bitmap, DWORD dwCompression, CPalette* pPal ) <br />
{<br />
BITMAP bm;<br />
BITMAPINFOHEADER bi;<br />
LPBITMAPINFOHEADER lpbi;<br />
DWORD dwLen;<br />
HANDLE hDIB;<br />
HANDLE handle;<br />
HDC hDC;<br />
HPALETTE hPal;<br />
<br />
<br />
ASSERT( bitmap.GetSafeHandle() );<br />
<br />
if( dwCompression == BI_BITFIELDS )<br />
return NULL;<br />
<br />
hPal = (HPALETTE) pPal->GetSafeHandle();<br />
if (hPal==NULL)<br />
hPal = (HPALETTE) GetStockObject(DEFAULT_PALETTE);<br />
<br />
bitmap.GetObject(sizeof(bm),(LPSTR)&bm);<br />
<br />
bi.biSize = sizeof(BITMAPINFOHEADER);<br />
bi.biWidth = bm.bmWidth;<br />
bi.biHeight = bm.bmHeight;<br />
bi.biPlanes = 1;<br />
bi.biBitCount = bm.bmPlanes * bm.bmBitsPixel;<br />
bi.biCompression = dwCompression;<br />
bi.biSizeImage = 0;<br />
bi.biXPelsPerMeter = 0;<br />
bi.biYPelsPerMeter = 0;<br />
bi.biClrUsed = 0;<br />
bi.biClrImportant = 0;<br />
<br />
int nColors = (1 << bi.biBitCount);<br />
if( nColors > 256 ) <br />
nColors = 0;<br />
dwLen = bi.biSize + nColors * sizeof(RGBQUAD);<br />
<br />
hDC = GetDC(NULL);<br />
hPal = SelectPalette(hDC,hPal,FALSE);<br />
RealizePalette(hDC);<br />
<br />
hDIB = GlobalAlloc(GMEM_FIXED,dwLen);<br />
<br />
if (!hDIB){<br />
SelectPalette(hDC,hPal,FALSE);<br />
ReleaseDC(NULL,hDC);<br />
return NULL;<br />
}<br />
<br />
lpbi = (LPBITMAPINFOHEADER)hDIB;<br />
<br />
*lpbi = bi;<br />
<br />
GetDIBits(hDC, (HBITMAP)bitmap.GetSafeHandle(), 0L, (DWORD)bi.biHeight,<br />
(LPBYTE)NULL, (LPBITMAPINFO)lpbi, (DWORD)DIB_RGB_COLORS);<br />
<br />
bi = *lpbi;<br />
<br />
if (bi.biSizeImage == 0){<br />
bi.biSizeImage = ((((bi.biWidth * bi.biBitCount) + 31) & ~31) / 8) <br />
* bi.biHeight;<br />
<br />
if (dwCompression != BI_RGB)<br />
bi.biSizeImage = (bi.biSizeImage * 3) / 2;<br />
}<br />
<br />
dwLen += bi.biSizeImage;<br />
if (handle = GlobalReAlloc(hDIB, dwLen, GMEM_MOVEABLE))<br />
hDIB = handle;<br />
else{<br />
GlobalFree(hDIB);<br />
<br />
SelectPalette(hDC,hPal,FALSE);<br />
ReleaseDC(NULL,hDC);<br />
return NULL;<br />
}<br />
<br />
lpbi = (LPBITMAPINFOHEADER)hDIB;<br />
<br />
BOOL bGotBits = GetDIBits( hDC, (HBITMAP)bitmap.GetSafeHandle(),<br />
0L,
(DWORD)bi.biHeight,
(LPBYTE)lpbi
+ (bi.biSize + nColors * sizeof(RGBQUAD)),<br />
(LPBITMAPINFO)lpbi,
(DWORD)DIB_RGB_COLORS);
<br />
if( !bGotBits )<br />
{<br />
GlobalFree(hDIB);<br />
<br />
SelectPalette(hDC,hPal,FALSE);<br />
ReleaseDC(NULL,hDC);<br />
return NULL;<br />
}<br />
<br />
SelectPalette(hDC,hPal,FALSE);<br />
ReleaseDC(NULL,hDC);<br />
return hDIB;<br />
}<br />
<br />
BOOL WriteDIB( LPTSTR szFile, HANDLE hDIB)<br />
{<br />
BITMAPFILEHEADER hdr;<br />
LPBITMAPINFOHEADER lpbi;<br />
<br />
if (!hDIB)<br />
return FALSE;<br />
<br />
CFile file;<br />
if( !file.Open( szFile, CFile::modeWrite|CFile::modeCreate) )<br />
return FALSE;<br />
<br />
lpbi = (LPBITMAPINFOHEADER)hDIB;<br />
<br />
int nColors = 1 << lpbi->biBitCount;<br />
<br />
hdr.bfType = ((WORD) ('M' << 8) | 'B');
hdr.bfSize = GlobalSize (hDIB) + sizeof( hdr );<br />
hdr.bfReserved1 = 0;<br />
hdr.bfReserved2 = 0;<br />
hdr.bfOffBits = (DWORD) (sizeof( hdr ) + lpbi->biSize +<br />
nColors * sizeof(RGBQUAD));<br />
<br />
file.Write( &hdr, sizeof(hdr) );<br />
<br />
file.Write( lpbi, GlobalSize(hDIB) );<br />
<br />
return TRUE;<br />
}<br />
<br />
BOOL WriteWindowToDIB( LPTSTR szFile, CWnd *pWnd )<br />
{<br />
CBitmap bitmap;<br />
CWindowDC dc(pWnd);<br />
CDC memDC;<br />
CRect rect;<br />
<br />
memDC.CreateCompatibleDC(&dc); <br />
<br />
pWnd->GetWindowRect(rect);<br />
<br />
bitmap.CreateCompatibleBitmap(&dc, rect.Width(),rect.Height() );<br />
<br />
CBitmap* pOldBitmap = memDC.SelectObject(&bitmap);<br />
memDC.BitBlt(0, 0, rect.Width(),rect.Height(), &dc, 0, 0, SRCCOPY); <br />
<br />
CPalette pal;<br />
if( dc.GetDeviceCaps(RASTERCAPS) & RC_PALETTE )<br />
{<br />
UINT nSize = sizeof(LOGPALETTE) + (sizeof(PALETTEENTRY) * 256);<br />
LOGPALETTE *pLP = (LOGPALETTE *) new BYTE[nSize];<br />
pLP->palVersion = 0x300;<br />
<br />
pLP->palNumEntries = <br />
GetSystemPaletteEntries( dc, 0, 255, pLP->palPalEntry );<br />
<br />
pal.CreatePalette( pLP );<br />
<br />
delete[] pLP;<br />
}<br />
<br />
memDC.SelectObject(pOldBitmap);<br />
<br />
HANDLE hDIB = DDBToDIB( bitmap, BI_RGB, &pal );<br />
<br />
if( hDIB == NULL )<br />
return FALSE;<br />
<br />
WriteDIB( szFile, hDIB );<br />
<br />
GlobalFree( hDIB );<br />
return TRUE;<br />
}<br />
|
|
|
|
|
THank you Gunnar its working fine now
|
|
|
|
|
Also if we can save the Graph and reoopen it on the Graph view
|
|
|
|
|
Hi folks,
unfortunately i don't have time to update this article, maybe within the next weeks...
For those who can't wait for so long i can send the new version (lots of bug-fixes, some new features) via mail.
Gunnar
|
|
|
|
|
Hi Gunnar,
Unfortunalety i can not wait for long. Therefore I have a request: could You send me the new version on mail?
Best regards,
Dawid Bednarczyk
|
|
|
|
|
If convenient, please send the latest bug-fixed version to me.
Thank you very much.
Email: min2max@yahoo.com
Max
|
|
|
|
|
...and possibly some other controls I haven't run into yet...
The problem is, that the validation of all of the controls is done in CAxisDlg::OnChanged() and the control is validating the data using the functions in DoDataExchange() after the UpdateData(TRUE)...
Unfortunately it is extremely annoying if you delete the value from the edit box or try to type in a negative number because it keeps saying "Please enter a number" due to this check:
if (d == 0.0 && chFirst != '0')
in _AfxSimpleFloatParse( ... )
Unfortunately, since this check is in the MFC code I can't make it a little smarter and I think the resolution is to change the way that the fields are validated (possibly in OnKillFocus()?)... does anybody have an idea of a simpler solution?
Thanks!
-Rex
|
|
|
|
|
I can execute my build or the .bin file and seems
to hang. I have a upper left view of a graph and
instruction for mouse. The rest is transparent.
I've been trying to debug but I'm having trouble.
I don't know what the view should look like ect.
When it hangs I have to stop exe. by (ctrl,alt,del)Where should I begain to debug. Not
knowing what view should look like or program does?
|
|
|
|
|
Hi!
We have encountered the same problem on one of our computers. All three computers run Windows2000 professional.
The computer that exhibit this behavior has a Soundblaster GeForce(1) graphic card. It seems strange that this error could depend on hardware, but it's our best guess.
Anyone else who has encountered this problem?
Martin
|
|
|
|
|
Hi!
The problem seems to be that the scaling of axis labels crash if the screen resolution is too low. When resolution is low division by zero occur. A quick fix is to assure that the paramter nBestCount in fitscale always is at least 1.
/Martin
|
|
|
|
|
Hi!
When I try to build the project under Visual C++ 7 i get the following error:
Error PRJ0019: A tool returned an error code: "Performing pre-link event"
I have not found a solution.
Any ideas?
/Martin
|
|
|
|
|
No need to say once more how great this library is.
A small question. I add a graph in a dialog and when resizing the dialog (and the graph) I experience too much flickering of the graph.
I have used too methods: The simple one is by overriding the OnSize of the dialog. The other one is by using the cdxCDynamicDialog class for the dialog (a well known resizing class from codex design that is used for resizing windows).
Both methods yield the same results: Excessive flickering.
Any ideas why this is happening and how to correct it
|
|
|
|
|
Hmmm...
Problem with flickering just solved. When creating the graph in a dialog, just enable the "clip chldren" property. It solves the flickering problem at least when using the cdxCDynamicDialog class for the dialog. It maybe solves it even with the overriding if the OnSize, but have not checked.
However I have to report another problem (a bug - and I think a serious one)
When resizing on the horizontal axis, the gragh is not displayed corectly. Part of the data on the right side of the graph are ommited - it looks like that the problem occurs when automatically switching between x axis scale changes.
I think that this has to do with a problem known to Gunnar Bolle : "Autoscaling a time-axis sometimes doesn't work as expected.". I was able to verify that the problem occurs when the X axis is date-time. Hope that he will be able to solve it soon. I will try myself but do not expect much !!!
Warm regards
Pothitos M. Baikas
|
|
|
|
|
I am graphing several curves on a single graph. Sometimes a curve will have an outlier point that is like a "spike" in the data. Sometimes there are several "spike" points in the same location but because there is limited pixels they all sortof land on the same place which is fine.
The problem is that sometimes this spike is not displayed. Panning the graph will make the point appear and then vanish. Zooming will make the point appear.
Has anyone else seen this before i start digging through the code?
chris
|
|
|
|
|
I think the judgement in function CXGraphDataSerie::Draw as following will change the curves, so you can try this
...
if (point.x != oldPoint.x )//delete this line
{//delete this line
...//keep this block
}//delete this line
...
|
|
|
|
|
How can I print two graph in one page?
|
|
|
|
|
I am looking into this as well - i would actually like 4 graphs on the same page. My first approach is simply to put 2 or 4 charts into a single view. I dont want to change any code in lib. I'll post again if i get anywhere.
chris
|
|
|
|
|
Chris:
Thank you for your help.I think this problem should correct from class CDCEx.
At first,I modify the declaration as this:
#ifdef _AFXDLL
class __declspec(dllexport) CDCEx : public CDC
#else
class __declspec(dllimport) CDCEx : public CDC
#endif
Then I add a function as following:
void CXGraph::PrintGraphEx(CDCEx *pDC,CRect clRect)
{
m_pPrintDC =pDC;
m_clPrintRect=clRect;
m_pPrintDC->m_bPrinting = true;
OnPaint();
m_pPrintDC=NULL;
}
At last, I modify the member function OnFilePrint() of view,and call PrintGraphEx in this function.
This method can print several charts in one page,but I want to get a better way to do this.Could you tell me?
|
|
|
|
|
Hey,
I've a y range from -0.1 to 1.0, in this case is the y range, which is displayed just -0.1 to .8. The problem seems to be to double comparsion in CXGraphAxis::Draw where the Axis is painted.
However, my solution is to calculate the needed steps first, than it works for the small double.
int nSteps = (m_fCurMax - m_fCurMin) / m_fStep;
double fY = m_fCurMin;
for (i = 0; i <= nSteps; i++,fY += m_fStep, fnY -= fStep)
//was: for (double fY = m_fCurMin; fY <= m_fCurMax; fY += m_fStep, fnY -= fStep)
|
|
|
|
|
Please help me to insert CXGraph in dialog.
|
|
|
|
|
I've succeeded in putting the graph in a modal dialog, but have not manged to get the menu working as it appears to be dependent on the graph being a view... I would appreciate somebody giving me a tip on how to do that...
As for putting the graph on a modal dialog... first, I created a group box as a placeholder for where I wanted the graph to be, then I put this code in OnInitDialog()
// IDC_GRID_GRAPH_RECT is my placeholder group box
CWnd* pGridGraphRectPtr = GetDlgItem(IDC_GRID_GRAPH_RECT);
pGridGraphRectPtr->GetWindowRect(&m_GridGraphRect);
ScreenToClient(m_GridGraphRect);
// the next line gets rid of the placeholder since it's not
// needed once the graph is displayed
pGridGraphRectPtr->DestroyWindow();
// This creates the graph to be displayed where the
// placeholder is...
m_ValuesGraph.Create("XGraph","", WS_CHILD | WS_VISIBLE, m_GridGraphRect, this, 1001);
I hope this helps! I keep the rect around as I'm actually swapping a few controls in the same spot based on a radio button setting, but if you're not doing that you can define the CRect locally.
|
|
|
|
|
Yes, I also have problems with menu etc in a dialog.
Did you ever manage to fix it?
Cheers,
/Martin
|
|
|
|
|
Sorry, it's been six months, so I don't remember. I ended up handing that project off to somebody else to complete, so I don't know what came of it.
|
|
|
|
|