Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

can I add a property/bool member variable/flag to a control item 1

Status
Not open for further replies.

Sedai

Programmer
Mar 4, 2001
158
US
can I do that?
I need to add a flag (bool value) to all my edit box controls.
Is that possible? If yes, how can I do it?

Thanks.
Avendeval


 
A boolean value for what? The only boolean value related to an edit box I can think of would be whether it is enabled or not...if that is what you are looking for just set a
bool value = m_EditBox.IsWindowEnabled();
 
I need a flag to be set when the content of the edit box meets some criteria for which I check, i.e. if the input is valid (by some rules, which I have defined myself). So far I've been working with bool values for every edit box,
(ON_EN_UPDATE i check the new input and if it's ok i set my variable to true),
but currently I have 6 such boxes and it is kind of awkward.
I am going to have another dialog box with 8 edit boxes in it, so that's going to be even worse. (Btw, the edit boxes are for coordinates of points, in case u were wondering).
Anyway, to cut a long story short, is this possible?
Thanks.
Avendeval


 
Manually, add flags that associated to each edit box (outside the ClassWizard created area). For example:
class CMyDilaog : public CDialog
{
protected:
bool m_bMyEdit1Valid;
bool m_bMyEdit2Valid;
...

//{{AFX_DATA(CMyDialog)
CEdit m_edtMyEdit1;
CEdit m_edtMyEdit2;
...
//}}AFX_DATA

};

In your ON_EN_UPDATE handler, set the corresponding flag based on your validation logic.

HTH
Shyan
 
that's what I have at the moment.
What I need is to be able to kind of add another member variable to the CWnd class from which each edit box is created, so that I can have the following syntax

GetDlgItem(MY_IDENTIFIER)->Valid = true;
Where Valid is my bool variable.
I know it's a big thing I'm asking for, I mean I need to modify the CWnd class. I guess it's impossible. I was just thinking of in the class there is some 'room' left to create your own flags and access and modify them thorugh each and every obj from that class.

Is that possible?
Avendeval


 
> that's what I have at the moment.
> What I need is to be able to kind of add another member
> variable to the CWnd class from which each edit box is
> created, so that I can have the following syntax

It only make sense if the member is also associated to the control. It also depends on the type of control. For example in CEdit class, you can associate it with either CString or int, or many others. But that means you're expecting or restricting the input to be of that type. Not necessary what you're looking for.

From your description, you just need a flag to indicate whether the entry in the edit box is valid. One way is what you are currently doing, I list another way at the end. Associate a new BOOL type to your edit box does not do what you want. It just means you can only enter a BOOL value into the edit box.


> GetDlgItem(MY_IDENTIFIER)->Valid = true;

First of all, there is not member function Valid in any CWnd and CWnd derived class. CEdit has many properties, but user defined property such as BOOL does not exist.

> Where Valid is my bool variable.
> I know it's a big thing I'm asking for, I mean I need to
> modify the CWnd class. I guess it's impossible. I was
> just thinking of in the class there is some 'room' left
> to create your own flags and access and modify them
> thorugh each and every obj from that class.
Some control has internal storage for additional user defined data. Normally a DWORD. One example is a list box control. Set/GetItemData set and retrieve user data that is associated to a specific item. But that is part of the control.

> Is that possible?
If you really want the CEdit object to carry extra information, one way is to derived you own class based on CEdit:
class CMyValidateEdit : public CEdit
{
protected:
bool m_bValid;
public:
bool IsValid(void) const;
void SetValid(const bool bValid);
};


Manually change the ClassWizard generated code:
CEdit m_Edit1;
to:
CMyValidateEdit m_Edit1;


Now you can just call:
m_Edit1.SetValid(...);

 
thanks. u answered axactly what i needed :).
Thanks!! Avendeval


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top