|
You can use the watch window.
BTW: come to #CodeProject on DalNet (mIRC)
|
|
|
|
|
Hi,
I want to format a flot into a string rounded to three digits.
I thought the code, should work.
double dtest = 10.329;
char buffer[255];
wsprintf(buffer,"%10.2f",dtest);
MessageBox(buffer);
Cheers
Rich
|
|
|
|
|
wsprintf(buffer,"%.3f",dtest);
will round it to three digits past the decimal point.
Christian
After all, there's nothing wrong with an elite as long as I'm allowed to be part of it!! - Mike Burston Oct 23, 2001
|
|
|
|
|
Unfortunately, wsprintf (part of Win32 API) doesn't accept %f, %g or %e. sprintf from stdio.h will do the job - it recognizes escape sequences for floating point.
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
You can also use the standard library "stringstream" class to format a std::string, like this :
double dTest = 10.329
std::stringstream ss;
ss << setiosflags( ios::fixed ) << setprecision(3) << dTest;
cout << ss.str();
std::stringstream ss;
ss << setiosflags( ios::fixed ) << setprecision(2) << dTest;
cout << ss.str();
std::stringstream ss;
ss << setiosflags( ios::fixed ) << setprecision(1) << dTest;
cout << ss.str();
This looks like more code/work for such a simple example, but often this ends up saving you code if you then have to use the 'string' in other functions.
The standard library stringstream also has the advantage that you can extend it in two ways:
(a) writing your own manipulators (for example, you can write a 'percent' manipulator that converts a value into a percentage as it is written to the output;
(b) you can write inserters/extractors for user defined types, so that you can use the same syntax to write your own types as you do for the 'built in' types like double.
-----------------------
The sermon on the mount...
Man 1 : Hear that? Blessed are the greek.
Man 2 : The greek?
Man 1 : Well apparently, he's going to inherit the earth.
Man 2 : Did anyone catch his name?
|
|
|
|
|
Dear sir,
I met a strange probelm when I am trying to program my first
MFC extended DLl. That is, I need to use STL in my DLL and
I define some date type such as:
typedef CArray<char,char> CStatusArray;
typedef CArray<int,int> CIndexArray;
But When I compile the file, I got
error C2143: syntax error : missing ';' before '<'
error C2143: syntax error : missing ';' before '<'
warning C4091: 'typedef ' : ignored on left of 'int' when no variable is declared
I know this is related to the DLL programming itself since the error is not
incurred in my MFC exe project. But I am new to DLL programming. So I am posting this to get your help. Thank you very much and any suggestion is welcome.
Best regards,
Cheng LEI
|
|
|
|
|
You're not using STL, you're using the Microsoft container classes. A CArray needs to have two templated arguments to tell it what to contain ( STL containers need one ). You probably *should* use STL, but that is another story.
The problem is not the typedef, but the fact that you probably have not provided the template arguments either in the typedef or the instances you use your typedefed names. Wthout providing the template arguments in the typedef, I can't see any reason for it myself. I never bother with typedefs at all, but they can make code more readable for people who are not familiar with templates or (in my case) STL.
Christian
After all, there's nothing wrong with an elite as long as I'm allowed to be part of it!! - Mike Burston Oct 23, 2001
|
|
|
|
|
Dear Christian and Michael,
Thank you for your helpful suggestion. I added #include "afxtempl.h" as
Michael said and there is no more errors. The original errors are not due to STL. Very sorry for this. In fact, there are some parts using STL in my code
such as
struct TrackedFeature {
CvPoint2D32f m_cvPoint;
int m_videoframe_index;
};
typedef std::list<trackedfeature> CvFeaturesList;
typedef CvFeaturesList::iterator CvFeaturesList_It;
I made a mistake to think the error is from STL. I am sorry, STL.
Now, I have another question, maybe caused by my not-so-good programming
skills. That is, I want to make my View and Doc class in a "MFC exe " project as a DLL to be used by other projects. But in the code, I need to get the
point of the "Application" (by AfxGetApp()). Since there are some project-specific memebers to be used in the class of "***App", such as a point to
another view class, it makes me unable to visit such members by just geting
a CWinApp using AfxGetApp(). What I am wondering is how I can get around with this. I think this problem is completely caused by my bad programming way.
But there is no much time left, so I hope no much modification needed.
I don't know if I said my question clearly. Wish to get your further suggestions. Anyway, thank you very much for your help on my last problem
and I will try to solve the new problem myself independently. I should not
always bother others with some maybe too trival questions But it's better
if I could get suggestions from you, the code gurus
Thank you very much again.
Best regards,
Cheng LEI
|
|
|
|
|
Cast the return value of AfxGetApp() to your CWinApp-derived type:
CMyApp* pMyapp = (CMyApp*) AfxGetApp(); A word of caution though, if you rely on this in your DLL, then you must make an MFC regular DLL, not an MFC extension DLL. An extension DLL shares the CWinApp object of the EXE, whereas a regular DLL has its own CWinApp object.
--Mike--
http://home.inreach.com/mdunn/
This posting is provided "as was" with no warranties, guarantees, lotteries, or any of those little bags of peanuts you get on planes. You assume all risk for crossing the street without holding mommy's hand. © 2001 Mike's Classy Software. Member FDIC. If rash develops, discontinue use.
your with and
|
|
|
|
|
Dear Sir,
So as you said, in my extension DLL, I should avoid using the App class.
It's realy bad and I will make corresponding modifications. Hope I am luckyenough to finish it in time
By the way, I visited your homepage and found a lot of useful stuff.
You self-introduction hoempage is funny
Thank you again!
Best regards,
Cheng LEI
|
|
|
|
|
hee, thanks Good luck with the project.
--Mike--
http://home.inreach.com/mdunn/
This posting is provided "as was" with no warranties, guarantees, lotteries, or any of those little bags of peanuts you get on planes. You assume all risk for crossing the street without holding mommy's hand. © 2001 Mike's Classy Software. Member FDIC. If rash develops, discontinue use.
your with and
|
|
|
|
|
I thought that the OP wanted a pointer to the EXE's CWinApp object? And shouldn't he in that case use an extension DLL for the very same reason?
I must be missing something....
Cheers
Steen.
"To claim that computer games influence children is rediculous. If Pacman had influenced children born in the 80'ies we would see a lot of youngsters running around in dark rooms eating pills while listening to monotonous music"
|
|
|
|
|
He had an EXE and put member variables in the CWinApp-derived object. He wanted to keep that same system when he moved the code into a DLL.
--Mike--
http://home.inreach.com/mdunn/
This posting is provided "as was" with no warranties, guarantees, lotteries, or any of those little bags of peanuts you get on planes. You assume all risk for crossing the street without holding mommy's hand. © 2001 Mike's Classy Software. Member FDIC. If rash develops, discontinue use.
your with and
|
|
|
|
|
Ah, I see. I just read that he wanted to move the view and doc classes to a DLL. I kinnda figured that since the frame wasn't moved into the DLL then the data should stay in the EXE CWinApp. But I missed the "to be used in other projects" part. This would imply that the data in CWinApp belong to the view/doc classes and not to the CWinApp. So shouldn't it be put in either DLL static data storage or in document members?
Cheers
Steen.
"To claim that computer games influence children is rediculous. If Pacman had influenced children born in the 80'ies we would see a lot of youngsters running around in dark rooms eating pills while listening to monotonous music"
|
|
|
|
|
It looks like the compiler's erroring at the "CArray" part. Have you #included "afxtempl.h" ?
--Mike--
http://home.inreach.com/mdunn/
This posting is provided "as was" with no warranties, guarantees, lotteries, or any of those little bags of peanuts you get on planes. You assume all risk for crossing the street without holding mommy's hand. © 2001 Mike's Classy Software. Member FDIC. If rash develops, discontinue use.
your with and
|
|
|
|
|
I just realised, you probably typed the < and >, but it got removed because it was parsed as a HTML tag. In that case, check out Michaels suggestion, but you're still not using STL.
Christian
After all, there's nothing wrong with an elite as long as I'm allowed to be part of it!! - Mike Burston Oct 23, 2001
|
|
|
|
|
I have created 2 toolbars below the menu bar at the top of the window as usual.
They are dockable.
However, they appear in 2 separate rows and are too short. I want them to be in a row.
How to arrange them into the same row such that the 2nd one is on the right of the 1st one?
thanks
|
|
|
|
|
The CGSToolbar class on this site has this method
void CGSToolbar::DockBarNextTo(CControlBar* pDockedBar, UINT nDockBarID)
{
ASSERT_VALID(pDockedBar);
CFrameWnd* pFrame = pDockedBar->GetDockingFrame();
pFrame->RecalcLayout();
CRect rect;
pDockedBar->GetWindowRect(&rect);
rect.OffsetRect(1,1);
pFrame->DockControlBar(this,nDockBarID,&rect);
}
I originally had it as an external function, so it works that way, too.
Christian
After all, there's nothing wrong with an elite as long as I'm allowed to be part of it!! - Mike Burston Oct 23, 2001
|
|
|
|
|
Sirs,
until now I have not used any databases, I just did what any underdeveloped programmer in the stoneage must also have done, namely storing data in house made text files, and reading them from my app.
Now that the future has begun I decided to go with it, and I am spiritually prepared to learn.
But there are so many of abbreviations like ADO, DAO, ODBC, SQL etc. that I am pretty confused which way to go so that I can learn something useful and on the other hand not to have to deal with the whole universe at once.
My data mainly comes from charts, and different engineering databases which rarely have thousands of elements rather less. On the user side I also wanna avoid special requirements, at most MS Office.
Could you please share your ideas as to where to start?
Thank you.
Bunburry
Experience is of no ethical value. It is merely the name men give to their mistakes.(O.Wilde)
|
|
|
|
|
I find ADO to best the best option nowadays. It's very simple to get started with and there are plenty of examples in MSDN and the Platform SDK. ADO is a wrapper for ODBC/OLEDB and is probably the best place to start with databases. It can connect to pretty much any database from Access to SQL to Oracle providing you have the latest version MDAC installed.
The thing I like about ADO is that I can pretty much take the same code from C++ to ASP to Visual Basic without too many headaches.
Michael
|
|
|
|
|
Micheal, i'm developing an MFC app that will use a database for primary storage. What special requirments would ADO have? I need to be able to set the app up relitavely easily on other machines once finished. Also, is it easier to grasp than DAO?
ARGH! My head hurts... too many TLA's.... :
---
"Transmit in all known frequencies and in all known langauges, including Welsh."
|
|
|
|
|
ADO requires MDAC to be installed. This comes with Office but is a simple download from Microsoft. I find ADO easier to use than DAO but I haven't used DAO in 4 years.
I use ADO in MFC apps, using one of the ADO wrapper classes found on CodeProject. Download some of the ADO classes here on CodeProject and compare them to your DAO code.
Michael
|
|
|
|
|
Guys I Used DAO for years, but when I Knew ADO I said GUAU. Is for that I made the ADO Classes equal to DAO Classes, for made easy to use ADO for the programmers that want to learn ADO....
Best Regards....
Chau!!!
Carlos Antollini.
|
|
|
|
|
I too have come from the text file storage area, but i'm working on a project which is going to require large amounts of data (including archived data), so holding everything in arrays is a bit stupid...
I'm currently learning DAO, which is a framework for interfacing with the MS Access engine (called the ket database engine). SQL (Structured Query Language) is the langauge you'll use to query data (try the SQL view in MS access once you've constructed a simple query to view the code). I don't think DAO would suit you much since you siad you want to avoid special requirements - DAO involves setting up a database using MS Access beforehand. ODBC is perhaps the way forward for you.
I'm sure you'll have some helpful replies, i'm not really that experienced with databases as of yet.
---
"Transmit in all known frequencies and in all known langauges, including Welsh."
|
|
|
|
|
The best one to learn is ADO because it allows you to specify the database location at runtime without playing with ODBC. Also, ADOX allows you to create your own databases from scratch.
ADO does tend to bite you in the bum a lot, for example, I found out the hard way that calling MoveFirst() on a recordset with no records crashes pretty damn hard. You might like to search this forum for ADO, I know Hazi and myself have both asked a lot of questions here to get over the initial learning hump and you'll probably save yourself some hassle. Other than that, obviously keep asking questions as you learn.
Christian
After all, there's nothing wrong with an elite as long as I'm allowed to be part of it!! - Mike Burston Oct 23, 2001
|
|
|
|
|