У меня проблема в моем коде. Я переписывать существующий модуль, нарисовать график (от электрической consomation) с GDI + (да Visual Studio Microsoft и со) Вот мой код, чтобы нарисовать один графПередача char * в качестве аргумента
void CourbeComptage::afficheCourbeJour_nonEDF(CWnd *cwnd)
{
dessin ligne,rectangle,texte;
int i;
int lx = x + margeH;
int ly = y + haut - margeV;
int x1, y1, x2, y2;
if(flagCourbe)
{
afficheGraduation();
// 4 - tracer la courbe de consommation avec des plages horaires
for(i=0;i<24;i++)
{
x1 = lx + i * pasX;
y1 = ly - coorX_conso[i];
x2 = lx + (i + 1) * pasX;
y2 = ly - 1;
plage[i] = (plage[i] > 3) ? 3 : (plage[i] < 1) ? 1 : plage[i];
if(typeCourbe == COURBE_BARRE_3D)
{
drawer->DrawFilledGradientRectangle(x1, y1, x2, y2, gradient[plage[i]], "transparent", 1);
switch(plage[i])
{
case 1: drawer->DrawFilledGradientRectangle(x1, y1, x2, y2, "conso_HC", "transparent", 1); break;
case 2: drawer->DrawFilledGradientRectangle(x1, y1, x2, y2, "conso_HP", "transparent", 1); break;
case 3: drawer->DrawFilledGradientRectangle(x1, y1, x2, y2, "conso_P", "transparent", 1); break;
}
}
else if(typeCourbe == COURBE_BARRE)
{
switch(plage[i])
{
case 1: drawer->DrawFilledSolidRectangle(x1, y1, x2, y2, "conso2_HC", "transparent", 1); break;
case 2: drawer->DrawFilledSolidRectangle(x1, y1, x2, y2, "conso2_HP", "transparent", 1); break;
case 3: drawer->DrawFilledSolidRectangle(x1, y1, x2, y2, "conso2_P", "transparent", 1); break;
}
}
else if(this->typeCourbe == COURBE_LIGNE)
{
if(i!= 23)
{
switch(plage[i])
{
case 1: drawer->DrawLine(lx + pasX/2 + i*pasX, ly - coorX_conso[i], lx + pasX/2 + (i+1)*pasX, ly - coorX_conso[i+1], "conso2_HC"); break;
case 2: drawer->DrawLine(lx + pasX/2 + i*pasX, ly - coorX_conso[i], lx + pasX/2 + (i+1)*pasX, ly - coorX_conso[i+1], "conso2_HP"); break;
case 3: drawer->DrawLine(lx + pasX/2 + i*pasX, ly - coorX_conso[i], lx + pasX/2 + (i+1)*pasX, ly - coorX_conso[i+1], "conso2_P"); break;
}
}
// A ecrire 4 types point x 2 lignes de courbe (conso et react)
}
}
}
}
Для того, чтобы упростить свой код и избежать некоторых тест я просто хочу, чтобы преобразовать, что:
switch(plage[i])
{
case 1: drawer->DrawFilledGradientRectangle(x1, y1, x2, y2, "conso_HC", "transparent", 1); break;
case 2: drawer->DrawFilledGradientRectangle(x1, y1, x2, y2, "conso_HP", "transparent", 1); break;
case 3: drawer->DrawFilledGradientRectangle(x1, y1, x2, y2, "conso_P", "transparent", 1); break;
}
в том, что:
drawer->DrawFilledGradientRectangle(x1, y1, x2, y2, gradient[plage[i]], "transparent", 1);
Так что я переписать эту функцию вроде:
void CourbeComptage::afficheCourbeJour_nonEDF(CWnd *cwnd)
{
static char gradient[4][9] = {"default", "conso_HC", "conso_HP", "conso_P"},
solid[4][10] = {"default", "conso2_HC", "conso2_HP", "conso2_P"};
dessin ligne,rectangle,texte;
int i;
int lx = x + margeH;
int ly = y + haut - margeV;
int x1, y1, x2, y2;
if(flagCourbe)
{
afficheGraduation();
// 4 - tracer la courbe de consommation avec des plages horaires
for(i=0;i<24;i++)
{
x1 = lx + i * pasX;
y1 = ly - coorX_conso[i];
x2 = lx + (i + 1) * pasX;
y2 = ly - 1;
plage[i] = (plage[i] > 3) ? 3 : (plage[i] < 1) ? 1 : plage[i];
if(typeCourbe == COURBE_BARRE_3D)
{
drawer->DrawFilledGradientRectangle(x1, y1, x2, y2, gradient[plage[i]], "transparent", 1);
}
else if(typeCourbe == COURBE_BARRE)
{
drawer->DrawFilledSolidRectangle(x1, y1, x2, y2, solid[plage[i]], "transparent", 1);
}
else if(this->typeCourbe == COURBE_LIGNE)
{
if(i!= 23)
{
drawer->DrawLine(lx + pasX/2 + i*pasX, ly - coorX_conso[i], lx + pasX/2 + (i+1)*pasX, ly - coorX_conso[i+1], solid[plage[i]]);
}
}
}
}
}
И что делать не работает, а это означает, что DrawFilledSolidRectangle (например) получить строку, но не нарисовать прямоугольник после цвета, передаваемого в строке. Я не знаю почему. Я попытался динамически выделить две вкладки gradient
и solid
, но это тоже не работает.
Вот прототипы некоторых функций:
void DrawLine(int x1, int y1, int x2, int y2, char * penName);
void DrawFilledSolidRectangle(int x1, int y1, int x2, int y2, char * colorName, char * borderPen, int borderSize = 1, bool ombre = false);
void DrawFilledGradientRectangle(int x1, int y1, int x2, int y2, char * gradientName, char * borderPen, int borderSize = 1, bool ombre = false);
А вот код DrawFilledSolidRectangle (DrawFilledGradientRectangle одно и то же, за исключением кисти, которая используется)
Rect * rects = (Rect *)malloc(borderSize * sizeof(Rect));
Rect * tmp;
int i;
if(ombre) DrawRectangle(x1, y1, x2, y2, borderPen, true);
for(i = 0 ; i < borderSize ; i++)
{
tmp = new Rect(x1+i, y1+i, x2-x1-i, y2-y1-i);
rects[i] = *tmp;
}
DrawRectangles(rects, borderSize, borderPen);
x1 += i;
y1 += i;
x2 -= x1+i;
y2 -= y1-i;
SolidBrush * b = new SolidBrush(couleurs[colorName]);
gNaa->FillRectangle(b, x1, y1, x2, y2);
delete[](rects);
Спасибо за вашу помощь , и извините за мой английский.
1) Что за вопрос? 2) Вы выделяете что-то с помощью 'malloc', а затем удаляете с помощью' delete [] ', это неправильно. –
Что не работает? –
Я просто редактирую свои вопросы. Я не был ясен. Проблема в том, что последняя функция (DrawFilledSolidRectangle) не использует правильный цвет, даже если строка проходит хорошо. – AMDG