Solved

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

Posted on 2002-07-04
5
170 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Expand macro to include alternate header placement and naming 5 66
string initialization in java 11 110
wordmultiple challenge 12 119
x-bar in Google Sheets 2 26
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
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.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

920 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

16 Experts available now in Live!

Get 1:1 Help Now