|
Christian Graus wrote:
A number of things are missing because it's assumed you'll use the algorithms the STL provides, which it plugs in to
Unfortunately, STL doesn't provide ready-to-use algorithm for string/string replacing in string, a'la CString::Replace(LPCTSTR, LPCTSTR). At least I don't know any - if you found one, let me know
Tomasz Sowinski -- http://www.shooltz.com
- It's for protection - Protection from what? Zee Germans?
|
|
|
|
|
Actually, I think you are right - at work we have a class called CSTring, which mimics the MFC CString and is derived from std::string. I hate it, but I use it when I need Replace....
Christian
come on all you MS suckups, defend your sugar-daddy now. - Chris Losinger - 11/07/2002
|
|
|
|
|
Daniel Lohmann wrote:
I tried hard for about three years to become comfortable with std::string,
Really ? I've only been coding three years. How hard did you try ?
Daniel Lohmann wrote:
I always missed things like GetBuffer()
It's called &string[0].
Daniel Lohmann wrote:
or Format()
Format is ugly - an ostringstream does a much better job, and the framework is extensible.
Daniel Lohmann wrote:
And I like that CString takes only 4 Bytes and you can even reinterperet this 4 Bytes as const char*.
You can do this with c_str().
Daniel Lohmann wrote:
CString is the one and only thing of MFC that really rocks
It is adequate and there are things it does better, but it does not *cane* std::string, they are about on a par.
Christian
come on all you MS suckups, defend your sugar-daddy now. - Chris Losinger - 11/07/2002
|
|
|
|
|
Christian Graus wrote:
Daniel Lohmann wrote:
I always missed things like GetBuffer()
It's called &string[0].
This does not help that much, because the standard does not ensure that the returned buffer is zero terminated
Christian Graus wrote:
Daniel Lohmann wrote:
or Format()
Format is ugly - an ostringstream does a much better job, and the framework is extensible.
Oh yes - I tried this, too. But I found that most times I don't need the extensibility. Complex data types tend to do too much formatting for their output, so that it is only usable for debugging purposes but not for output to the end user. And those ostream concatenations tend to get really long and nearly unreadable:
printf( "Error %d (0x%x) in Module %s Line %d: %s.\n",
dwErrorCode, dwErrorCode, nLine, pszModule, pszMsg );
comes to
cout << "Error " << dwErrorCode << " (0x" << hex << dwErrorCode << ") in Module " << pszModule << "Line " << nLine << ": " << pszMsg << "." << endl;
I doubt that the above is really better to read, to write and especially to maintain.
Christian Graus wrote:
Daniel Lohmann wrote:
And I like that CString takes only 4 Bytes and you can even reinterperet this 4 Bytes as const char*.
You can do this with c_str().
No, you cant. I was not talking about conversion to LPCTSTR. The thing is that the memory layout of a CString instance is the same as for a char*. Thus one could write the following:
CString Text( "Hello World" );
TRACE("%s", Text );
Of course that is bad style, I only want to demonstrate the principle. The point is that it makes a lot of debugging tasks easier if you know that the 4 bytes representing a string point directly to the string buffer it manages - especially if you have to debug release builds...
--
Daniel Lohmann
http://www.losoft.de
|
|
|
|
|
Daniel Lohmann wrote:
the standard does not ensure that the returned buffer is zero terminated
YEs, I've actually noticed that it isn't when using the memory window. But if you want zero terminated, then you're reading, not writing. In that case, c_str() is fine.
Daniel Lohmann wrote:
And those ostream concatenations tend to get really long and nearly unreadable:
printf( "Error %d (0x%x) in Module %s Line %d: %s.\n",
dwErrorCode, dwErrorCode, nLine, pszModule, pszMsg );
comes to
cout << "Error " << dwErrorCode << " (0x" << hex << dwErrorCode << ") in Module " << pszModule << "Line " << nLine << ": " << pszMsg << "." << endl;
I doubt that the above is really better to read, to write and especially to maintain.
You're kidding, right ? How is (0x%x) easy to ready, and not error prone ?
Christian
come on all you MS suckups, defend your sugar-daddy now. - Chris Losinger - 11/07/2002
|
|
|
|
|
Christian Graus wrote:
YEs, I've actually noticed that it isn't when using the memory window. But if you want zero terminated, then you're reading, not writing. In that case, c_str() is fine.
I frequently need to read and write the same buffer. (I use a library that does a lot of in-place modifications of string buffers.)
Christian Graus wrote:
You're kidding, right ? How is (0x%x) easy to ready, and not error prone ?
I find it easy to read
Of course, one has to know the printf format types and flags, but if you know them it is a very compact representation of what you intend to do...
Sometimes I got the feeling I am a bit old-fashioned.
(Actually the truth is, that I have learned C++ IO before I learned how to do it in C. Believe it or not: I was used to use ostream for quite a long time and then I moved to printf )
--
Daniel Lohmann
http://www.losoft.de
|
|
|
|
|
Check out _splitpath() .
CString strPath = "C\\I386\\IAS.MDB";
char* pFullPath = strPath.GetBuffer (0);
_splitpath (pFullPath, ...);
strPath.ReleaseBuffer();
I'm working on releasing my FileSystem class to CP, which will make stuff like this easy to do.
Btw, have you become "nss" now?
/ravi
Let's put "civil" back into "civilization"
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
Nope nss because its my home account. I wanted email to come here while I'm here, and you have to have another identity it appears for a different email(my experimentation). Thanks for that very interesting bit of code. Guess you're back now that the place has been cleaned up by the housekeeper ....
|
|
|
|
|
She spends 2-3 hours at my place (I'm a neat freak so it's easy to clean), but I spent most of the day at the bookstore and in search of food. Gonna lull myself to sleep with Petzold's C# tome.
I really should start posting articles again. I have a bunch of GUI helper code that would make the list control gymnastics you alluded to easy to do. Plus stuff for getting and validating edit controls, easily setting bunches of radio buttons, etc, etc. Stuff I got tired of duplicating in each project.
I'm going to crash now because I'm soooo sleepy. G'night!
/ravi
Let's put "civil" back into "civilization"
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
...or alternatively you could use the Path functions in SHLWAPI. While _splitpath does this job, the Path ones will do some more difficult and tricky ones.
Stuart Dootson
'Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p'
|
|
|
|
|
|
Thank you very much indeed!
ns
|
|
|
|
|
I have created a CConBttn Class with a CButton base class...
On the "OnKeyDown" event, im trying to add text in to a modal dialog.
Is this possible??
if so... HOW!!!
thanx in advance.
Scott
|
|
|
|
|
If your dialog is modal, then your keydown event will not be caught if it is not within the dialog in question.
Christian
come on all you MS suckups, defend your sugar-daddy now. - Chris Losinger - 11/07/2002
|
|
|
|
|
Ugh, that is soooo hard to read! Your name sounds familiar. Are you related to Mark Perham, the guy who wrote that cool Explorer look-alike way back when?
(Sorry, I didn't end up answering your question).
/ravi
Let's put "civil" back into "civilization"
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
I've got an SDI app with a CFormView in the main frame when it initializes. That works fine. I'd like to be able to toggle on/off that view to an empty client view via a menu command.
The MSDN docs say you can only have one view at a time in SDI but doesn't give any examples on how to remove the current view, create a new one and do I need a new frame window to do it?
I've tried to switch to a simple text view....but, I'm still trying to learn this doc/view stuff.
appPtr->pDocTemplate->RemoveDocument(GetActiveDocument());
delete appPtr->pDocTemplate;
appPtr->pDocTemplate = new CSingleDocTemplate(IDR_TEXTTYPE,
RUNTIME_CLASS(CTest3Doc),
RUNTIME_CLASS(CMainFrame),
RUNTIME_CLASS(CTextView));
appPtr->AddDocTemplate(appPtr->pDocTemplate);
|
|
|
|
|
|
Thanks. I found something here. D-OH-H-H-H!!!! I Should have checked first. Anyways, in case anyone else want to know:
http://www.codeproject.com/docview/replacingview.asp
http://www.codeproject.com/docview/switchingviews.asp
|
|
|
|
|
I Read the article http://www.codeproject.com/useritems/asyncwininet.asp;
and write the code like 'asyncdemo' which from msdn:
http://msdn.microsoft.com/downloads/samples/internet/default.asp?url=/downloads/samples/internet/networking/asyncdemo/default.asp
but I have a question
when I call InternetQueryDataAvailable() ,it return ERROR_IO_PENDING
then I will recieve a callback status :INTERNET_STATUS_REQUEST_COMPLETE
and the LPINTERNET_ASYNC_RESULT (lpvStatusInformation)->dwError!=0,
the download incorrect.
what's the matter???
the 'asyncdemo' alse download file incorrect
who have the source code of asynchronous download
thanks very much
|
|
|
|
|
I am interested in making a window similar to a start bar but creating it at the top of the desktop and having it so that when a window is maximized it won't cover over the window I have created (instead all windows) will think that the bottom of my window is the top of the screen.
I know this can be done but I don't even know what it is called. If anyone could even tell me what this is called or point me in the right direction it would be greatly appreciated.
Thanks
|
|
|
|
|
Check out the SHAppBarMessage API. I've been meaning to right my first CP article on this - I promise I will get round to it as soon as I have moved house (about a week to 10 days ish, if you can wait that long)
Dylan Kenneally
London, UK
|
|
|
|
|
After creation of ur window, use SetWindowPos(...) with HWND_TOPMOST property for the hWndInsertAfter parameter. This will ensure that your application maintains its topmost position even when it is deactivated, ie other applications are having focus.
|
|
|
|
|
Hello,
I'm trying to use TextOut() to put a string to a window, but when I put the \n or \r\n in the CString.Format(), they print as black-boxes, not linefeeds. My intent is to get one CString with linefeeds to print to the screen.
Any ideas? Thanks!
JennyP
|
|
|
|
|
|
Golly... that seems like a lot of work to keep track of the text positioning! What about word processors? Do they keep maps of each line of text and its position? I would assume this is available in some control....?
thanks! JP
JennyP
|
|
|
|