Solved

Accessing text of an edit box

Posted on 1998-10-29
2
282 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 40 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

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
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.
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…

707 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