Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 778
  • Last Modified:

Read Only Edit Box Won't Update

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
gateguard
Asked:
gateguard
3 Solutions
 
gateguardAuthor Commented:
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
 
AlexFMCommented:
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
 
mahesh1402Commented:
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
 
mahesh1402Commented:
*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
 
Nass89Commented:
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now