|
Thanks for the answer. I thought that there is a way using DirectX but I wanted to avoid it. But since I did not find any other ways I think I must use it.
|
|
|
|
|
Hi all
How do you draw an ellipse using c++ given that you've got all the coefficients (ie. a,b,c,d,e & f). The ellipse() function that i know only accepts the vertices of the rectangle (as the parameters) in which the ellipse should be drawn. I need it for my final year project at uni. Thanks a lot
|
|
|
|
|
Well,
the first aproach might be to calculate the enclosing rectangle of your ellipse function by using the first degration( german:Ableitung) in x and y. for finding the minimum and maximum coordinates. But then you will find out, that the ellipse function will only draw parallel to the x- and y-axis.
The only way to draw an arbitrary ellipse is to use the path functions with transform parameters/matrices. These graphic functions are only supported in Windows NT/2000. With XP I can't tell. They are definitly not supported in Win95/98/ME.
Even dwarves started small.
|
|
|
|
|
how can i use this path function?can you explain a little bit more please? i'm using win2k.
|
|
|
|
|
Okay,
here is the code. I took it from a private project, I developed in 1996. It took me quite a while to find it.
void CGraphEllipse::zeichne(CDC* pDC)
{ if( m_listAbschnitte.IsEmpty() ) return;
if( m_a == 0.0 ) return;
CPen *pOldPen = pDC->SelectObject(&m_penStift);
CBrush *pOldBrush = pDC->SelectObject(&m_brPinsel);
XFORM xfMatrix;
xfMatrix.eM11 = 1.0;
xfMatrix.eM12 = 0.0;
xfMatrix.eM21 = 0.0;
xfMatrix.eM22 = 1.0;
xfMatrix.eDx = 0.0;
xfMatrix.eDy = 0.0;
double dSinPhi = 0;
double dCosPhi = 1;
double dPhi = 0;
if( m_c != m_a ) dPhi = atan2(2*m_b,(m_a-m_c))/2.0;
dSinPhi = sin(dPhi);
dCosPhi = cos(dPhi);
xfMatrix.eM11 = dCosPhi;
xfMatrix.eM12 = dSinPhi;
xfMatrix.eM21 = -dSinPhi;
xfMatrix.eM22 = dCosPhi;
xfMatrix.eDx = m_ptZiehZentrum.x;
xfMatrix.eDy = m_ptZiehZentrum.y;
SetGraphicsMode(pDC->m_hDC,GM_ADVANCED);
pDC->BeginPath();
SetWorldTransform(pDC->m_hDC,&xfMatrix);
pDC->Ellipse(-(int)m_dR1,-(int)m_dR2,(int)m_dR1,(int)m_dR2);
pDC->EndPath();
if( m_bGeschlossen )
{ if( m_bOpaque ) pDC->StrokeAndFillPath();
else pDC->StrokePath();
}
else pDC->StrokePath();
pDC->SelectObject(pOldPen);
pDC->SelectObject(pOldBrush);
ModifyWorldTransform(pDC->m_hDC,NULL,MWT_IDENTITY);
SetGraphicsMode(pDC->m_hDC,GM_COMPATIBLE);
}
This function was used to draw a arbitrary rotated ellipse.
Of course, you have to do your own calculations for the centerpoints and that stuff.
The point of interest is the calculation of the transformation matrix. But this you should have alredy done if you have the coeffx of your ellipse.
Hope this helps
See also help for XFORM and CDC Path functions in your VC-Compiler
G. Steudtel
Even dwarves started small.
|
|
|
|
|
Well,
the first aproach might be to calculate the enclosing rectangle of your ellipse function by using the first degration( german:Ableitung) in x and y. for finding the minimum and maximum coordinates. But then you will find out, that the ellipse function will only draw parallel to the x- and y-axis.
The only way to draw an arbitrary ellipse is to use the path functions with transform parameters/matrices. These graphic functions are only supported in Windows NT/2000. With XP I can't tell. They are definitly not supported in Win95/98/ME.
G. Steudtel
Even dwarves started small.
|
|
|
|
|
Is it better, when designing visual components to register them with RegisterClass so that a user can place a custom control in the resource editor; or to simply use a CWnd derived class and treat the visual components as a simple C++ class entity ?
I think that RegisterClass is something that is more Win32 lingo than C++ (and/or MFC).
Max.
Maximilien Lincourt
For success one must aquire one's self
|
|
|
|
|
Personally I'd go the RegisterClass route. There have been times I've used a custom control using straight Win32, no MFC or classes. It'll make your control usable than just MFC, you could use it from VB, Delphi, Python, who knows what else.
Joel Lucsy
|
|
|
|
|
Hy guys,
I'm building an application (Visual C++) that has to write the results of elaboration on a CD-ROM using the ISO9660 format (praticly creating the ISO-image and after burn a CD-R!!).
I know that in WindowsXP this operation is integrated inside the OS (or better the OS use automaticly the SW layer relative to burn CD)but in my case I'll use Windows2000.
Anyway,I suppose that will be necessary to include a library or buy a SDK but unfortunatly I have no ideas about where and how find it and eventually some explaination to how use it.
Someone have some suggests for me,please.
Thanks in advance
Andrea
|
|
|
|
|
Read all you can about the ISO format, cause you might have to code everything yourself. There are lots of open source rojects where you can learn about CD-ROM image creation.
Finally there are a few CD-ROM writing libraries and SDK like www.padus.com and others that might help you.
|
|
|
|
|
Hi,
I'm using GDI+ in my MFC based application and create GDI+ classes on the fly using the new operator as follows:
Bitmap* mybitmap = new Bitmap(320,24);
The above line compiles fine if I build the application in release mode, but in debug mode, compiler (VC++6.0 w. SP5, latest platform sdk) fails with:
error C2660: 'new' : function does not take 3 parameters
That is because of mfc's debug definitions on top of the file:
#ifdef _DEBUG<br />
#define new DEBUG_NEW<br />
#undef THIS_FILE<br />
static char THIS_FILE[] = __FILE__;<br />
#endif
and DEBUG_NEW is defined in afx.h as:
#define DEBUG_NEW new(THIS_FILE, __LINE__)
So, what exactly is wrong with calling a constructor with parameters? Does the "debug" version new operator handle the case incorrect or am I making a terrible mistake somewhere?
Any help would be appreciated.
P.S: Bitmap(320,200) is the same as Bitmap(320,200,PixelFormat32bppARGB) and neither case it didn't compile.
|
|
|
|
|
http://www.codeproject.com/vcpp/gdiplus/gdiplusspeed.asp#xx81095xx
Read the thread "Can't create bitmaps with new"
|
|
|
|
|
I found if you comment out the line #define new DEBUG_NEW it will work just fine. You just won't have any indications that you're leaking memory.
Joel Lucsy
|
|
|
|
|
Thanks for the comments, though I know that it works without defining DEBUG_NEW or with using the new operator from globalnamespace (i.e. ::new) as described in Benjamin's comment, but does anyone have any idea why it doesn't work with GDI+ classes? I mean there must be some error somewhere, since the debug_new operator seems to work fine with classes who take parameters in their constructors but not with GDI+.
For example I have created a class with
class CTest <br />
{<br />
public:<br />
CTest();<br />
CTest(int x);<br />
virtual ~CTest();<br />
};<br />
and it works fine by
CTest* test = new CTest(3);
and further testing.. tadaa I found the error!
if your class lacks a constructor without parameters (so do the GDI+ classes), as in:
class CTest <br />
{<br />
public:<br />
CTest(int x);<br />
virtual ~CTest();<br />
};<br />
the debug new operator fails on the following line:
<br />
CTest* test = new CTest(3);<br />
Must be a bug or a lazy implementation.
edit:
That wasn't true, I retested it and debug_new works with the CTest class in both cases.
I'm pretty confused by now..
|
|
|
|
|
Hope I can post this here. How do I disable/enable the message that comes up when you want to delete a file in general on windows? I'm not looking for tis info in Help in the right way so I cant find it...
Appreciate your help,
ns
|
|
|
|
|
Right click on your rec. bin and select properties, then check or uncheck the 'Display delete confirmation dialog' check box.
Or did you mean in code?
Dylan
|
|
|
|
|
Nope> Just mechanically like you informed me. Many thanks!
Appreciate your help,
ns
|
|
|
|
|
I have made a base class like this:
class CLogBook
{
public:
CLogBook();
virtual ~CLogBook();
BOOL Open(string);
void Close();
BOOL FillListBox(HWND);
virtual BOOL Write(string) = 0;
BOOL Clear();
protected:
fstream m_filestream;
};
and a derived class like:
class CErrorLog : public CLogBook
{
public:
CErrorLog();
~CErrorLog();
BOOL Write(string);
};
It builds fine untill I declare a varible of CErrorLog somewhere in my code!
Then I get:
NetPaint error LNK2019: unresolved external symbol "public: __thiscall CErrorLog::CErrorLog(void)" (??0CErrorLog@@QAE@XZ) referenced in function _$E1
NetPaint error LNK2019: unresolved external symbol "public: virtual __thiscall CErrorLog::~CErrorLog(void)" (??1CErrorLog@@UAE@XZ) referenced in function _$E2
I think errors like these are impossible for you to solve, but I make I tray anyway!
Rickard Andersson@Suza Computing
C# and C++ programmer from SWEDEN!
UIN: 50302279
E-Mail: nikado@pc.nu
Speciality: I love C#, ASP.NET and C++!
|
|
|
|
|
Seems that your CErrorLog class is not included in your project.
So :
1. Make sure ErrorLog.cpp and .h have been loaded in your project.(Look at the file browser)
2. Check your #include's
~RaGE();
|
|
|
|
|
I don't think that is the problem...
This is my .h file:
extern string strDay[7];
extern string strMonth[12];
class CLogBook
{
public:
CLogBook();
virtual ~CLogBook();
BOOL Open(string);
void Close();
BOOL FillListBox(HWND);
virtual BOOL Write(string) = 0;
BOOL Clear();
protected:
fstream m_filestream;
};
class CErrorLog : public CLogBook
{
public:
CErrorLog();
~CErrorLog();
BOOL Write(string);
};
And my .cpp:
#include "stdafx.h"
string strDay[7] = {"Söndag", "Måndag",
"Tisdag", "Onsdag",
"Torsdag", "Fredag",
"Lördag"};
string strMonth[12] = {"januari", "februari", "mars",
"april", "maj", "juni",
"juli", "augusti", "september",
"oktober", "november", "december"};
CLogBook::~CLogBook()
{
Close();
}
BOOL CLogBook::Open(string path)
{
m_filestream.open(path.c_str(),
ios_base::in | ios_base::out | ios_base::app);
if(!m_filestream.is_open())
return FALSE;
return TRUE;
}
void CLogBook::Close()
{
if(!m_filestream.is_open())
m_filestream.close();
}
BOOL CLogBook::Clear()
{
if(!m_filestream.is_open())
return FALSE;
m_filestream.write("",0);
return TRUE;
}
BOOL CLogBook::FillListBox(HWND listbox)
{
if(!m_filestream.is_open())
return FALSE;
m_filestream.seekg(0);
while(!m_filestream.eof())
{
string buf("");
getline(m_filestream, buf, '\n');
ListBox_AddString(listbox, buf.c_str());
}
return TRUE;
}
BOOL CLogBook::Write(string data)
{
if(!m_filestream.is_open())
return FALSE;
m_filestream.write(data.c_str(), (int)data.length());
return TRUE;
}
BOOL CErrorLog::Write(string data)
{
string strDataToWrite("");
strDataToWrite.append(DateTimeString());
strDataToWrite.append(" > ");
strDataToWrite.append(data);
return CLogBook::Write(strDataToWrite);
}
Rickard Andersson@Suza Computing
C# and C++ programmer from SWEDEN!
UIN: 50302279
E-Mail: nikado@pc.nu
Speciality: I love C#, ASP.NET and C++!
|
|
|
|
|
C++ will not "include" (map) object as long as it's not referenced....
So if you declare class:
class CBrian {
CBrian();
virtual ~CBrian();
void X();
}
It will compile just fine even tho CBrian() and ~CBrian() has no body.
As soon as you declare: CBrain var; compiler will try to map space(frame) for all object members and functions. C++ at that stage will notice all the missing members.
|
|
|
|
|
Argh!
Thank you!
I made a body for all my "unresolved external symbols" and it works!
Rickard Andersson@Suza Computing
C# and C++ programmer from SWEDEN!
UIN: 50302279
E-Mail: nikado@pc.nu
Speciality: I love C#, ASP.NET and C++!
|
|
|
|
|
DWORD dwCb = sizeof(RASENTRYNAME);
DWORD dwEntries = 0;
RASENTRYNAME lpRasEntryName[20];
lpRasEntryName[0].dwSize = sizeof(RASENTRYNAME);
RasEnumEntries(NULL,NULL,lpRasEntryName,&dwCb,&dwEntries);
This is the code. The problem is that RasEnumEntries returns 610 which is ERROR_BUFFER_INVALID only on Windows98. The code works perfectly on win2000. What is the problem, I need this problem to be solved as soon as possible
Please help me
|
|
|
|
|
Jump_Around wrote:
DWORD dwCb = sizeof(RASENTRYNAME);
DWORD dwEntries = 0;
RASENTRYNAME lpRasEntryName[20];
lpRasEntryName[0].dwSize = sizeof(RASENTRYNAME);
RasEnumEntries(NULL,NULL,lpRasEntryName,&dwCb,&dwEntries);
Change to:
DWORD dwCb = sizeof(RASENTRYNAME);<br />
DWORD dwEntries = 0;<br />
RASENTRYNAME lpRasEntryName[20];<br />
<br />
ZeroMemory(lpRasEntryName, sizeof(lpRasEntryName));<br />
<br />
lpRasEntryName[0].dwSize = sizeof(RASENTRYNAME);<br />
RasEnumEntries(NULL,NULL,lpRasEntryName,&dwCb,&dwEntries);
I'm not sure about it
Rickard Andersson@Suza Computing
C# and C++ programmer from SWEDEN!
UIN: 50302279
E-Mail: nikado@pc.nu
Speciality: I love C#, ASP.NET and C++!
|
|
|
|
|
Try:
DWORD dwCb = 20 * sizeof(RASENTRYNAME);
|
|
|
|