|
code-frog wrote: Well, I couldn't resist
I'm kind of being sarcastic as well. I couldn't resist saying *something* when someone is probably using C style file handling in a C++ program, in the year 2005.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
How about trying to use C99 (ISO/IEC 9899:1999) in a C++ program?!
Maxwell Chen
|
|
|
|
|
Whats wrong with the 'C' FILE aproch even in a C++ program. I did it once when i needed to write u pure ANSCI c++ program ???
codito ergo sum
|
|
|
|
|
BadKarma wrote: Whats wrong with the 'C' FILE aproch even in a C++ program.
Everything. It's very ugly.
BadKarma wrote: I did it once when i needed to write u pure ANSCI c++ program ???
I don't see the correlation. A pure ANSI C++ program would use C++ file handing.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Christian Graus wrote: I don't see the correlation. A pure ANSI C++ program would use C++ file handing.
Which classes should i us;)e then?;)
codito ergo sum
|
|
|
|
|
ifstream/ofstream - iostreams are the c++ file handling class library.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
I am continually surprised by people who think they are C++ programmers because they write thier C code in files that end with .cpp or .cxx. They think a constant is made with #define, they've never even heard of Scott Meyers, etc., etc.
Matt Gerrans
|
|
|
|
|
Yep, the world is full of people who use C++, but have no idea of half the stuff it offers them.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
|
|
How can I convert a wchar_t into an integer.
iTest is the integer var.
wByteBuff is the wchar_t var.
I tried: swprintf(iTest,"%d",wByteBuff);
but i always get the error :error C2665: 'swprintf' : none of the 2 overloads can convert parameter 1 from type 'int'
i also tried with %x,%X,%i,%u,%c but none of this is working.
|
|
|
|
|
char to int is implicit. Is that not true for wchar ?
swprintf takes wide strings, I can't imagine why you're passing an int as the first parameter ?
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
try using the _wtoi function
|
|
|
|
|
thanks, but I searched this so much that I forgot what I wanted at first.
I wanted to convert the character contained in the wchar_t to it's decimal value.
|
|
|
|
|
|
Hi,
To start VC++ basics and concepts where shall i start? Do i need to know win32 appln first (by reading "programming windows" by charles petzold) before MFC???
I would like to learn VC++ in deeper. Could anyone suggest me how ?? and provide me some good books and tutorials???
|
|
|
|
|
The first step is to learn C++ itself, without any Windows stuff. IMO, you should then learn MFC, and finally learn Win32, to gain an understanding of what MFC is taking care of for you. This breaks down what you're learning so you can focus on one bit at a time. Learning Win32 then magically finding you don't need to know it anymore is just too much to bite off at once, IMO.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
After seeing a lot of the IM log managers out there I wanted to create a C++ program that via a command line prompt would copy IM log files into a a buffer or text file. While I get access the space in C:\Doc and Settings\GAIM\logs whatever, I cannot figure out how to open those files/ or write them into a buffer or text file. I am creating the program in Visual Studio for WIndows XP platforms.I know I must be missing a simple windows function call but any help would be greatly appreciated! Thanks
|
|
|
|
|
bobfilar wrote: I cannot figure out how to open those files
Your mean read a text file ? You need to use an ifstream. Read my iostreams articles, or google ifstream for more info.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
well... kinda. After reading you article on iostream modifiers and "deriving your own stream" I understand what you mean, but a for instance in what I am trying to do is this. An IM client, say GAIM, stores logs and user preferences on a .xml file. I am wondering if I can code within my program the ability to enter in my program via the command prompt and have it point towards .xml file, but instead of opening the file to view on my desktop its contents get written into another file, say a text file or whatever you feel like. I too immediately looked at iostream for the project, but was still stuck on the implementation. Thanks for the advice though!
|
|
|
|
|
If the file you're reading is XML, then you want an XML DOM implimentation, such as IXMLDocument, which will allow you to read the XML as XML. In fact, if I were doing this, I'd use XSLT to transform the XML into the text I wanted, then an ofstream to write it back to disk.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
There is picture(IDB_BITMAP1) on the dialog. after I clicked pic that I choosed, then I got pic instantly disappearing. I am trying to figure it out to get pic appear. can you tell me what did I wrong?
void CAssignDlg::OnPaint()
{
CPaintDC dc(this);
CBitmap mybmp;
CPoint org(0,0);
HBITMAP hBitmap;
HANDLE hImageFile;
if(m_bNoPicture)//before choose pic
{
CBitmap mybmp;
mybmp.LoadBitmap(IDB_BITMAP1);
m_Picture.SetBitmap((HBITMAP)mybmp);
}
else)//after chose pic
{
HBITMAP hBit = (HBITMAP)LoadImage( NULL,
"C:\\Test.bmp",
IMAGE_BITMAP,
0,
0,
LR_CREATEDIBSECTION | LR_DEFAULTSIZE | LR_LOADFROMFILE );
CBitmap* b = new CBitmap;
b->Attach(hBit);
m_Picture.SetBitmap(*b);
//DeleteObject(hBit);
}
}
|
|
|
|
|
This is at least a memory leak. Load the bitmap as a member variable, not in your paint handler. You will run out of GDI resources pretty quickly, in fact, that may be what is happening.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
I am little confusing about "load the bitmap as member variable, not in your paint handler". can you explain it little more?
|
|
|
|
|
class CAssignDlg
{
HBITMAP m_Bitmap; <- THIS is a member variable
void CAssignDlg::OnPaint() <- THIS is a paint handler.
{
CPaintDC dc(this);
CBitmap mybmp;
CPoint org(0,0);
HBITMAP hBitmap;
HANDLE hImageFile;
if(m_bNoPicture)//before choose pic
{
CBitmap mybmp;
mybmp.LoadBitmap(IDB_BITMAP1);
m_Picture.SetBitmap((HBITMAP)mybmp);
}
else)//after chose pic
{
HBITMAP hBit = (HBITMAP)LoadImage( NULL,
"C:\\Test.bmp",
IMAGE_BITMAP,
0,
0,
LR_CREATEDIBSECTION | LR_DEFAULTSIZE | LR_LOADFROMFILE ); <- THIS code loads an image EVERY TIME the form gets painted.
CBitmap* b = new CBitmap;
b->Attach(hBit); <- THIS creates a new pointer every time, and because it's not a member variable, you lose it ( you can't ever clean this memory up )
m_Picture.SetBitmap(*b);
//DeleteObject(hBit);
}
}
I would have a CBitmap * in your class, and set it to NULL. Wrap the code to assign the value in a block that checks if the pointer is currently NULL. Delete the pointer in your destructor.
}
Christian Graus - Microsoft MVP - C++
|
|
|
|