How to create an array of edit boxes in a dialog based application 
Author Message
 How to create an array of edit boxes in a dialog based application

Dear experts(Visual C++ and MFC),

I am using Visual C++ version 6.0 and MFC for creating a GUI application. In this
application, I need to have an array of controls (edit boxes).

I like to have an array of 6 edit boxes on a dialog, in a dialog based
application.

1. Suppose I created a simple dialog based application using MFC AppWizard (exe).
2. I placed one edit box on it.
3. I highlighted this edit box and pressed (CTRL and double click) to add a
member variable.
4. I typed the variable name as "m_Frequency" and selected the category = Value,
variable type = Float.

Now I want five more exactly same edit boxes on this dialog with same name
m_Frequency but in an array (i.e. m_Frequency[0], m_Frequency[1], m_Frequency[2],
m_Frequency[3], m_Frequency[4], m_Frequency[5]).

It would have been easy in Visual Basic. I would have copied first created edit
box onto second and then onto third and so on
or I could have typed the second control same as the first one and a popup
message would have appeared to ask me that this variable already exist and do I
want to make it an array, that's exactly what I wanted.

But in Visual C++:
it just won't let me name second variable same as first one.
or/otherwise
if I try copping first "m_Frequency" edit box into second one, it gives me a new
ordinary edit box with no name attached.

Please help. Thanks.

Sohan Chouhan
(613) 584 - 8811 ext. 4709
Canada.



Sat, 20 Sep 2003 01:58:14 GMT  
 How to create an array of edit boxes in a dialog based application

Sohan Chouhan schrieb in Nachricht

Quote:
> Dear experts(Visual C++ and MFC),
> 1. Suppose I created a simple dialog based application using MFC AppWizard
(exe).
> 2. I placed one edit box on it.
> 3. I highlighted this edit box and pressed (CTRL and double click) to add
a
> member variable.
> 4. I typed the variable name as "m_Frequency" and selected the category =
Value,
> variable type = Float.

> Now I want five more exactly same edit boxes on this dialog with same name
> m_Frequency but in an array (i.e. m_Frequency[0], m_Frequency[1],
m_Frequency[2],
> m_Frequency[3], m_Frequency[4], m_Frequency[5]).

Look at your .cpp-file and what the wizard did to your class. You have
DDX_-calls there.
First, move them out of the AFX_DATA_MAP, then use them to connect the
edit-boxes to your array.

dlg.h
class MyDialog
    vector<float> m_table;

dlg.cpp

MyDialog::MyDialog()
{
    m_table.resize(6);

Quote:
}

MyDialog::DoDataExchange()
{
// {{AFX_DATA_MAP(CAboutDlg)
// }}AFX_DATA_MAP
DDX_Text(pDX, IDC_EDIT_0, m_table[0]);
DDX_Text(pDX, IDC_EDIT_1, m_table[1]);
DDX_Text(pDX, IDC_EDIT_2, m_table[2]);
DDX_Text(pDX, IDC_EDIT_3, m_table[3]);
DDX_Text(pDX, IDC_EDIT_4, m_table[4]);
DDX_Text(pDX, IDC_EDIT_5, m_table[5]);

Quote:
}

You have to move them outside the data-map or classwizard refuses to edit
this file any further.

hth
uli



Sat, 20 Sep 2003 02:21:13 GMT  
 How to create an array of edit boxes in a dialog based application
You could create an array of edit control pointers in your dialog class;
something such as:

    CEdit *m_pEditBoxes[6];

Then assuming you have some control member variables (such as m_ctlEditBox1
through m_ctlEditBox6) you have created using ClassWizard, then in your
OnInitDialog after your call to the base class OnInitDialog
(CDialog::OnInitDialog) you could assign values to the array elements as in
the following:

    m_pEditBoxes[0] = &m_ctlEditBox1;
    m_pEditBoxes[1] = &m_ctlEditBox2;
    m_pEditBoxes[2] = &m_ctlEditBox3;
    m_pEditBoxes[3] = &m_ctlEditBox4;
    m_pEditBoxes[4] = &m_ctlEditBox5;
    m_pEditBoxes[5] = &m_ctlEditBox6;

Then you do not need to mess with anything that ClassWizard messes with,
right?


Dear experts(Visual C++ and MFC),

I am using Visual C++ version 6.0 and MFC for creating a GUI application. In
this
application, I need to have an array of controls (edit boxes).

I like to have an array of 6 edit boxes on a dialog, in a dialog based
application.

1. Suppose I created a simple dialog based application using MFC AppWizard
(exe).
2. I placed one edit box on it.
3. I highlighted this edit box and pressed (CTRL and double click) to add a
member variable.
4. I typed the variable name as "m_Frequency" and selected the category =
Value,
variable type = Float.

Now I want five more exactly same edit boxes on this dialog with same name
m_Frequency but in an array (i.e. m_Frequency[0], m_Frequency[1],
m_Frequency[2],
m_Frequency[3], m_Frequency[4], m_Frequency[5]).

It would have been easy in Visual Basic. I would have copied first created
edit
box onto second and then onto third and so on
or I could have typed the second control same as the first one and a popup
message would have appeared to ask me that this variable already exist and
do I
want to make it an array, that's exactly what I wanted.

But in Visual C++:
it just won't let me name second variable same as first one.
or/otherwise
if I try copping first "m_Frequency" edit box into second one, it gives me a
new
ordinary edit box with no name attached.

Please help. Thanks.

Sohan Chouhan
(613) 584 - 8811 ext. 4709
Canada.



Sat, 20 Sep 2003 05:00:16 GMT  
 How to create an array of edit boxes in a dialog based application
Ulrich Eckhardt and Sam Hobbs,

Thanks for trying to help.

Although I was not find a perfect solution to my problem but I
have convinced myself on a way around.

Sohan



Sun, 21 Sep 2003 20:37:55 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Trapping Keystrokes in a Dialog Box or Dialog based application

2. Associating an array of strings to several Edit Boxes in a Dialog Box

3. Replacing the dialog box of a dialog-based application

4. Trapping Keystrokes in a Dialog Box or Dialog based application

5. Printing a Dialog Box from a Dialog-Based Application

6. PBM: Message box not displayed after main dialog box is closed in MFC dialog-based app

7. How can I use CPrintDialog on a Dialog Box based application

8. how to create array of Controls (edit boxes)?

9. Need help creating a dialog base application for 1.52

10. creating toolbar on a dialog based application.

11. How to create a Dialog based Application with MainDlg hidden on startup

12. Struggling Newbie:, Creating a dialog-based application from AppWizard

 

 
Powered by phpBB® Forum Software