|
That's the funny thing, there isn't such a string in there...
|
|
|
|
|
How to Add/remove the Dialog caption and border at run time?
TIA
|
|
|
|
|
Change window style (GetWindowLong/SetWindowLong)
|
|
|
|
|
Hi there
Can anyone advise.
I have a class called Employee ok.
Now i want the user to create employees by adding
a name, empid and so on.
Creating an Employee object
// Employee *NewEmp = new Emp ??
I want the new employees details in a file .dat it keeps
on creating one employee overriding the previous info.
How can i create more than one employee
Hit me over the knuckles if im way of!
Am i using new wrong? or am i missing the hole new
concept totaly
thanks
|
|
|
|
|
if your class is written with contructor
Employee::Employee(CString strName, int iAge)
{
this->m_strName = strName;
this->m_iAge = iAge;
}
you probably could initiate your object as such
Employee *pEmp = new Employee(_T("Someone"), 22);
these are basic, man
Sonork 100.41263:Anthony_Yio
|
|
|
|
|
See my previous post regarding CArray. Simply create your employees in a CObArray and call the Serialize member function of the CObArray with a valid CArchive. This will alloy you to read and write your array with minimal amount of code.
|
|
|
|
|
bhangie wrote:
// Employee *NewEmp = new Emp ??
I assume you meant Employee *NewEmp = new Employee ?
bhangie wrote:
I want the new employees details in a file .dat it keeps
on creating one employee overriding the previous info.
So do you have something akin to:
for each employee in list
{
open .dat file
write employee info to file
close .dat file
} In other words, after writing all employees to the .dat file, what one employee is in the file: the first one in the list or the last?
bhangie wrote:
Am i using new wrong? or am i missing the hole new
concept totaly
You are using it correctly. However, at this point, there is no way to know if your design is sound.
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
Why does more and more memory being allocated when running following function again and again:
void TestFunc()
{
CTaskData data; // My Own class
CArray<ctaskdata, ctaskdata&=""> arrData;
arrData.Add( data );
}
// Should not all memory be freed?
--------------------
// My Own class
class CTaskData : public CObject
{
DECLARE_SERIAL (CTaskData)
public:
CTaskData() {}
virtual ~CTaskData() {}
CTaskData( const CTaskData ©Data ) {
m_iDays = copyData.m_iDays;
m_oleTimeStart = copyData.m_oleTimeStart;
m_strName = copyData.m_strName;
}
virtual void Serialize(CArchive& ar);
CTaskData& operator=( const CTaskData ©Data ) {
m_iDays = copyData.m_iDays;
m_oleTimeStart = copyData.m_oleTimeStart;
m_strName = copyData.m_strName;
}
public:
CString m_strName;
int m_iDays;
COleDateTime m_oleTimeStart;
};
APe
|
|
|
|
|
Use std::vector instead. Vector is more efficient in memory management.
Sonork 100.41263:Anthony_Yio
|
|
|
|
|
Thanks.
I've had my plans doing that. You convinced me.
APe
|
|
|
|
|
Just a reminder.
One disadvantage of using the vector is that you can't serialize your object in the vector like the way you do it in the CArray or CObArray
Cause vector do not inherit the CObject.
with CArray/CObArray, you could do something like this in your Serialize function of your CDocument class without much effort.
void CYoutDoc::Serialize(CArchive& ar)
{
m_oaYourArray.Serialize(ar);
}
In the code above, each object in oaYourArray is being serialize one by one to CArchive. Of course, provided that the object you store in the oaYourArray has Serialize function overrided. It is almost effortless.
Sonork 100.41263:Anthony_Yio
|
|
|
|
|
OK.
does
m_oaYourArray.Serialize(ar);
work if I use CObject* in the array?
Thanks for your replys.
APe
|
|
|
|
|
No need to be CObject. Just make your object inherit CObject.
eg.
class CYourClass : public CObject
{
....
Serialize(...)
Sonork 100.41263:Anthony_Yio
|
|
|
|
|
I nearly thought if there should bee problems if I used CObject* (pointer) or inherited ones.
APe
|
|
|
|
|
It is difficult for me to explain bit by bit the detail of this but I could recommend you a book.
Try the SAMS publishing book.
"Learning Visual C++ 6.0 in 21 days"
The CArchive tutorial in chap 12. It should clear your doubt.
Although this is a not the best book for learning MFC but it is a good jump start for newbie.
Hope this helps
Sonork 100.41263:Anthony_Yio
|
|
|
|
|
I usually use CObArray which would avoid constant copying of your data and will permit serialization.
<br />
CObArray arrData;<br />
<br />
CTaskData * pData =new CTaskData;<br />
...<br />
arrData.Add(pData);<br />
<br />
...<br />
<br />
for ( int nObj = 0; nObj < arrData.GetSize(); nObj++)<br />
delete arrData[nObj];<br />
<EDIT>I do not mind being voted down but please explain why </EDIT>
|
|
|
|
|
Thanks I try that.
But I still think it's strange....
APe
|
|
|
|
|
d00_ape wrote:
// Should not all memory be freed?
No, not necessarily. Windows' memory manager is a very complicated beast. It does what it does very well, which implies that we don't always know what it is going to do. If you just take it a cursory glance, it would seem that variables/objects going out of scope would automatically decrease your program's memory usage, and increase the amount Windows has to offer. If it was something that simple, the geniuses at Microsoft with multiple PhDs that do nothing but work on the memory manager must've overlooked that! They are going for efficiency, which is not always obvious.
Read the very last section of this article for a good description of what is going on.
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
OK!
Thanks for the link. Also found other interesting things in it.
APe
|
|
|
|
|
Please , help me find the QueryPerformanceFrequency's or QueryPerformanceCounter's Windows NT functions similarity in Linux.
Or suggest the other with high accuracy.
Thanks.
|
|
|
|
|
|
hi,
i've written a program using a formview and several dialogs, mainly created with the ressource-editor of visual studio. the problem is, that for some users the gui is not displayed the right way. i think, they are using a different font or fontsize than i do.
what can i do, to ensure, that all users of the application see the same like i see? do i really have to define a standardfont and attach it to every little cstatic-object? every program i know, does not make such problems, so there must be a way, to prevent such display-errors.
thanks
|
|
|
|
|
namdans wrote:
what can i do, to ensure, that all users of the application see the same like i see?
You can't, nor should you want to. If I have my system set up to use some fancy-dancy font, and your app comes along and uses its own font, I'm not going to be happy. In other words, let the user configure their own system (e.g., font, color, scheme) via Control Panel, and simply respect those settings in your application. Unless you code around this, this happens by default.
namdans wrote:
do i really have to define a standardfont and attach it to every little cstatic-object?
No, this is hardly, if ever, necessary. Unless you are writing a specialized application where fonts are part of the design, let the OS handle them.
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
David,
Do you know how to get access to the windows fonts for using with drawing text on a dc. I want my application to use the system settings but i dont seem to be able to get hold of the correct font. What should i be doing?
Cheers,
Andy.
|
|
|
|
|
I am using the AfxBeginThread, with a global function ThreadProc(LPVOID), i do some background processing ie a while loop is executing infinitely but due to that execution i have to update some controls on the Dialog.
This updation is not occurring rather an error message
comes that u can't modify a C++ class inside the thread
Please can someone tell me what is the problem and the solution...thanks
Ever Welcome...
|
|
|
|