943,844 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Marked Solved
  • Views: 3749
  • C++ RSS
Feb 14th, 2009
0

Send text to multiline EditBox

Expand Post »
Hi Guys,
I'm trying to write a program (MFC) that while working displays a log to the user. For this log I thought I'd use an Edit Box because I can set it to be "multiline".
What I had in mind is to display each new log entry in a new row. Now I don't know any other function that I can use in order to display my text except "SetWindowText".
I tried using it with "LineScroll()" to write to a new line but it doesn't work. It only overwrites the first row.
So clearly I'm using the wrong function and maybe even the wrong Object to display my log.
Please Help....

Thank you,
Gadi
Reputation Points: 18
Solved Threads: 0
Light Poster
GadiK is offline Offline
32 posts
since Dec 2008
Feb 14th, 2009
0

Re: Send text to multiline EditBox

The problem is easy to solve, instead of adding a new line to the text box, simply add the line to a global string, then assign the string to the textbox.
C++ Syntax (Toggle Plain Text)
  1. #include <windows.h>
  2. #include <iostream>
  3.  
  4. HWND hEdit; // Text Box
  5. std::string log;
  6.  
  7. void AddLogLine(char *line) {
  8. log += line;
  9. log += "\n";
  10. SetWindowText( hEdit, log.c_str() );
  11. }
  12.  
  13. /* Rest of the Code *
  14.  
You could also consider using a Listbox instead.

Hope this helps.
Reputation Points: 1429
Solved Threads: 129
Posting Virtuoso
William Hemsworth is offline Offline
1,542 posts
since Mar 2008
Feb 15th, 2009
0

Re: Send text to multiline EditBox

Okay the idea with the string worked! (Only for some reason "\n" isn't enough and you need to write "\r\n").
But I would've thought there is a much simpler way to do this using MFC. Maybe there's some object for output to dialog window using the "<<" operator?
Reputation Points: 18
Solved Threads: 0
Light Poster
GadiK is offline Offline
32 posts
since Dec 2008
Feb 15th, 2009
0

Re: Send text to multiline EditBox

I don't use MFC, so i'm not sure. Either way, as far as I know, there's no function in the windows api that allows you to add text to a window. If it were me, i'd just stick with the way I just showed you It works.
Reputation Points: 1429
Solved Threads: 129
Posting Virtuoso
William Hemsworth is offline Offline
1,542 posts
since Mar 2008
Feb 15th, 2009
0

Re: Send text to multiline EditBox

Okay,
thanks a lot!! I'll stick to your method.
Reputation Points: 18
Solved Threads: 0
Light Poster
GadiK is offline Offline
32 posts
since Dec 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Structures in Classes
Next Thread in C++ Forum Timeline: end char = '/0' ???





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC