Solved

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

Posted on 1998-04-04
6
245 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

707 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

13 Experts available now in Live!

Get 1:1 Help Now