|
Thanks for the info.
Well here goes another trip into the ugly tree...
CString RightTrimDouble(double dfInput)
{
CString sTemp="";
sTemp.Format("%#f",dfInput); // Force the decimal
sTemp.TrimRight("0");
sTemp.TrimRight(".");
return sTemp;
}
Isn't it ugly? Not even a mother would be proud of that!
O'well. It happens
-- modified at 12:35 Tuesday 23rd May, 2006
|
|
|
|
|
don't do that, because if you have a pure integer (no decimal digits), you can alterate the value of the number.
see my CString CVisualCalcDlg::RemoveTrailingZeros(const CString& strResult) function to see how i do it...
TOXCCT >>> GEII power
[VisualCalc 3.0 updated ][Flags Beginner's Guide new! ]
|
|
|
|
|
The %#f in the format string always forces the decimal to be placed which prevents that. (At least that's what I intended) I was trying to protect against integer input.
Let me know if I'm still missing something obvious.
Either way, thanks for the heads up.
|
|
|
|
|
What's wrong with std::ostringstream?
CString str;
double mydbl = 0.17000;
std::ostringstream ss;
ss << mydbl;
str = ss.str().c_str();
MessageBox( str);
"What classes are you using ? You shouldn't call stuff if you have no idea what it does" Christian Graus in the C# forum
led mike
|
|
|
|
|
I'm still a C programmer thats been locked in a C/C++ Hybrid mode for quite a while and I haven't fully embraced 90% of what is C++ ish except for OOP of course. I haven't really gotten to know any of the C++ libraries as the C libraries had usually been sufficient (except today).
I keep meaning to learn the C++ standard library and templates and such but my little detour down MFC lane in the late 90's really messed with that intention.
It's embarrassing to say I've never seen "ostringstream" before (I've been a C programmer for 16 years and every day I feel like a newbie and another day behind the rest)
Thanks for the direction!
|
|
|
|
|
No need to be embarrassed, I do not know if anyone else here has been down the same road you are following, but I followed that exact same road. I recommend that you think of a personal project, preferably the development of a template that you can develop on your own at home. You just need to make the requirement that it is written entirely in standard C++ (no Microsoft extensions or dependency allowed), taking full advantage of the STL (Standard Template Library). Just pretend you are back writing code for DOS. I recommend template development because that requires a better understanding of C++, than non-template development.
One last note: MFC messed me up as well, since I was bypassing the basics of C++ and locking myself in that world. Get back to your roots, the way you learned C in the first place.
INTP
"Program testing can be used to show the presence of bugs, but never to show their absence."Edsger Dijkstra
|
|
|
|
|
Hi,
I have to read and write Windows NT data streams in my project. I have successfully read and write Alternate Data stream, Security stream,Encrypted stream, Quota stream, Reparse stream and Object Id stream. But not able to read or write Extended attribute data stream and Property data stream. Can any one tell me how i can read/write these streams in NTFS enviroment.
Touseef Afzal
"I only fail when i give up "
|
|
|
|
|
I'm not much of an MFC/C++ guy but I know C. I'd seen in some forum here, that we can mix MFC with Console apps. I dunno whether he meant console app to be C++ or not!
My qstn is how to use C in an MFC [exe] project. What extra things should I do to mix C inside so that I too can do some MFC stuff and porting some of my progs to GUI?
Thanks
|
|
|
|
|
blacksalt wrote: My qstn is how to use C in an MFC [exe] project
It depends what do you mean by "C". If you simply have source files (with C code) that you want to add to your project, then you can simply add them to the project and call the functions. Basically C++ is just an improvement of C.
Cédric Moonen
Software developer
Charting control
|
|
|
|
|
1. Include any external C source code files in the project, the same as including a C++ file. The compiler knows the difference between the two file types base on the file extension.
2. Enclose the prototypes for the C functions in the header file or anywhere that a C prototype is provided [in a C++ file], using the extern “C” declaration as follows:
extern "C"
{
void prn();
}
3. Now you are set to do what ever you want as far as MFC development is concerned.
There is one other possibility; copying all your C files along with their headers into the project folder and changing the extension to ‘.cpp’. I generally do not recommend this if you have other C programs that depend on the same sources, as it is usually better to avoid having multiple copies of the same sources. Then again doing this makes the sources more specific to the C++ project being developed.
Any way you get the general idea of how it works.
Oh, you will have to change any code that is dependent on user interaction via standard input/output or any other non-Windows method. The difficulty of that depends on how you wrote the original code to begin with.
Good Luck!
INTP
"Program testing can be used to show the presence of bugs, but never to show their absence."Edsger Dijkstra
|
|
|
|
|
OK I tried adding all C and .h files to the MFC project. There are many errors.
I'll change all the printf() calls to Afxmssg type. Now one of the main culprit is directory fns & variables. I think those also need to be replaced with MFC part. With code properly arranged out I'll get back to you.
As of now there are no calls from MFC code to any of the C fns. I understand that this has to be done within externC.
Thanx for the reply.
|
|
|
|
|
This is the first time I have been back since I posted my answer to you, but it appears you get the idea. Please do not use synonyms or Web acronyms when talking about coding, use the complete word so every one knows what you are talking about (assuming fns means function).
During the process I would be surprised if you did not receive many errors. Most of those should be related to I/O, always try to separate the I/O from the code that actually does the work as much as possible. Your ultimate goal is to write a solution (program) that has a back end (which does the work) and a front end (which show it to the user). If you do it right, then the back end will be portable (at least in theory).
INTP
"Program testing can be used to show the presence of bugs, but never to show their absence."Edsger Dijkstra
|
|
|
|
|
Please help me!!! Can any one tell me how to delete a line in text file. Please tell me how to do it in C (not MFC, C++)
Thanks...
If you have faith in the cause and
the means and in God, the hot
Sun will be cool for you.
|
|
|
|
|
You can't. What you have to do is read the file in memory, erase the line and write the complete file back. An alternative is to open a temporary file, write line by line in it (except for the line you want to remove), delete your original file and then rename your new file.
Cédric Moonen
Software developer
Charting control
|
|
|
|
|
I cannot take big data inside memory because I may have 1 Lakh records to be written to the file. I cannot also use temp file because I may to exchange data from original file to temp file alteast 50,000 times.
If you have faith in the cause and
the means and in God, the hot
Sun will be cool for you.
|
|
|
|
|
|
There is no way of doing that.
Mmmh, I think there is problem with your design: if you have to update files so many times, I don't think this is the right choice. Can't you use a database for that ?
What is the purpose of this file exactly ?
Cédric Moonen
Software developer
Charting control
|
|
|
|
|
Requirement is we have to query data from database and modify the recordsets and write the data into the text file.
If you have faith in the cause and
the means and in God, the hot
Sun will be cool for you.
|
|
|
|
|
An optimization is to write the remaining file from the point of the deleted data rather than the entire file.
Bahadur - yar - Jung wrote: I cannot take big data inside memory because I may have 1 Lakh records to be written to the file.
Use buffered IO
"What classes are you using ? You shouldn't call stuff if you have no idea what it does" Christian Graus in the C# forum
led mike
|
|
|
|
|
hi
how can i change the background color of a slider ctrl.
can anybody help me?
thanx
nirmal
|
|
|
|
|
nirmal wrote: how can i change the background color of a slider ctrl.
can anybody help me?
HBRUSH CEttDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
if (pWnd==GetDlgItem(IDC_SLIDER1))
{
hbr=CreateSolidBrush(RGB(123,123,13));
}
return hbr;
} Here IDC_SLIDER1 is the control ID of Slider control.
Knock out 't' from can't,
You can if you think you can
|
|
|
|
|
Is it possible to create in C++ the equivalent of the command window in matlab, i.e. a window ( the command prompt I guess), that would be launched at the beginning of a debbug session. While the debug is paused at the breakpoint, a chosen operation ( say viewing the value of an object) could be invoked on some object ( say "Matrix A")in the current namespace, by typing the corresponding command in that window ( say "View(A)") that would return the entries fo matrix A. One could also think of the computation of the condition number of that matrix, while the debug is stopped at the breakpoint, throught the command "cond(A)".
Any suggestion greatly appreciated
McBridou
-- modified at 8:45 Tuesday 23rd May, 2006
|
|
|
|
|
Hi
How I can draw animation on the desktop window (like Sheep or snow or MSAgent program)?
Thanks
|
|
|
|
|
1)Create a transparent window and draw over it.
2)If you want to draw directly over the desktop you can use GetDesktopWindow()
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
Thank you, but
1) Drawing just one bitmap in transparent window is ok, but second one makes problem
2)it has same problem (redrawing previous area?)
|
|
|
|