|
Nemanja Trifunovic wrote:
Hey! The guy is coming from VB. Are you going to make him afraid of C++?
VB and C I thought he said. Admittedly the sample code is more complex than it needed to be in order to make the point ( it's a copy & paste from an earlier question ), but from memory the MFC classes for file IO use the shift operators as well, so why not point someone to the proper way to do things ?
Christian
I have come to clean zee pooollll. - Michael Martin Dec 30, 2001
Picture the daffodil. And while you do that, I'll be over here going through your stuff.
|
|
|
|
|
Christian Graus wrote:
VB and C I thought he said.
Yes, he said, but if he really knew C, he would have simply used the lucy's solution (fopen).
I vote pro drink
|
|
|
|
|
Nemanja Trifunovic wrote:
Yes, he said, but if he really knew C, he would have simply used the lucy's solution (fopen).
Actually, you're right, and that had occured to me when I read lucy's response, but then I saw Chris' MFC reliant post, so I felt obliged to defend the standard (which IMO equates to 'proper') way of doing things.
Christian
I have come to clean zee pooollll. - Michael Martin Dec 30, 2001
Picture the daffodil. And while you do that, I'll be over here going through your stuff.
|
|
|
|
|
CG
You sure are an STL warrior warring against the ruling MFCians.
Nish
Sonork ID 100.9786 voidmain
www.busterboy.org
If you don't find me on CP, I'll be at Bob's HungOut
|
|
|
|
|
Nish [BusterBoy] wrote:
You sure are an STL warrior warring against the ruling MFCians.
And proud of it. Bring them on.
Christian
I have come to clean zee pooollll. - Michael Martin Dec 30, 2001
Picture the daffodil. And while you do that, I'll be over here going through your stuff.
|
|
|
|
|
Look up CFile in MSDN.
Click here and use the menu on the left side to navigate thought the members functions etc.
Sprudling
|
|
|
|
|
What does CFile do that IOStreams do not ?
Christian
I have come to clean zee pooollll. - Michael Martin Dec 30, 2001
Picture the daffodil. And while you do that, I'll be over here going through your stuff.
|
|
|
|
|
What does IOStreams do that fopen etc doesn't?
Tim Smith
Descartes Systems Sciences, Inc.
|
|
|
|
|
I'm not sure, but let me hazard some guesses.
IOStreams are C++ based, and a file stream will always close the file in it's destructor, even if an exception is raised, as soon is it goes out of scope.
IOStreams can be extended to allow one step reading/writing of custom file types, as well as custom modifiers that need only be written once and work with every type to be streamed.
Once the code is written, output can be streamed to any other stream type ( the console, a custom stream type, etc. ), simply by changing the type of the stream, all the other code will remain valid.
Christian
I have come to clean zee pooollll. - Michael Martin Dec 30, 2001
Picture the daffodil. And while you do that, I'll be over here going through your stuff.
|
|
|
|
|
I just thought that since he's using MFC he might as well use CFile.
Sprudling
|
|
|
|
|
I just thought that since he's using MFC he might as well use CFile.
Fair enough. I thought so long as he's reading a file he may as well learn the best way to do it. I was asking seriously, because I didn't know if there actually is some reason one might choose CFile beyond sticking with MFC.
Christian
I have come to clean zee pooollll. - Michael Martin Dec 30, 2001
Picture the daffodil. And while you do that, I'll be over here going through your stuff.
|
|
|
|
|
Thanks for all the help. I knew it should not be that hard.
|
|
|
|
|
Here would be the basics to read a file in C++:
#include < fstream.h >
void main()
{
//File Stream Object
fstream DataFile;
char FileName[81];
cout << "Enter the name of the file you wish to open\n";
cin.getline(FileName, 81);
DataFile.open(FileName, ios::out);
}
Nick Parker
|
|
|
|
|
i don't understand why the insertitem function is good and the text doesn't appear!!
void CMyListView::OnInitialUpdate()
{
CListView::OnInitialUpdate();
ModifyStyle(0, LVS_REPORT,0);
// this code only works for a report-mode list view
//ASSERT(GetStyle() & LVS_REPORT);
// Gain a reference to the list control itself
CListCtrl& theCtrl = GetListCtrl();
// Insert a column. This override is the most convenient.
theCtrl.InsertColumn(0, _T("Names"), LVCFMT_CENTER);
// The other InsertColumn() override requires an initialized
// LVCOLUMN structure.
LVCOLUMN col;
col.mask = LVCF_FMT | LVCF_TEXT;
col.pszText = _T("Version");
col.fmt = LVCFMT_CENTER;
theCtrl.InsertColumn(1, &col);
theCtrl.InsertColumn(2,"Description",LVCFMT_CENTER);
// Set reasonable widths for our columns
theCtrl.SetColumnWidth(0, 200);
theCtrl.SetColumnWidth(1, 100);
theCtrl.SetColumnWidth(2, 100);
GetListCtrl().InsertItem(0, "First row");
}
GetListCtrl().InsertItem(0, "First row") is good but the text doesn't appear!!
Help me, please
PS: LVS_TYPEMASK == LVS_LIST only Michael Dunn. It is not that
|
|
|
|
|
|
I use this code in my view class (according to Christian Graus articles about GDI+)
using namespace Gdiplus;
Graphics graphics(pDC->m_hDC);
Pen pen(Color(255,234,0,123));
int y = 0;
for (int x = 0; x <= 250; x += 30)
{
graphics.DrawLine(&pen, x, 0, 0, y);
graphics.DrawLine(&pen, x, 250, 250, y);
graphics.DrawLine(&pen, y, 0, 250, x);
graphics.DrawLine(&pen, y, 250, 0, x);
y += 30;
}
When I run the application nothing appear in client area,but after I minimiza and maximiza framework then I can see lines
Does anybody know the reason?
Thanks
Mazy
Don't Marry a Person You Can Live With...
Marry Someone You Can Not Live Without
|
|
|
|
|
Where are you doing the drawing ?
Christian
I have come to clean zee pooollll. - Michael Martin Dec 30, 2001
Picture the daffodil. And while you do that, I'll be over here going through your stuff.
|
|
|
|
|
View class,OnDraw()
Mazy
Don't Marry a Person You Can Live With...
Marry Someone You Can Not Live Without
|
|
|
|
|
Mazdak wrote:
View class,OnDraw()
Well, that's correct. Put in a break point to see if it gets called on startup, because the fact that forcing WM_PAINT by minimise and maximising the window draws OK means the code is working fine.
Christian
I have come to clean zee pooollll. - Michael Martin Dec 30, 2001
Picture the daffodil. And while you do that, I'll be over here going through your stuff.
|
|
|
|
|
I put breakpoint and somrthing wrong with this line:
Graphics graphics(pDC->m_hDC);
pDC->m_hDC -------->
- m_hDC 0x01010053 HDC__ *
unused CXX0030: Error: expression cannot be evaluated int
m_hDC can not evaluated
Mazy
Don't Marry a Person You Can Live With...
Marry Someone You Can Not Live Without
|
|
|
|
|
Sometimes the debug window says that, but the variable is OK. Or was pDC NULL ?
Anyhow, try dereferencing pDC instead of refering to m_hDC, because operator HDC is defined for CDC.
Christian
I have come to clean zee pooollll. - Michael Martin Dec 30, 2001
Picture the daffodil. And while you do that, I'll be over here going through your stuff.
|
|
|
|
|
Sorry for bothering you but would you please give me sample,I don't know how to do that?
Mazy
Don't Marry a Person You Can Live With...
Marry Someone You Can Not Live Without
|
|
|
|
|
No bother at all. pDC is a *pointer* to a CDC, which is why you use a -> instead of a . to access it's members. A class can define an operator for a type, so that if a class is passed into a function that is looking for a different type, that type is returned. For example, CPoint wraps a POINT, and also defines operator POINT, so the underlying POINT is returned to functions that require it.
This will only work if you have an object, not a pointer. The way to turn a pointer into an object is to put a * in front of it. For example, if you had a CPoint * called pPoint, you could do this:
CPoint pt = *pPoint;
In the same way, you can do this
Graphics graphics(*pDC);
instead of
Graphics graphics (pDC->m_hDC);
Christian
I have come to clean zee pooollll. - Michael Martin Dec 30, 2001
Picture the daffodil. And while you do that, I'll be over here going through your stuff.
|
|
|
|
|
AHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH
I just want to hit my haed to the wall.
Still the same porblem
AHHHHHHHHHHHHHHHHHHHHHHHHHHHH
Mazy
Don't Marry a Person You Can Live With...
Marry Someone You Can Not Live Without
|
|
|
|
|
Did you check in the debugger if pDC is a valid object, or if it is 0 ?
Christian
I have come to clean zee pooollll. - Michael Martin Dec 30, 2001
Picture the daffodil. And while you do that, I'll be over here going through your stuff.
|
|
|
|
|