Troubles when converting this C# to C++

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hi, I have a working piece of C# code, and Im needing it in C++. Its quite a lot of code, but hopefully a simple fix. This is what Ive got.
clsColors.h

<div style="color:Black;background-color:White; <pre>
#pragma once

<span style="color:Blue; using <span style="color:Blue; namespace System;
<span style="color:Blue; using <span style="color:Blue; namespace System::Drawing;
<span style="color:Blue; using <span style="color:Blue; namespace System::Collections;
<span style="color:Blue; using <span style="color:Blue; namespace System::Collections::Generic;
<span style="color:Blue; using <span style="color:Blue; namespace System::Data;
<span style="color:Blue; using <span style="color:Blue; namespace System::Diagnostics;

<span style="color:Blue; ref class clsColors
{
<span style="color:Blue; public:
<span style="color:Blue; static Color clrHorBG_GrayBlue = Color.FromArgb(255, 233, 236, 250);
<span style="color:Blue; static Color clrHorBG_White = Color.FromArgb(255, 244, 247, 252);
<span style="color:Blue; static Color clrSubmenuBG = Color.FromArgb(255, 240, 240, 240);
<span style="color:Blue; static Color clrImageMarginBlue = Color.FromArgb(255, 212, 216, 230);
<span style="color:Blue; static Color clrImageMarginWhite = Color.FromArgb(255, 244, 247, 252);
<span style="color:Blue; static Color clrImageMarginLine = Color.FromArgb(255, 160, 160, 180);
<span style="color:Blue; static Color clrSelectedBG_Blue = Color.FromArgb(255, 186, 228, 246);
<span style="color:Blue; static Color clrSelectedBG_Header_Blue = Color.FromArgb(255, 146, 202, 230);
<span style="color:Blue; static Color clrSelectedBG_White = Color.FromArgb(255, 241, 248, 251);
<span style="color:Blue; static Color clrSelectedBG_Border = Color.FromArgb(255, 150, 217, 249);
<span style="color:Blue; static Color clrSelectedBG_Drop_Blue = Color.FromArgb(255, 139, 195, 225);
<span style="color:Blue; static Color clrSelectedBG_Drop_Border = Color.FromArgb(255, 48, 127, 177);
<span style="color:Blue; static Color clrMenuBorder = Color.FromArgb(255, 160, 160, 160);

<span style="color:Blue; static Color clrCheckBG = Color.FromArgb(255, 206, 237, 250);
<span style="color:Blue; static Color clrVerBG_GrayBlue = Color.FromArgb(255, 196, 203, 219);
<span style="color:Blue; static Color clrVerBG_White = Color.FromArgb(255, 250, 250, 253);

<span style="color:Blue; static Color clrVerBG_Shadow = Color.FromArgb(255, 181, 190, 206);
<span style="color:Blue; static Color clrToolstripBtnGrad_Blue = Color.FromArgb(255, 129, 192, 224);
<span style="color:Blue; static Color clrToolstripBtnGrad_White = Color.FromArgb(255, 237, 248, 253);
<span style="color:Blue; static Color clrToolstripBtn_Border = Color.FromArgb(255, 41, 153, 255);
<span style="color:Blue; static Color clrToolstripBtnGrad_Blue_Pressed = Color.FromArgb(255, 124, 177, 204);

Color clrToolstripBtnGrad_White_Pressed = Color.FromArgb(255, 228, 245, 252);

clsColors(<span style="color:Blue; void);
<span style="color:Blue; void DrawRoundedRectangle(Graphics objGraphics, <span style="color:Blue; int m_intxAxis, <span style="color:Blue; int m_intyAxis, <span style="color:Blue; int m_intWidth, <span style="color:Blue; int m_intHeight, <span style="color:Blue; int m_diameter, Color color);
};
[/code]

clsColors.cpp

<div style="color:Black;background-color:White; <pre>
#include <span style="color:#A31515; "StdAfx.h"
#include <span style="color:#A31515; "clsColors.h"

