Display values in a Text Box? 
Author Message
 Display values in a Text Box?

I wrote a small dialog-based program to read some values from an external
device over the serial port. The Communication is ok. But I want to display
the read values in a (maybe) text box in this window.
I'm a Beginner and I think it's not very difficult, but I need some help.
Thank you
Dirk Kurock


Thu, 10 Apr 2003 03:00:00 GMT  
 Display values in a Text Box?

Quote:
>I wrote a small dialog-based program to read some values from an external
>device over the serial port. The Communication is ok. But I want to display
>the read values in a (maybe) text box in this window.

Dirk,

Place an edit control on the dialog using the dialog editor, give it
an identifier (again using the dialog editor). In your code you can
then do something like this:

        SetDlgItemInt( hDlg, IDC_EDIT, iValue, true );

Dave
--
MVP VC++ FAQ: http://www.mvps.org/vcfaq
My address is altered to discourage junk mail.
Please post responses to the newsgroup thread,
there's no need for follow-up email copies.



Thu, 10 Apr 2003 03:00:00 GMT  
 Display values in a Text Box?

Quote:

> I wrote a small dialog-based program to read some values from an external
> device over the serial port. The Communication is ok. But I want to display
> the read values in a (maybe) text box in this window.
> I'm a Beginner and I think it's not very difficult, but I need some help.
> Thank you
> Dirk Kurock

This code does that, using a CEdit m_ctl member variable created by the wizard:

// Append line of text
void CCom::AddMessage(LPCTSTR lpszMessage)
{
        CString strTemp = lpszMessage;
        strTemp += _T("\r\n");
        int len = m_ctl.GetWindowTextLength();
        if (len > SCROLL_BUFFER_LIMIT - 50)
        {       // flush some old
                m_ctl.SetSel(0, 100, TRUE);
                m_ctl.ReplaceSel("");
                len = m_ctl.GetWindowTextLength();
        }
        m_ctl.SetSel(len,len);
        m_ctl.ReplaceSel(strTemp);

Quote:
}

--
Scott McPhillips [VC++ MVP]


Thu, 10 Apr 2003 03:00:00 GMT  
 Display values in a Text Box?
It is MUCH easier to let classiwizard to all the work for you.

Create you edit box in the resourec editor

Double-click on it to create a member variable with the appropriate type
(maybe an int, maybe a text string .. depends on how you get your data)

This will associate a (memeber) variable with the text (edit) box

Now you simply need to copy a value into the variable and (from within the
dialog class) call UpdateData(FALSE) to copy from the variable to the
control.

NOTE: if this data is for display only, set the edit control style to
read-only
--
Roger Onslow
Software Developer
See my articles at http://www.codeguru.com
See the product I am working on at http://www.swishzone.com

"Operator .. give me the number for 911" .. Homer Simpson


Quote:

> > I wrote a small dialog-based program to read some values from an
external
> > device over the serial port. The Communication is ok. But I want to
display
> > the read values in a (maybe) text box in this window.
> > I'm a Beginner and I think it's not very difficult, but I need some
help.
> > Thank you
> > Dirk Kurock

> This code does that, using a CEdit m_ctl member variable created by the
wizard:

> // Append line of text
> void CCom::AddMessage(LPCTSTR lpszMessage)
> {
> CString strTemp = lpszMessage;
> strTemp += _T("\r\n");
> int len = m_ctl.GetWindowTextLength();
> if (len > SCROLL_BUFFER_LIMIT - 50)
> { // flush some old
> m_ctl.SetSel(0, 100, TRUE);
> m_ctl.ReplaceSel("");
> len = m_ctl.GetWindowTextLength();
> }
> m_ctl.SetSel(len,len);
> m_ctl.ReplaceSel(strTemp);
> }

> --
> Scott McPhillips [VC++ MVP]



Fri, 11 Apr 2003 07:06:11 GMT  
 Display values in a Text Box?

I'd prefer a control variable.
I'd suggest to read Joe Newcomer's essay about avoiding UpdateData:

http://www3.pgh.net/~newcomer/updatedata.htm

HTH, Nikolaus


<snip>

Quote:
> Now you simply need to copy a value into the variable and (from within the
> dialog class) call UpdateData(FALSE) to copy from the variable to the
> control.

<snip>


Wed, 16 Apr 2003 00:16:11 GMT  
 Display values in a Text Box?
The article is a load of rubbish.

Its just bad code (his example) being used as an example of why you
shouldn't call good code (UpdateData).

Basically, don't do what this person say.  His idea of the way Ok/Cancel
should behave just isn't correct .. its not the way the MFC was written to
behave.

