|
|
Too many errors, RGB errors, Missing initializers, Missing routines.
|
|
|
|
|
|
Hi
I found that whenever i increased the number of bars to greater than 20, the graph only displayed a section of the bars (max 20 - in the rectangle).
I tried increasing the size of the rectangle, but this had the same result (ie no change)
Any help with this would be much appreciated.
|
|
|
|
|
hi. thanx for your prrety and simple graph.
but i can't understand how to deal with size of bar? i have 4 bars. size of one of them is 1000 the next 90 next 50 next 5 .
how your class draw this ? it seems that it cant draw true.
could u plz guide me to solve this.
lots of thanx
|
|
|
|
|
<br />
CGraphCtrl.h<br />
<br />
#include <iostream><br />
#include <fstream><br />
using namespace std;
...
public:
...
void SaveBitmap(const char* filename);
CGraphCtrl.cpp
void CGraphCtrl::SaveBitmap(const char* filename)<br />
{<br />
RECT windowRect;<br />
::GetWindowRect(m_hWnd, &windowRect);<br />
<br />
int bitmap_dx = windowRect.right - windowRect.left;<br />
int bitmap_dy = windowRect.bottom - windowRect.top;<br />
<br />
ofstream file(filename, ios::binary);<br />
if(!file) return;<br />
<br />
BITMAPFILEHEADER fileHeader;<br />
BITMAPINFOHEADER infoHeader;<br />
<br />
fileHeader.bfType = 0x4d42;<br />
fileHeader.bfSize = 0;<br />
fileHeader.bfReserved1 = 0;<br />
fileHeader.bfReserved2 = 0;<br />
fileHeader.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);<br />
<br />
infoHeader.biSize = sizeof(infoHeader);<br />
infoHeader.biWidth = bitmap_dx;<br />
infoHeader.biHeight = bitmap_dy;<br />
infoHeader.biPlanes = 1;<br />
infoHeader.biBitCount = 24;<br />
infoHeader.biCompression = BI_RGB;<br />
infoHeader.biSizeImage = 0;<br />
infoHeader.biXPelsPerMeter = 0;<br />
infoHeader.biYPelsPerMeter = 0;<br />
infoHeader.biClrUsed = 0;<br />
infoHeader.biClrImportant = 0;<br />
<br />
file.write((char*)&fileHeader, sizeof(fileHeader));<br />
file.write((char*)&infoHeader, sizeof(infoHeader));<br />
<br />
BITMAPINFO info;<br />
info.bmiHeader = infoHeader; <br />
<br />
HDC winDC = ::GetWindowDC(m_hWnd);<br />
HDC memDC = CreateCompatibleDC(winDC);<br />
BYTE* memory = 0;<br />
HBITMAP bitmap = CreateDIBSection(winDC, &info, DIB_RGB_COLORS, (void**)&memory, 0, 0);<br />
SelectObject(memDC, bitmap);<br />
BitBlt(memDC, 0, 0, bitmap_dx, bitmap_dy, winDC, 0, 0, SRCCOPY);<br />
DeleteDC(memDC);<br />
::ReleaseDC(m_hWnd, winDC);<br />
<br />
int bytes = (((24*bitmap_dx + 31) & (~31))/8)*bitmap_dy;<br />
file.write((char *)memory, bytes);<br />
<br />
DeleteObject(bitmap);<br />
}
|
|
|
|
|
thank u varandas79
it was realy needed
but it doesn't work or i cant work with it.
the compiler makes error on line :
using namespace std;
the error is :
error C2871: 'std' : does not exist or is not a namespace
could u please help me
-- modified at 1:48 Monday 25th September, 2006
|
|
|
|
|
I found a problem when I used this control in a small window: The plot was wrong
suppose the following:
SetBarValue(0,10);
SetBarValue(1,100);
SetBarValue(0,30);
if the window height is smaller than bar[1]*unit then the graph output is wrong with bar[1] smaller than bar[0] and bar[2]
This is a scale problem and I corrected using the following code: (notice ++KM)
BOOL CGraphCtrl::OnEraseBkgnd(CDC* pDC)
{
int *BAR=new int[NumOfBars]; //++KM
float scale=1.0; //++KM
int i,max=0; //++KM
CRect rc;
GetClientRect (rc);
BGC = RGB(224,231,240);
int Width = rc.Width();
int Height= rc.Height();
int bx=0, by=0;
//find max value //++KM
for(i=0;i<(int)NumOfBars;i++) //++KM
max=(bar[i]>max)?bar[i]:max; //++KM
if(max>Height-offset-7) //++KM
{ //++KM
scale=(float)((float)(Height-offset-7)/(float)max); //++KM
} //++KM
for(i=0;i<(int)NumOfBars;i++) //++KM
{ //++KM
BAR[i] = (int)((float)(bar[i])*scale); //++KM
} //++KM
// KillTimer(1);
pDC->FillSolidRect(0,0,Width,Height,BGC);
pDC->FillSolidRect(offset-2,0,2,Height-(offset-2),RGB(0,0,0,));
pDC->FillSolidRect(offset,Height-offset,Width-offset,2,RGB(0,0,0,));
for(i=1;i<=(Height-offset)/(unit/2);i++)
{
if(i%2 != 0)
{
pDC->MoveTo(offset-2,(Height-offset) - i*(unit/2));
pDC->LineTo(offset-6,(Height-offset) - i*(unit/2));
}
else
{
pDC->MoveTo(offset-2,(Height-offset) - i*(unit/2));
pDC->LineTo(offset-10,(Height-offset) - i*(unit/2));
}
}
for(i=0;i<(int)NumOfBars;i++)
{
bx = ((Width-offset)/NumOfBars)*i+offset;
pDC->FillSolidRect(bx, Height-BAR[i]-offset,(Width-offset)/NumOfBars,BAR[i],BC[i]); //++KM
pDC->Draw3dRect(bx, Height-BAR[i]-offset,(Width-offset)/NumOfBars,BAR[i],RGB(255,255,255),BC[i]); //++KM
}
delete BAR; //++KM
return CStatic::OnEraseBkgnd(pDC);
}
(there is another problem with the original code: It changes the values of original data: bar[i])
|
|
|
|
|
thanx. u did solve my problem
u got my 5
|
|
|
|
|
I can't find that function in the source!
|
|
|
|
|
The source code does not match the executable. The SetBarColor method is missing. (e.g. the compiled EXE file has colored bars but the one built from source does not...)
Chuck
|
|
|
|
|
I made it, it is quite simple :
Add in .h :
/////////////////// 8< cut 8< ///////////////////
int SetBarColor(int idx, COLORREF clr);
/////////////////// 8< cut 8< ///////////////////
Add in .cpp :
/////////////////// 8< cut 8< ///////////////////
int CGraphCtrl::SetBarColor(int idx, COLORREF clr)
{
if(idx < this->NumOfBars && idx >= 0){
BC[idx] = clr;
return idx;
} else {
return -1;
}
Invalidate();
}
/////////////////// 8< cut 8< ///////////////////
Hope this helps...
|
|
|
|
|
Hello author,
I am learning to write VC++ programs studying the programs given here. Came across your program, seems wonderful. May be this is 2 elementary but the program has memory leaks at two places. I hope other viewrs have spotted it and corrected it.
If not ... at the following in the destructor:
CGraphCtrl::~CGraphCtrl()
{
if(bar)
{
delete [] bar;
bar =0;
}
if(BC)
{
delete [] BC;
BC =0;
}
}
Chaitanya123
|
|
|
|
|
Hi,
There is no memory leak!
We have to use
delete[] bar;
only if bar is allocated dynamically using,
bar = new int[MAXBARS];
but here the variable bar is declare as
int bar[MAXBARS]; (allocated in stack)
This memory will be cleared automatically when it exits its scope.
same with BC also.
Thanks,
Shaibu
|
|
|
|
|
Hi, your graph is pretty.
But, I think your [default] Device MapeMode is incompatible by your defines:
#define UCM 28
#define UINCH 72
Because defualt MapMode is MM_TEXT.
But you designed or defined your Map by MM_TWIPS.
So call pDC->SetMapMode(MM_TWIPS) in your class to have correct ruler.
Another suggection: To have an "flicker-free" drawing, search that keyword in this site.
Thanks, BEB
|
|
|
|
|
Dear Behzad,
Thankyou very much for the suggestions.
Shaibu
|
|
|
|
|
What's the use of
void OnCustomDraw(NMHDR* pNMHDR, LRESULT* pResult);
for the static control????
|
|
|
|
|
Hi,
It has nothing to do there.
I had to delete those test code lines.
Regards,
Shaibu
|
|
|
|
|
I have been waiting for a long time for a simple bar graph control, was too lazy, thanks, you got my 5.
Actual Linux Penguins were harmed in the creation of this message.
|
|
|
|
|
Thanks Snyp
Shaibu
|
|
|
|
|