Solved

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

Posted on 1998-04-04
6
247 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
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 
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

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
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.

770 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