Solved

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

Posted on 2002-07-04
5
179 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Expand to include initial dialog with two choices. 9 94
Sed question 2 139
unix example issues 18 114
Excel file not created as expected 7 111
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
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…
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.
Suggested Courses

752 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