Solved

Printing output to edit control  in MFC

Posted on 2007-03-23
23
2,053 Views
Last Modified: 2013-11-26
Hello,
I want to be able to print out certain integer and float values to a textbox with some text before the values so that the user knows whats being printed. I need to print the values in a loop. However I have some problems. This is the background information:

I dont know if i should be adding a CEdit control variable or a Cstring value variable! So I added both and i tried stuff out with both. The Cedit Control variable is called tEdit_output and the CString value variable is called tEdit_Result. Please provide me an example with whichever variable you think  Ineed to use!
I need the values of some integers (say the value of j here for simplicity ) to be printed out in the format "
"And the value is ", j

in the following loop:

for(j =0;j<num;j++)
{
...print here to window

}//j
I
Its a multiline edit control.

THanks in advance,
-D

0
Comment
Question by:indacrypt
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 11
  • 6
  • 6
23 Comments
 
LVL 44

Accepted Solution

by:
AndyAinscow earned 150 total points
ID: 18779387
Point of clarification for you - there is a section specific to MFC questions - this is really meant for .NET questions.  

Have code like the following in the loop

CString s;
tEditOutput.GetWindowText(s);  //get current text
s += _T("\r\n");  //add a new line
s += INSERT YOUR TEXT HERE //put your new text here
tEditOutput.SetWindowText(s);  //now put back into the edit


---------------
CString ss;
ss.Format(_T("Hello %d"), 54);  // ss now is "Hello 54"
0
 
LVL 19

Assisted Solution

by:alb66
alb66 earned 100 total points
ID: 18779449
You can use both tEdit_output and tEdit_Result.

1) First prepare the big string to print...

CString str1, str2;

for(j =0;j<num;j++)
{
   str2.Format( "Some text  %d\r\n", yourvalue[j];
   str1 += str2;
}

2) Then print it...

if you want to use tEdit_output you can write:
 
    tEdit_output.SetWindowText( str1 );

if you want to use tEdit_Result you can write:

    tEdit_Result = str1;
    UpdateData( false );


Remember that UpdataData() is called by the framework in OnInitDialog() and OnOK() to perform tha data transfer from each variable member to each window control.

Personally I prefer to use control variabile to menage controls look, while I use value variable to menage controls content.

0
 

Author Comment

by:indacrypt
ID: 18779452
thanks andy....i guess i just checked .Net coz im using that programming environment. But thanks for clarifying that. What is the GetWindowText function for  in the above snippet of code?I mean im not getting anything from the window...im just printing to it.THanks!
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 44

Assisted Solution

by:AndyAinscow
AndyAinscow earned 150 total points
ID: 18779582
I thought you would be adding each new line onto the existing text.  IF you aren't then:

CString s;
s = INSERT YOUR TEXT HERE //put your new text here
tEditOutput.SetWindowText(s);  //now put into the edit



I prefer using the control rather than the variable the UpdateData will perform an update on EVERY control you have a variable mapped to.  This way you only update the control whose contents has actually changed.
0
 

Author Comment

by:indacrypt
ID: 18779668
alb66...what does updateData(false) do?
0
 

Author Comment

by:indacrypt
ID: 18779680
ANd Andy..one more thing with your s and ss exmaples...did u mean it can be done either way....
0
 
LVL 19

Expert Comment

by:alb66
ID: 18779736
UpdateData( false ) trasfer data from the value member variables ( tEdit_Result ) to the window control (the edit box).
As Andy said, this occurs for every control in the dialog with an associated  varable.
0
 

Author Comment

by:indacrypt
ID: 18779771
So if say I want to print 4 different things with an explanation for each of them I need 4 string variables??.....
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 18779782
s and ss - one was showing you how to put a string into the edit control, the other was how to put an integer into a string with text.
0
 

Author Comment

by:indacrypt
ID: 18779875
sorry ..my questions must seem retarded. Its just that im  really tired though.  Ok..heres what I tried:

for(j =0;j<form2_ldPtr[i].get_tot_num_of_legs();j++)\
{
 temp_ord_num = form2_ldPtr[i].get_tract_num(j);
CStr_Output.Format("\n Tractor for leg %d",j, " =%d \n " , temp_ord_num);
CStr_temp += CStr_Output;
}//j
tEdit_output.SetWindowText(CStr_temp);

Now in debug mode I've checked that temp_ord_num has the correct values. However when i print it out to the window it prints onl "Tractor for leg 0"...Tractor for leg 1 etc. It does not print temp_ord_num. Instead theres a weird character like a little rectangle thts printed after tractor for leg j, and also it doesnt insert the new line character....
0
 
LVL 19

Expert Comment

by:alb66
ID: 18779898
Try this:

CStr_Output.Format("\r\n Tractor for leg %d =%d \r\n" , j ,  temp_ord_num);
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 18779911
new line - \r\n

SetWindowText as I said earlier will replace any text existing in the control.  If you want to append to the existing text you need my first code snippet.




ps
retarded questions - everyone must start learning somewhere
0
 

Author Comment

by:indacrypt
ID: 18779970
okie...the code from both of u works thank  u VERY MUCH....only problem NOW is....the scroll button is not being enabled:| a wee bit of the last line is getting cut off !! It is multiline and all the atuoscroll options are enabled for the output text window
0
 

Author Comment

by:indacrypt
ID: 18779976
"s += _T("\r\n");  " ..andy in that line of code what is the _T for?
0
 
LVL 19

Expert Comment

by:alb66
ID: 18780030
Try to set "vertical scroll" property to true.
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 18780034
UNICODE - crudely said if UNICODE is defined then it will wide chars (2 byte) else ASCII chars (1 byte)
0
 

Author Comment

by:indacrypt
ID: 18780083
no unicode and veritcal scroll property is true:(
0
 
LVL 19

Expert Comment

by:alb66
ID: 18780099
You must set "Vertical scroll" to true...
0
 

Author Comment

by:indacrypt
ID: 18780140
Vertical Scroll from the properties for the text window, is set to TRUE. Do you mean I have to do something else to set it to true?...
0
 
LVL 19

Expert Comment

by:alb66
ID: 18780173
sorry, i misunderstood your previous comment...
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 18780203
UNICODE or not - doesn't make any difference to what you are doing.
Win 95, 98, Me are ASCII based, WIn NT, 2000, XP, Vista are UNICODE based.  They can run ASCII programs (albeit with slight performance hit).
0
 

Author Comment

by:indacrypt
ID: 18780259
darn..what else can it be
0
 

Author Comment

by:indacrypt
ID: 18780265
wierd..i reduced the size of the text window a little bit and now it scrolls!! thanks so much for your help
0

Featured Post

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Suggested Solutions

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
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.
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

696 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