There is no good reason at all not to use UpdateData etc in a dialog.
Indeed, control variables just mean more code for you to write when using
DDX and UpdateData MFC does it all for you.
--
Roger Onslow
Software Developer
See my articles at http://www.codeguru.com
See the product I am working on at http://www.swishzone.com

"Operator .. give me the number for 911" .. Homer Simpson


Quote:

> I'd prefer a control variable.
> I'd suggest to read Joe Newcomer's essay about avoiding UpdateData:

> http://www3.pgh.net/~newcomer/updatedata.htm

> HTH, Nikolaus



> <snip>
> > Now you simply need to copy a value into the variable and (from within
the
> > dialog class) call UpdateData(FALSE) to copy from the variable to the
> > control.
> <snip>



Wed, 16 Apr 2003 11:31:48 GMT  
 Display values in a Text Box?

Quote:
>There is no good reason at all not to use UpdateData etc in a dialog.

Roger,

In the real world things are never so black and white.

For the use that this person wanted (to repeatedly update an edit
control), the more efficient method is to use SetDlgItemText/Int
directly (or through a member control variable).

Using UpdateData updates all the DDX member variables - which means
unnecessary extra code is running, and in a complex dialog it may well
be totally the wrong thing to do.

As in most programming, there are few solid rules, use whatever method
best fits the requirement.

Dave
--
MVP VC++ FAQ: http://www.mvps.org/vcfaq
My address is altered to discourage junk mail.
Please post responses to the newsgroup thread,
there's no need for follow-up email copies.



Thu, 17 Apr 2003 01:27:48 GMT  
 Display values in a Text Box?

Quote:
> >There is no good reason at all not to use UpdateData etc in a dialog.

Maybe I should have worded my statement as:
    "there is no good reason at all why UpdateData cannot be used in a
dialog"
That is what I was trying to say.

Quote:
> In the real world things are never so black and white.
[snip]
> As in most programming, there are few solid rules, use whatever method
> best fits the requirement.

Indeed ... and thats _exactly_ why I don't like the article referred to.
It's author claims that you should NEVER use UpdateData in a dialog because
it doesn't work and is flawed.  However, the reason _why_ his examples have
problems is that he is not utilising dialogs and ddx etc in an
MFC-compatible way .. ie the problemis really with the way he writes his
programs, not anything inherently wrong with UpdateData etc.

Its a bit like saying "don't use the ++ operator because 'i = i++;' gives
strange behaviour" whereas one should be saying "don't write code like 'i =
i++;' because that is not appropriate use of the ++ operator".

Hopefully that better illustrates the point I was trying to make here.
--
Roger Onslow
Software Developer
See my articles at http://www.codeguru.com
See the product I am working on at http://www.swishzone.com

"Operator .. give me the number for 911" .. Homer Simpson


Quote:

> >There is no good reason at all not to use UpdateData etc in a dialog.

> Roger,

> In the real world things are never so black and white.

> For the use that this person wanted (to repeatedly update an edit
> control), the more efficient method is to use SetDlgItemText/Int
> directly (or through a member control variable).

> Using UpdateData updates all the DDX member variables - which means
> unnecessary extra code is running, and in a complex dialog it may well
> be totally the wrong thing to do.

> As in most programming, there are few solid rules, use whatever method
> best fits the requirement.

> Dave
> --
> MVP VC++ FAQ: http://www.mvps.org/vcfaq
> My address is altered to discourage junk mail.
> Please post responses to the newsgroup thread,
> there's no need for follow-up email copies.



Thu, 17 Apr 2003 19:05:59 GMT  
 Display values in a Text Box?

Quote:
>Indeed ... and thats _exactly_ why I don't like the article referred to.

OK Roger, that's good, we're all agreed then :) Use whatever seems
most appropriate in the particular circumstance.

Cheers
Dave
--
MVP VC++ FAQ: http://www.mvps.org/vcfaq
My address is altered to discourage junk mail.
Please post responses to the newsgroup thread,
there's no need for follow-up email copies.



Thu, 17 Apr 2003 21:20:26 GMT  
 
 [ 9 post ] 

 Relevant Pages 

1. Displaying values in an Edit Box

2. Displaying double values in edit boxes

3. Displaying integer values in an Edit box

4. Displaying integer values in an Edit box

5. Text box value & calling a method

6. Setting values in VC6 IDE Preprocessor Definitions text box

7. Pass text box value to a browser

8. Creating multiple text boxes and then getting the values

9. Can’t display text in dialog box in original format

10. Displaying text in an Edit Box

11. Displaying text in Edit Box

12. How to display complete long text in combo boxes

 

 
Powered by phpBB® Forum Software