Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Read Only Edit Box Won't Update

Posted on 2006-10-22
5
Medium Priority
?
775 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
ID: 17783051
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 400 total points
ID: 17783106
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 1200 total points
ID: 17783213
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
ID: 17783227
*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 400 total points
ID: 17783320
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

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…
In this post we will learn different types of Android Layout and some basics of an Android App.
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 shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Suggested Courses

916 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