|
If the edit control is on a dialog box, select the styles property tab in the resource editor and check number. This only applies to integer values though and not floating point or doubles values.
If you need to validate that the contents will only be values of the form "00.00", then you will need to derive you own class from the edit control and override entry validation. In this case I sugest a search of codeproject and its' afiliates to find articles on overriding the edit control, who knows may be someone has already solved the problem for you.
INTP
|
|
|
|
|
If you only want to use integers then the previously mentioned solution is definitely best. However if you want to use floating point numbers then you need create your own class derived from CEdit. You then must overload one function..the OnChar() function. This is called when the WM_CHAR message is passeg to your edit control. In the OnChar() function put the following..
void CNewEdit::OnChar(UINT nChar,UINT nRepCnt,UINT nFlags)
{
// Ascii character for 0-9 is 48 to 57 inclusive
//Allows num characters and the backspace and delete chars
if(((nChar >= 48)&&(nChar <= 57))
||(nChar == 127)||(nChar == 8))
{
CEdit::OnChar(nChar, nRepCnt, nFlags);
}
// only needed if floating point numbers being used.
// 46 is ascii code for '.'
if(nChar == 46)
{
// Get the existing text
char line[100];
LPTSTR buffer = line;
this->GetLine(0,buffer);
CString str = line;
// check if '.' is already present
if(str.Find('.') == -1)
{
int lineLen = this->LineLength();
// if no numbers already put a zero first
if(lineLen == 0)
{
this->SetSel(0,0);
this->ReplaceSel("0.");
}
else CEdit::OnChar(nChar, nRepCnt, nFlags);
}
}
}
its not perfect code but it does the job fine.
Then just add an edit control to your dialog and define a member variable(control) for your edit and it should work fine.
|
|
|
|
|
Thanks for the replies folks. It's put me on the right track.
- monrobot13
|
|
|
|
|
I have run into a strange memory overrun problem.
Note: The following example code may not reproduce the problem,
they are for illustation only.
Note: There are no compiler errors generated by either of the following
2 cases.
CASE 1: TEST_CTESTCLASS define in Test.cpp file.
Bounds Checker reported an overrun, when my application existed.
The VC++ 6.0 debugger does not show m_pTestClass1 as being a
member of CTestClass2 and yet I can still set it to NULL, with no
complants. If I do not set it to NULL, there is no overrun reported.
Note: The variable type CTestClass2 is declared as a member of a
CScrollView derived class. If the member is removed and made global,
then the overrun is not reported.
#ifndef __TEST_H__
#define __TEST_H__
class CTestClass1
{
int m_donothing;
public:
CTestClass() : m_donothing(0) {}
};
class CTestClass2
{
#ifdef TEST_CTESTCLASS
CTestClass1* m_pTestClass1;
#endif
public:
CTestClass2();
}
#endif // __TEST_H__
#include "stdafx.h"
#define TEST_CTESTCLASS
#include "Test.h"
CTestClass2::CTestClass2()
{
#ifdef TEST_CTESTCLASS
m_pTestClass1 = NULL;
#endif
}
CASE 2: TEST_CTESTCLASS define in Test.h file.
In case 2 below Bounds Checker reports no overruns and the VC++ 6.0
debugger shows m_pTestClass1 as being a member of CTestClass2.
#ifndef __TEST_H__
#define __TEST_H__
#define TEST_CTESTCLASS
class CTestClass1
{
int m_donothing;
public:
CTestClass() : m_donothing(0) {}
};
class CTestClass2
{
#ifdef TEST_CTESTCLASS
CTestClass1* m_pTestClass1;
#endif
public:
CTestClass2();
}
#endif // __TEST_H__
#include "stdafx.h"
#include "Test.h"
CTestClass2::CTestClass2()
{
#ifdef TEST_CTESTCLASS
m_pTestClass1 = NULL;
#endif
}
Does anyone have a clue as to what is causing this problem?
Thanks for any hints, etc..., that you can give me.
INTP
|
|
|
|
|
A couple of things I noticed:
- Shouldn't the compiler complain that definition for CTestClass2 is not terminated by a ; ?
- In general its bad mojo to put #ifdef s in the middle of a class definition. Change your compiler directives and you have a class with the same name but different addresses. You'll get random memory access violations with this type of object.
In fact the second thing is what is going on. The first example you only enable the directive when you compile just that file. In essence, what you defined and what you compiled don't match and hence the memory violation. Any other file that includes this will believe the object is defined the wrong way. The second one is "foolproof" since any inclusion will enable the directive.
As I said, its bad mojo to have precompiler directives in the middle of your definition. You really should avoid it to avoid problems just like this.
|
|
|
|
|
Thanks!
My brain must have been out to lunch! As soon as I read your answer it all became clear. Why I did not realize this for myself, I do not know.
Tom Larsen wrote:
- Shouldn't the compiler complain that definition for CTestClass2 is not terminated by a ; ?
:-DSorry about that! It was just an illustration of the problem, not the actual code that created it.
Tom Larsen wrote:
As I said, its bad mojo to have precompiler directives in the middle of your definition. You really should avoid it to avoid problems just like this.
Normaly I do not do this sort of thing. In this case, however, the code used to generate some data for analisys required direct access to member variables to produce the required charts.
I do not like the solution I came up with and will try to find a better way.
Thanks again!
INTP
|
|
|
|
|
What I recommend in cases like this is to wrap the entire class definition for both versions in #ifdef and then make typedef the type to the name you need. It is easier to manage a typedef than it is to manage and entire class that has its internal possibly changing. It also makes problems easier to track down because the code won't compile or link if the pre-compile directives are out of wack.
|
|
|
|
|
I am looking for a sample of adding "Start parameters" to a window service.
|
|
|
|
|
Services actually process 2 command lines.
(1) There's the old command line that you specify upon starting the program. A full command line that the service control manager uses to start your service.
(2) "Start Parameters" which the Service control manager passes to your service's dispatcher (the one you specify via StartServiceCtrlDispatcher() ). The "start parameters" are the ones that you see (and you can 'set') in the Services control panel.
I only use #1 -- which is parseable in the old fashioned argc/argv way. I don't see much use for the "start parameters" way....
Does this help? or confuse?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br />
Peter Weyzen<br />
Staff Engineer<br />
<A HREF="http://www.santacruznetworks.com">Santa Cruz Networks</A>
|
|
|
|
|
Hi everyone,
I have a class like this:
class CFoo
{
public:
CFoo();
~CFoo();
BOOL SortByName();
protected:
std::vector<CRec*> m_Recs;
private:
struct NameComparer
{
bool operator()(const CRec* A,const CRec* B)
{
return ((A->m_strName) < (B->m_strName));
}
};
};
BOOL CFoo::SortByName()
{
std::stable_sort(m_Recs.begin(), m_Recs.end(), NameComparer());
return TRUE;
}
Now, basically, I am trying to properly write and use a predicate function (I think that's what they're called; please correct me if I'm wrong) in the context of calling std::stable_sort (and just std::sort for that matter). There are many helpful examples around, but they don't seem to cover dealing with a non-trivial class (or if they do I haven't 'gotten it' yet).
In my case, I want to be able to sort the vector of CRec 's according to several different CRec member variables (different CString s, int s, double s, etc.). My questions are:
1) Did I use proper coding techniques to solve the problem as I have shown here?
2) Is it the case that I need to add additional struct s under the private section of CFoo for each comparison CFoo member function I want to write (with the comparisons applied to the std::vector m_Recs and based on the CRec members themselves actually)?
3) Why do I need to wrap the comparison functions in a struct? How does that fact relate to operator() , etc.?
Thank you all again for reading and giving any advice,
Best,
Eric
|
|
|
|
|
It's usually best to wait a few days before posting the same question again. And, surprisingly, an answer may not be know by the current CP members!
A rich person is not the one who has the most, but the one that needs the least.
|
|
|
|
|
Hi David,
I know. And I knew that I risked being rude, but I figured that since it was late when I left the post it might not get seen by many, so I took the chance.
Anyhow, I take your point and I appreciate your feedback.
Best,
Eric
|
|
|
|
|
Cloaca wrote:
And I knew that I risked being rude...
It was being rude per se, it's just that with timezone differences and the like, it may take two full days before the post has been digested by everyone.
A rich person is not the one who has the most, but the one that needs the least.
|
|
|
|
|
You are right David. That's a good point also. I should male it a policy not to repost for a week or so I guess.
Thanks again,
Eric
|
|
|
|
|
In sum, your solution is okay. In general, check out these books for in-depth explanation on STL.
The C++ Standard Library : A Tutorial and Reference by Nicolai M. Josuttis
Effective STL: 50 Specific Ways to Improve Your Use of the Standard Template Library by Scott Meyers
Kuphryn
|
|
|
|
|
Hi Kuphryn,
I will grab these two references that you noted. And thanks for the comment on the way I'm doing it now, I appreciate your input!
Thanks very much,
Eric
|
|
|
|
|
Cloaca wrote:
Is it the case that I need to add additional structs under the private section of CFoo for each comparison CFoo member function I want to write [...]?
Yes. AFAIK every comparison need its own comparer (like you have with the NameComparer )
Cloaca wrote:
3) Why do I need to wrap the comparison functions in a struct? How does that fact relate to operator(), etc.?
struct does mean the same as class, but everything is public by default .
As you only want a class with only one public operator, writing struct instead of class does save you a whopping 6 keystrokes (7 for 'public' plus the ':', minus one because struct is longer than class .
I think that is the only reason.
"We trained hard, but it seemed that every time we were beginning to form up into teams we would be reorganised. I was to learn later in life that we tend to meet any new situation by reorganising: and a wonderful method it can be for creating the illusion of progress, while producing confusion, inefficiency and demoralisation."
-- Caius Petronius, Roman Consul, 66 A.D.
|
|
|
|
|
Hi jhwurmbach,
Thanks for your reply. That makes sense, but it then makes me wonder why I need a class (or struct) at all to hold the comparison function.
Why is it that I just can't declare the comparison function (just as a 'simple' member of CFoo ) and pass it to the stable_sort() call? I have been reading about operator() and functors, but I am not putting it all together yet, I guess. Does it have someting to do with the fact that functions passed to the algorithms can only have one parameter?
I appreciate your help, thanks again!
Eric
|
|
|
|
|
stds::sort is a template function. That means the arguments for the function determines what kind of code the compiler generates for the function (as opposed to a regular function, where the compiler always generates the same code). A template argument must be either a type or a constant--the compiler must be able to determine what the argument is at compile time, so it knows what code to generate. For the sort function, the template argument might have been a functor type or it might have been a constant that resolves to a function pointer. If you think about it, you can see how making the argument a type gives much more flexibility to the user of the template function, so that is the choice that the template designer made.
|
|
|
|
|
Hi antlers,
Ahh. I think that puts it together for me. A function is of course not a type. But by using the 'struct method', you kind-of wrap the function in a type. And so it is acceptable to the algorithm at compile time. The syntax of operator() is the way a wrapped function can be exposed to the algorithm for use in, for example, a sort call as a comparison.
And this minimal extra work is the small price to pay for a very flexible system of getting whatever might be needed into the templated algorithms. I see. Thanks very much for your help, I appreciate it!
Best,
Eric
|
|
|
|
|
Hello all
I've an application which is working well on win2000 & winXP. But when I ran the same application in win98 & winMe, it's leading to fatal crash and giving me blue screen.
In the case of fatal crash, how can we detect to which part of the application is causing it? I'm not able to debug this problem on win98 and winMe.
If anyone know abt any tools or techniques which can help me in debugging the problem, pls help me.
Many thanks for your help.
Hari.
|
|
|
|
|
haritadala wrote:
In the case of fatal crash, how can we detect to which part of the application is causing it?
Are you using/assuming something that is not available on non-NT machines?
A rich person is not the one who has the most, but the one that needs the least.
|
|
|
|
|
Hello David
Thanks for the reply. I'm not using or assuming something that's not on NT machines. My application is taking to devices connected to usb port. I'm using the driver supplied by third party vendor(this driver works on all windows machines, according to vendor). I'm able to send/receive data even on win98/winMe. But when I try to disconnect I'm experiencing fatal crash.
Any ideas as on how to debug this problem will be very much appreciated.
Many thanks for your help.
Hari.
|
|
|
|
|
It sounds like you need to contact the vender of the driver.
If all else fails try to find a memory validator or crash protect program, that can generate a report, even if the code is not available.
Once upon a time, I kept rejecting the release of a program based on the reports generated by Bounds Checker, since our sister would not release the
code to me in order to find the multple problems. Eventualy, they just turned the whole project over to me and it took months to find and fix all the problems.
INTP
|
|
|
|
|
How is it that you are unable to debug this on 98/ME?
Are you using .net/2003? If so, look into the remote debugging features of it, you should be able to debug that way....
Or is the blue-screen coming before any exceptions are trapped?
-p
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br />
Peter Weyzen<br />
Staff Engineer<br />
<A HREF="http://www.santacruznetworks.com">Santa Cruz Networks</A>
|
|
|
|