Solved

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

Posted on 2002-07-04
5
166 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
Comment Utility
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
Comment Utility
Ooops, second function name should be void Cddddlg::OnButton2()

VinExpert
0
 
LVL 4

Assisted Solution

by:mblat
mblat earned 25 total points
Comment Utility
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

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: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

762 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now