?
Solved

Accessing text of an edit box

Posted on 1998-10-29
2
Medium Priority
?
286 Views
Last Modified: 2013-11-20
I have an edit box named IDCTextFormula in a window. Is this the easiest way to change its text?:

CEdit* formula = (CEdit*)GetDlgItem(IDCTextFormula);
formula->SetWindowText("test");

Likewise, with any control, do you have to go through all that work just to access a method?
0
Comment
Question by:TylerRick
[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 Comments
 
LVL 4

Accepted Solution

by:
pagladasu earned 160 total points
ID: 1324027
If you do not want to use GetDlgItem, you can try member variables.
Using class wizard, let us say you associate a member variable of type CString
with the edit control IDCTextFormula. Let us say the name of this variable is
m_edit_textformula.
In your code where you want to change the contents of the edit control, you write
m_edit_textformula="test";
UpdateData(FALSE);

The other method could be by using class wizard and associating a control type
of variable (of type CEdit) with the edit control IDCTextFormula. Let us this is called m_editctrl. Then in your code you write:
m-editctrl.SetWindowText("test");

Hope you will find this an easier method.

Thanks.
Pagladasu

0
 

Expert Comment

by:aasif
ID: 1324028
It all depend on your choice. You can define a variable for it (with the help of Class Wizard) or access it through GetDlgItem method. Usually I use Class Wizard for such type of controls which I access number of times, where as I have to access a control in my application only few time I use

(CEdit* GetDlgItem(IDCTextFormula))->SetWindowText("Test");

In your case, you can also define a CString type varaiable with your CEdit control through Class Wizard, and after moving new value just call UpdateData(FALSE). This will update your Edit Box with new value.



0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

771 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