In my dialog I have the design of pie chart that blocks the opening of other dialogs..I don't know why..I can post class code
What I have tried:
There is a block of messageBox and dialog of c++ of error, I can put PieChatWnd.cpp
<pre>
#include "stdafx.h"
#include "PieChartWnd.h"
#include <math.h>
#include <limits>IMPLEMENT_DYNAMIC(CPieChartWnd, CWnd)
CPieChartWnd::CPieChartWnd():i_elementIndex(0), d_totalVal(0)
{
lb_param.hght = 20;
lb_param.wdth = 50;
lb_param.xGapLeft = 200;
lb_param.xGapRight = 20;
lb_param.yGap = 10;
lb_param.fStyle = FontStyleRegular;
lb_param.sFont = "";
lb_info.lbRctHght= 0;
lb_info.lbIndex = 0;
lb_info.lbVisibleRectHght = 1000;
lb_info.lbTextColor = Color::Black;
lb_info.lbValueRectColor = Color::Black;
lb_info.sMaxLenString = "";
bkg_params.cr_backgrnd = Color::White;
bkg_params.cr_GradientD = Color::White;
bkg_params.cr_GradientL = Color::White;
bkg_params.s_ChartTittle = "";
bkg_params.f_ColorGradD = 0;
bkg_params.f_ColorGradL = 0;
bkg_params.sFont = "";
bkg_params.fStyle = FontStyleRegular;
fl_startAngle = 0;
fl_startAngleIncline = 0;
fl_InclineAngle = 0;
f_depth = .5;
b_SaveFlag = FALSE;
b_ShowPercentages = TRUE;
pie_ChartStyle = ThreeDStyle;
cr_HighlightColor = Color(255, 255, 255);
s_saveImage = "";
}
CPieChartWnd::~CPieChartWnd()
{
map<int, pie_chart_element*="">::iterator iter = map_pChart.begin();
for (; iter != map_pChart.end(); ++iter)
{
if(iter->second)
{
pie_chart_element* ele = iter->second;
if(ele)
delete ele;
}
}
map_pChart.clear();
Gdiplus::GdiplusShutdown(m_gdiplusToken);
}
BEGIN_MESSAGE_MAP(CPieChartWnd, CWnd)
ON_WM_PAINT()
ON_WM_CREATE()
ON_WM_SIZE()
ON_WM_VSCROLL()
ON_WM_LBUTTONDOWN()
END_MESSAGE_MAP()
void CPieChartWnd::OnPaint()
{
CPaintDC dc(this);
if (pie_ChartStyle == DoughnutStyle)
DrawDoughnutStyle(&dc);
if (pie_ChartStyle == TwoDStyle)
Draw2DStyle(&dc);
if (pie_ChartStyle == ThreeDStyle)
Draw3DStyle(&dc);
ManageTime(m_dPrimoValore,m_dSecondoValore);
}
int CPieChartWnd::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CWnd::OnCreate(lpCreateStruct) == -1)
return -1;
ModifyStyle(0, WS_CLIPCHILDREN);
CRect rect;
GetClientRect(rect);
m_VscrollBar.Create(WS_CHILD | SBS_VERT,CRect(rect.right -40, rect.top + 10, rect.right -20, rect.bottom - 10), this, 1);
return 0;
}
void CPieChartWnd::DrawDoughnutStyle(CDC* pDc)
{
CRect rect;
CRect rectBnd;
Bitmap* mBtmap = NULL;
Graphics* graphics = NULL;
float totalAngle = fl_startAngle;
map<int, pie_chart_element*="">::iterator iter;
Pen penOutLine(Color::White, 1);
GetBoundRect(rectBnd);
GetClientRect(rect);
mBtmap = new Bitmap(rect.Width(), rect.Height());
graphics = Graphics::FromImage(mBtmap);
graphics->SetSmoothingMode(SmoothingModeHighQuality);
DrawBackGround(graphics);
LinearGradientBrush brBkgndInner(PointF((REAL)rect.left, (REAL) rect.top),
PointF((REAL)rect.right, (REAL)rect.bottom),
bkg_params.cr_GradientL,
bkg_params.cr_GradientD);
REAL rRatio = (REAL)rectBnd.Width() / 15;
LinearGradientBrush crGradient(Point(rectBnd.right/2, rectBnd.top),
Point(rectBnd.right/2, rectBnd.bottom),
Color(0,0,0),
Color(0,0,0));
SolidBrush brHighLight(Color(100, cr_HighlightColor.GetR(), cr_HighlightColor.GetG(), cr_HighlightColor.GetB()));
Pen pnHighLight(cr_HighlightColor);
iter = map_pChart.begin();
for(; iter != map_pChart.end(); ++iter)
{
pie_chart_element* ele = iter->second;
if (ele){
penOutLine.SetColor(CalculateGradientLight(ele->cr_Base, 160));
crGradient.SetLinearColors(ele->cr_GradientL, ele->cr_GradientD);
graphics->FillPie(&crGradient,
RectF((REAL)rectBnd.left, (REAL)rectBnd.top, (REAL)rectBnd.Width(), (REAL)rectBnd.Height()),
(REAL)totalAngle,
(REAL)ele->f_angle);
crGradient.SetLinearColors(ele->cr_GradientD, ele->cr_GradientL);
graphics->FillPie(&crGradient,
RectF(REAL(rectBnd.left + rRatio),
REAL(rectBnd.top + rRatio),
REAL(rectBnd.Width() - rRatio * 2),
REAL(rectBnd.Height()- rRatio * 2)),
(REAL)totalAngle,
(REAL)ele->f_angle);
graphics->DrawPie(&penOutLine,
RectF((REAL)rectBnd.left, (REAL)rectBnd.top, (REAL)rectBnd.Width(), (REAL)rectBnd.Height()),
(REAL)totalAngle,
(REAL)ele->f_angle);
if (ele->b_select){
graphics->FillPie(&brHighLight,
RectF((REAL)rectBnd.left, (REAL)rectBnd.top, (REAL)rectBnd.Width(), (REAL)rectBnd.Height()),
(REAL)totalAngle,
(REAL)ele->f_angle);
graphics->DrawPie(&pnHighLight,
RectF((REAL)rectBnd.left, (REAL)rectBnd.top, (REAL)rectBnd.Width(), (REAL)rectBnd.Height()),
(REAL)totalAngle,
(REAL)ele->f_angle);
}
totalAngle += ele->f_angle;
}
}
if (!map_pChart.empty())
{
graphics->FillEllipse(&brBkgndInner, RectF( REAL(rectBnd.CenterPoint().x - rRatio * 3),
REAL(rectBnd.CenterPoint().y - rRatio * 3),
rRatio * 6, rRatio * 6));
penOutLine.SetBrush(&brBkgndInner);
graphics->DrawEllipse(&penOutLine, RectF( REAL(rectBnd.CenterPoint().x - rRatio * 3),
REAL(rectBnd.CenterPoint().y - rRatio * 3),
rRatio * 6, rRatio * 6));
}
DrawLabels(graphics);
if(b_ShowPercentages)
DrawPiechartPecentages(graphics, fl_startAngle);
delete graphics;
graphics = NULL;
Graphics gr(pDc->m_hDC);
CachedBitmap* btmp = new CachedBitmap(mBtmap, &gr);
SaveImageInternal(mBtmap);
if (mBtmap)
{
delete mBtmap;
mBtmap = NULL;
}
gr.DrawCachedBitmap(btmp, rect.left, rect.top);
if (btmp)
{
delete btmp;
btmp = NULL;
}
}
void CPieChartWnd::ManageTime(double dLoadTime, double dUnloadTime)
{
CPieChartWnd::InsertItem(_T("Rendimento"), _T("Rendimento"), dLoadTime, Color(255, 255, 50, 50));
CPieChartWnd::InsertItem(_T("Restante"), _T("Restante"), dUnloadTime, Color(255, 166, 190, 255));
CPieChartWnd::SetInclineAngle(40);
CPieChartWnd::SetDepth(40);
CPieChartWnd::SetBackgrndColor(Color(255, 240, 240, 250));
CRect rect;
CPieChartWnd::GetClientRect(rect);
Invalidate();
}
PIECHARTITEM CPieChartWnd::InsertItem(CString sElement, CString sLabel, double dValue, Color crColor)
{
d_totalVal = 100.00;
if (sElement.Compare(L"") && !HasElement(sElement) && dValue > 0)
{
pie_chart_element* element = new pie_chart_element;
element->s_element = sElement;
element->s_label = sLabel;
element->d_value = dValue;
element->f_angle = 0;
element->f_percentage = 0;
element->i_ID = i_elementIndex;
map_pChart[i_elementIndex] = element;
i_elementIndex++;
element->cr_Base = crColor;
element->f_ColorGradD = GRADIENTD;
element->f_ColorGradL = GRADIENTL;
element->cr_GradientL = CalculateGradientLight(crColor, GRADIENTL);
element->cr_GradientD = CalculateGradientDark(crColor, GRADIENTD);
element->b_select = FALSE;
if (sLabel.GetLength() > lb_info.sMaxLenString.GetLength())
{
lb_info.sMaxLenString = sLabel;
}
UpdatePieChart();
CalculateLabelRect();
ResetItemScrollBar();
Invalidate();
return (PIECHARTITEM)element;
}
return NULL;
}
void CPieChartWnd::UpdatePieChart(void)
{
map<int, pie_chart_element*="">::iterator iter = map_pChart.begin();
iter = map_pChart.begin();
for(; iter != map_pChart.end(); ++iter)
{
pie_chart_element* ele = iter->second;
if (d_totalVal > 0)
{
ele->f_percentage = float(ele->d_value / d_totalVal);
ele->f_angle = 360 * ele->f_percentage;
ele->pie_3d_props.f_InclineAngle = ele->f_angle;
}
}
}
Color CPieChartWnd::CalculateGradientLight(Color crBase, float fGradVal)
{
BYTE r = crBase.GetR();
BYTE g = crBase.GetG();
BYTE b = crBase.GetB();
float fact = 255.0f;
float rGrad = (255 - r) / fact;
float gGrad = (255 - g) / fact;
float bGrad = (255 - b) / fact;
r = BYTE(min(r + rGrad * fGradVal, 255));
b = BYTE(min(b + bGrad * fGradVal, 255));
g = BYTE(min(g + gGrad * fGradVal, 255));
return Color(r, g, b);
}
Color CPieChartWnd::CalculateGradientDark(Color crBase, float fGradVal)
{
BYTE r = crBase.GetR();
BYTE g = crBase.GetG();
BYTE b = crBase.GetB();
float fact = 255.0f;
float rGrad = r / fact;
float gGrad = g / fact;
float bGrad = b / fact;
r = BYTE(max(r - rGrad * fGradVal, 0));
b = BYTE(max(b - bGrad * fGradVal, 0));
g = BYTE(max(g - gGrad * fGradVal, 0));
return Color(r, g, b);
}
BOOL CPieChartWnd::HasElement(CString sElement)
{
map<int, pie_chart_element*="">::iterator iter;
iter = map_pChart.begin();
for(; iter != map_pChart.end(); ++iter)
{
pie_chart_element* ele = iter->second;
if (!ele->s_element.Compare(sElement))
return TRUE;
}
return FALSE;
}
int CPieChartWnd::GetElementID(CString sElement)
{
map<int, pie_chart_element*="">::iterator iter;
iter = map_pChart.begin();
for(; iter != map_pChart.end(); ++iter)
{
pie_chart_element* ele = iter->second;
if (!ele->s_element.Compare(sElement))
return ele->i_ID;
}
return -1;
}
BOOL CPieChartWnd::RemoveItem(CString sElement)
{
map<int, pie_chart_element*="">::iterator iter;
iter = map_pChart.begin();
for(; iter != map_pChart.end(); ++iter)
{
pie_chart_element* ele = iter->second;
if (!ele->s_element.Compare(sElement))
{
d_totalVal -= ele->d_value;
delete ele;
ele = NULL;
map_pChart.erase(iter);
i_elementIndex--;
ReArrangeElementMap();
UpdatePieChart();
CalculateLabelRect();
GetVerticalScrollPos(m_VscrollBar.GetScrollPos(), false);
ResetItemScrollBar();
Invalidate();
return TRUE;
}
}
return FALSE;
}
BOOL CPieChartWnd::RemoveItem(int iElementID)
{
map<int, pie_chart_element*="">::iterator iter;
iter = map_pChart.find(iElementID);
if (iter != map_pChart.end())
{
pie_chart_element* ele = iter->second;
d_totalVal -= ele->d_value;
delete ele;
ele = NULL;
map_pChart.erase(iter);
i_elementIndex--;
ReArrangeElementMap();
UpdatePieChart();
CalculateLabelRect();
GetVerticalScrollPos(m_VscrollBar.GetScrollPos(), false);
ResetItemScrollBar();
Invalidate();
return TRUE;
}
return FALSE;
}
PIECHARTITEM CPieChartWnd::GetPieChartItem(CString sElement)
{
map<int, pie_chart_element*="">::iterator iter;
iter = map_pChart.begin();
for(; iter != map_pChart.end(); ++iter)
{
pie_chart_element* ele = iter->second;
if (!ele->s_element.Compare(sElement))
return (PIECHARTITEM)ele;
}
return NULL;
}