clsColors::clsColors(<span style="color:Blue; void)
{
<span style="color:Blue; void DrawRoundedRectangle(Graphics objGraphics, <span style="color:Blue; int m_intxAxis, <span style="color:Blue; int m_intyAxis, <span style="color:Blue; int m_intWidth, <span style="color:Blue; int m_intHeight, <span style="color:Blue; int m_diameter, Color color)
{
Pen^ pen = <span style="color:Blue; gcnew Pen(color);

<span style="color:Green; //Dim g As Graphics
RectangleF^ BaseRect = <span style="color:Blue; gcnew RectangleF(m_intxAxis, m_intyAxis, m_intWidth, m_intHeight);
RectangleF^ ArcRect = <span style="color:Blue; gcnew RectangleF(BaseRect->Location, <span style="color:Blue; gcnew SizeF(m_diameter, m_diameter));
<span style="color:Green; //top left Arc
objGraphics->DrawArc(pen, ArcRect, 180, 90);
objGraphics->DrawLine(pen, m_intxAxis + Convert->ToInt32(m_diameter / 2), m_intyAxis, m_intxAxis + m_intWidth - Convert->ToInt32(m_diameter / 2), m_intyAxis);

<span style="color:Green; // top right arc
ArcRect->X = BaseRect->Right - m_diameter;
objGraphics->DrawArc(pen, ArcRect, 270, 90);
objGraphics->DrawLine(pen, m_intxAxis + m_intWidth, m_intyAxis + Convert->ToInt32(m_diameter / 2), m_intxAxis + m_intWidth, m_intyAxis + m_intHeight - Convert->ToInt32(m_diameter / 2));

<span style="color:Green; // bottom right arc
ArcRect->Y = BaseRect->Bottom - m_diameter;
objGraphics->DrawArc(pen, ArcRect, 0, 90);
objGraphics->DrawLine(pen, m_intxAxis + Convert->ToInt32(m_diameter / 2), m_intyAxis + m_intHeight, m_intxAxis + m_intWidth - Convert->ToInt32(m_diameter / 2), m_intyAxis + m_intHeight);

<span style="color:Green; // bottom left arc
ArcRect.X = BaseRect->Left;
objGraphics->DrawArc(pen, ArcRect, 90, 90);
objGraphics->DrawLine(pen, m_intxAxis, m_intyAxis + Convert->ToInt32(m_diameter / 2), m_intxAxis, m_intyAxis + m_intHeight - Convert->ToInt32(m_diameter / 2));
}
}

[/code]

Most of this code, repeats itself... so if you could correct one piece, Ill be able to (or should be able to) do the rest. Originally it was VB, but I got it to C# nicely.
Here are the errors that I am getting.
1> clsColors.cpp<br/>
1>c:usersjeaniedocumentsvisual studio 2010projectstestingoutcpptestingoutcppclsColors.h(37): error C3845: clsColors::clrToolstripBtnGrad_White_Pressed: only static data members can be initialized inside a ref class or value type<br/>
1>clsColors.cpp(7): error C2601: DrawRoundedRectangle : local function definitions are illegal<br/>
1> clsColors.cpp(5): this line contains a { which has not yet been matched<br/>
1>clsColors.cpp(11): warning C4244: argument : conversion from int to float, possible loss of data<br/>
1>clsColors.cpp(11): warning C4244: argument : conversion from int to float, possible loss of data<br/>
1>clsColors.cpp(11): warning C4244: argument : conversion from int to float, possible loss of data<br/>
1>clsColors.cpp(11): warning C4244: argument : conversion from int to float, possible loss of data<br/>
1>clsColors.cpp(12): warning C4244: argument : conversion from int to float, possible loss of data<br/>
1>clsColors.cpp(12): warning C4244: argument : conversion from int to float, possible loss of data<br/>
1>clsColors.cpp(12): error C2664: System::Drawing::RectangleF::RectangleF(System::Drawing::PointF,System::Drawing::SizeF) : cannot convert parameter 2 from System::Drawing::SizeF ^ to System::Drawing::SizeF<br/>
1> No user-defined-conversion operator available, or<br/>
1> No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called<br/>
1>clsColors.cpp(12): fatal error C1903: unable to recover from previous error(s); stopping compilation

Whats the problem? <hr class="sig Just Learning. No hard feelings if I seem very dumb.

View the full article
 
Back
Top