Solved

how to create a runtime edit boxes erasing previously created edit boxes at client area?

Posted on 2002-07-04
5
178 Views
Last Modified: 2013-11-20
In a dialog based application, onclick button1 i should generate dynamically three edit boxes, and onclick button2  previous edit boxes should vanish and new set of four edit boxes should appear.(i.e. client area should be erased on onclick button2 and new sizes of edit boxes should appear dynamically). if any one knows please send me sample program.
thanks
0
Comment
Question by:ravi_pvkumar
  • 2
5 Comments
 
LVL 8

Accepted Solution

by:
VinExpert earned 25 total points
ID: 7131462
Hi,

Solution is simple.

1. Have the CEdit pointers in the .h file of ur dialog class in the public section

//I am taking 2 pointers here for easy understanding
CEdit *pEdit1;
CEdit *pEdit2;

2. Have rectangles of each edit control u want to display also

CRect m_cRect1;
CRect m_cRect2;

3. In the constructor U intialize them to NULL and set the rect sizes

pEdit1 = NULL;
pEdit2 = NULL;

//Fill in m_cRect1 and m_cRect2 here
//...

4. Now, on click on button 1, u execute the follwing code

void Cddddlg::OnButton1()
{
//Delete the old set if any
if(pEdit2)
{
delete pEdit2;
pEdit2 = NULL;
}

pEdit1 = new CEdit;
pEdit1->Create(WS_CHILD|WS_BORDER|WS_TABSTOP|ES_LEFT, m_cRect1, this, 100);
pEdit1->ShowWindow(SW_SHOW);
}

void Cddddlg::OnButton1()
{
//Delete the old set if any
if(pEdit1)
{
delete pEdit1;
pEdit1 = NULL;
}

pEdit2 = new CEdit;
pEdit2->Create(WS_CHILD|WS_BORDER|WS_TABSTOP|ES_LEFT, m_cRect2, this, 101);
pEdit2->ShowWindow(SW_SHOW);
}

That should give u the idea on how to go abt it.

Try it out.
VinExpert
0
 
LVL 8

Expert Comment

by:VinExpert
ID: 7131465
Ooops, second function name should be void Cddddlg::OnButton2()

VinExpert
0
 
LVL 4

Assisted Solution

by:mblat
mblat earned 25 total points
ID: 7133052
Or one can hide/show edit boxes after appropriate clicks.

Like this

CMyDlg:OnButton1()
{
    ShowFirstTreeEditBoxes(TRUE);
}

CMyDlg:OnButton1()
{
        ShowFirstTreeEditBoxes(FALSE);
}

CMyDlg::ShowFirstTreeEditBoxes(BOOl bFlag)
{
// first 3 boxes
GetDlgItem(IDC_EDIT1)->ShowWindow(bFlag ? SW_SHOW : SW_HIDE);
GetDlgItem(IDC_EDIT2)->ShowWindow(bFlag ? SW_SHOW : SW_HIDE);
GetDlgItem(IDC_EDIT3)->ShowWindow(bFlag ? SW_SHOW : SW_HIDE);
// other 4
GetDlgItem(IDC_EDIT4)->ShowWindow(!bFlag ? SW_SHOW : SW_HIDE);
GetDlgItem(IDC_EDIT5)->ShowWindow(!bFlag ? SW_SHOW : SW_HIDE);
GetDlgItem(IDC_EDIT6)->ShowWindow(!bFlag ? SW_SHOW : SW_HIDE);
GetDlgItem(IDC_EDIT7)->ShowWindow(!bFlag ? SW_SHOW : SW_HIDE);
}

Then one doesn't need to mess with on-screen coordiates - they set in resource editor.

Hope it helps...
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question