Solved

How to redirect "printf( )" to a window in Visual C++?

Posted on 1998-04-04
6
246 Views
Last Modified: 2008-02-01
Dear experts:

I am now doing a course project using Visual C++. I am trying to transplant an existing UNIX Ansi C program to
Windows 95 platform. In this C program, there are many "printf()" functions to print out some information to the screen. I would like to convert these outputs to a window ( a ScrollView ) rather than DOS mode screen. May you tell me a proper way of doing that using Visual C++? Thanks.

-jzzhang
0
Comment
Question by:jzzhang
  • 3
  • 3
6 Comments
 
LVL 11

Accepted Solution

by:
alexo earned 20 total points
ID: 1184058
Easiest solusion: create a read-only editbox with scrollbars.  For each string you want to write to it, set the selection (EM_SETSEL) to [0x7FFF-0x7FFF] and replace the selection (EM_REPLACESEL) with the string.  Don't forget "\r\n" at the end of lines.

Don't you thing 10 points is kinda, err..., cheap?

0
 
LVL 2

Author Comment

by:jzzhang
ID: 1184059
Alexo:

Thank you for your answer. It works fine using your method. However, the output in a CEdit control is reverse. That is the last line of string always displays at the top. The first line of string goes to the bottom. Can you provide me a solution to display all these lines of strings in the right order? Thanks.

Jzzhang
0
 
LVL 2

Author Comment

by:jzzhang
ID: 1184060
Alexo:

Can you tell me what means to set the selection (EM_SETSEL) to [0x7FFF-0x7FFF]? What is the meaning of this number?

Jzzhang
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 11

Expert Comment

by:alexo
ID: 1184061
The number is what will make the CEdit box act normal.
It will select the area *after* your last line so replacing the selection will add the line.
Use: SetSel(0x7FFF, 0x7FFF)

0
 
LVL 2

Author Comment

by:jzzhang
ID: 1184062
Alexo:

Your method is great! I would like to give you 200 points. But how?

0
 
LVL 11

Expert Comment

by:alexo
ID: 1184063
Thanx.  I appreciate it!
You can post a dummy 200-point question titled "for alexo only".  Just let me know in what area.

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

864 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now