Solved

Read Only Edit Box Won't Update

Posted on 2006-10-22
5
713 Views
Last Modified: 2013-11-20
I have a read only edit box that I'm trying to use to display a file-count in a dialog box when the dialog box opens.

As part of the initialization of the dialog box, some files are counted and I know that's working but I can't get the count-value to display in an edit box (either as an integer or as a string).

I even tried adding a button to manually force the program-calculated value into the dialog box.  But the dialog box remains blank.

Articles on the subject seemed to break down into two categories:

1.  Those which warn against using GetDlgItem, but then don't tell you how to use an alternative.
2.  Those which warn against using UpdateData, but then don't tell you how to use an alternative.

I tried both methods, get no errors, and nothing displays in the edit box.  Right now, I'm just trying to display:  "test".  Can't even do that.

Googling the subject is an exercise in bizarro world help, where the help exists only at the very beginning levels and what seems to me to be the much more advanced levels, with nothing in between.

And what's really bizarre is I actually solved this problem several years ago (I don't do all that much MFC programming) and the program I wrote actually worked using GetDlgItem, using a single parameter, but when I try to use GetDlgItem in my new program I get an error saying GetDlgItem doesn't take only one parameter.    In both cases I was using Visual C++6.0.  In fact, using the same installation of it on the same computer and it works in one program and not in another.  

I'm not against using two parameters (the first one being a handle), but I have no idea how to do it, or how to find help with it, since all help on the subject seems to assume that the reader already knows as much about handles as everybody else, or why I need it in one program and not in another.

Any help would be greatly appreciated.
0
Comment
Question by:gateguard
5 Comments
 

Author Comment

by:gateguard
Comment Utility
Correction:

This:

I even tried adding a button to manually force the program-calculated value into the dialog box.  But the dialog box remains blank.

Should be:

I even tried adding a button to manually force the program-calculated value into the EDIT BOX.  But the EDIT BOX remains blank.
0
 
LVL 48

Assisted Solution

by:AlexFM
AlexFM earned 100 total points
Comment Utility
Can you show your code?
If you do this in MFC CDialog-derived class, it should be:

GetDlgItem(ID_TEXT)->SetWindowText(_T("test"));

ID_TEXT - resource ID of textbox.
0
 
LVL 22

Accepted Solution

by:
mahesh1402 earned 300 total points
Comment Utility
I am not sure why you need GetDlgItem in your application if its MFC application.

If your application is MFC application, then you may create a member variable for your editbox using classwizard of CEdit or CString type.

In your resource editor after adding Editbox to your dialog, invoke classwizard either by pressing CTRL+W or right click on dialog and select classwizard. Class Wizard dialog will open.. click on 2nd tab 'Member Variables'. Select CONTROL ID from list and click on 'Add Variable' button. Now in add variable dialog type variable name whatever u want like m_Editrw and select variable type as 'Control' from Category combobox and click OK. Now you have control variable m_Editrw associated with your editbox which is CEdit type.

Now you can access directly CEdit class members for your edit control and you dont need to use GetDlgItem etc.

to set text to your editbox you can now directly use  m_Editrw.SetWindowText("45");

However in classwizard while adding member variable if you have selected 'Control' under Category as variable type then you may set text like :

m_Edit = "45";
UpdateData(false);

Hope this helps
-MAHESH
0
 
LVL 22

Expert Comment

by:mahesh1402
Comment Utility
*Correction in above:

However in classwizard while adding member variable if you have selected 'VALUE' under Category as variable type then you may set text like :

m_Edit = "45";
UpdateData(false);

-MAHESH
0
 
LVL 5

Assisted Solution

by:Nass89
Nass89 earned 100 total points
Comment Utility
Hi,
You wrote, you are counting a file, are you writing in the EditBox in a while-loop?
If you have a loop then use the following codes!

for(.......){
          m_ctrlEdit.SetWindowText("Your Text"r);
          m_ctrlEdit.UpdateWindow();

          ....//your codes
          ....
          ....
          ....
}

Good luck
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
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 video discusses moving either the default database or any database to a new volume.

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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now