Solved

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

Posted on 1998-04-04
6
249 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
[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
  • 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
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 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

Independent Software Vendors: 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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Focus not getting shifted out of  editbox 2 69
sorting efficency of sorting algorithm 30 129
VS2015 Redefinition errors 4 88
How do I get Window Title of all opened process? 4 33
Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

763 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