Output to a control instead of the MS Dos box for C programs

T

tizi_de

Hello all,

I'm looking for a sample program in C to print out lines not to the
standard MS Dos Box but into a different control e.g. text control.

Has C the possibility to do printouts to a control instead of using the
MS Dos Box? And what control can I use for this purpose when I need to
have the most similar look to the MS Dos Box?

Every help is greatly appreciated.
Thanks in advance.

With kind regards,
Tiziana
 
K

Kenny McCormack

Hello all,

I'm looking for a sample program in C to print out lines not to the
standard MS Dos Box but into a different control e.g. text control.

Has C the possibility to do printouts to a control instead of using the
MS Dos Box? And what control can I use for this purpose when I need to
have the most similar look to the MS Dos Box?

Off topic. Not portable. Cant discuss it here. Blah, blah, blah.

Useful clc-related links:

http://en.wikipedia.org/wiki/Aspergers
http://en.wikipedia.org/wiki/Clique
http://en.wikipedia.org/wiki/C_programming_language
 
C

CBFalconer

tizi_de said:
I'm looking for a sample program in C to print out lines not to the
standard MS Dos Box but into a different control e.g. text control.

Has C the possibility to do printouts to a control instead of using
the MS Dos Box? And what control can I use for this purpose when I
need to have the most similar look to the MS Dos Box?

See the links below.

--
Some useful references about C:
<http://www.ungerhu.com/jxh/clc.welcome.txt>
<http://www.eskimo.com/~scs/C-faq/top.html>
<http://benpfaff.org/writings/clc/off-topic.html>
<http://anubis.dkuug.dk/jtc1/sc22/wg14/www/docs/n869/> (C99)
<http://www.dinkumware.com/refxc.html> (C-library}
<http://gcc.gnu.org/onlinedocs/> (GNU docs)
<http://clc-wiki.net> (C-info)
 
R

Roland Pibinger

I'm looking for a sample program in C to print out lines not to the
standard MS Dos Box but into a different control e.g. text control.
Has C the possibility to do printouts to a control instead of using the
MS Dos Box?

Of course, don't you know that you can do anything in C?
And what control can I use for this purpose when I need to
have the most similar look to the MS Dos Box?

Write your output to a file with extension *.html and the following
structure:

<html>
<body>
<pre>

// your output here

</pre>
</body>
</html>

Open that file in/with your browser.

Good luck,
Roland Pibinger
 
N

Nick Keighley

tizi_de said:
I'm looking for a sample program in C to print out lines not to the
standard MS Dos Box but into a different control e.g. text control.

Has C the possibility to do printouts to a control instead of using the
MS Dos Box? And what control can I use for this purpose when I need to
have the most similar look to the MS Dos Box?

try comp.os.ms-windows.programmer.win32 where you might get better
answers.
Ignore Kenny he's the group idiot.
 
J

jacob navia

tizi_de a écrit :
Hello all,

I'm looking for a sample program in C to print out lines not to the
standard MS Dos Box but into a different control e.g. text control.

Has C the possibility to do printouts to a control instead of using the
MS Dos Box? And what control can I use for this purpose when I need to
have the most similar look to the MS Dos Box?

Every help is greatly appreciated.
Thanks in advance.

With kind regards,
Tiziana

Many people have done that, a "printf" in a control.
It is not VERY hard to do, but maybe the simplest thing
is to create the control, then call SetWindowText with
the handle of the control and the text you want to put into it.


(I am assuming is a static text control or an edit field)

More sophisticated usages with scrolling, etc are more demanding and
you would have to reimplement the "Dos box" what is nothing else
than a window with scrolling in it.

jacob
 
C

CBFalconer

jacob said:
tizi_de a écrit :

Many people have done that, a "printf" in a control.
It is not VERY hard to do, but maybe the simplest thing
is to create the control, then call SetWindowText with
the handle of the control and the text you want to put into it.

Haven't you learned yet that SetWindowText and 'a control' have
nothing to do with standard C? Neither does a MS Dos Box, nor a
handle. Please stop cluttering this group with off-topic
foolishness.
 
K

Keith Thompson

jacob navia said:
tizi_de a écrit :

Many people have done that, a "printf" in a control.
It is not VERY hard to do, but maybe the simplest thing
is to create the control, then call SetWindowText with
the handle of the control and the text you want to put into it.
[snip]

jacob's advice may be correct, but since he's not talking about
standard C, most of us here can't confirm or refute his information.

Tiziana: You need to post to a newsgroup that's specific to your
system. comp.os.ms-windows.programmer.win32 *might* be the right
place.
 
J

jacob navia

CBFalconer said:
Haven't you learned yet that SetWindowText and 'a control' have
nothing to do with standard C? Neither does a MS Dos Box, nor a
handle. Please stop cluttering this group with off-topic
foolishness.

A handle is an opaque pointer.

Its definition can be expressed in standard see as:

struct window;

typedef struct window *WindowHandle; // Or HWND for short.

This is very common in windows systems, and since the Mac,
opaque pointers are part of the life of C programmers.
 
B

Bill Reid

Hello all,

I'm looking for a sample program in C to print out lines not to the
standard MS Dos Box but into a different control e.g. text control.

Has C the possibility to do printouts to a control instead of using the
MS Dos Box? And what control can I use for this purpose when I need to
have the most similar look to the MS Dos Box?
OFF TOPIC!!!
Every help is greatly appreciated.
Thanks in advance.

With kind regards,
Tiziana
But since you asked so nicely...

First off, I'm assuming you're talking about using something like
printf() to print to a Windows "control" rather than the actual function
found in the winapi (or equivalent) for printing to the control. To
do the latter, check your Windows API package documentation...

However, to do the former, sure, I do it all the time, but as
usual exactly how you code this depends on what you really
want and what you're starting off with...

Here's the basic trick though: you have to selectively
re-define "printf()" to "print" to the control as if it
were the "console" (what you're calling a "DOS Box", or
equivalently, an "xterm" in Unix). Here's how I do it,
but again, your mileage may vary:

#ifdef __WINGUI__
#include <vcl.h>
#pragma hdrstop
#include <p_output.h>
#define printf gui_printf
#endif

Now this assumes a couple of things. First, I'm using
a particular development package (so "vcl.h" may be
something else for you, or you are using the "winapi" package
available bone-stock free from Microsoft on their website, which
may be the best idea of all, frankly). Second, this
is clearly "dual-use" code; I can conditionally compile
it as either Windows GUI application or as a "console"
(or "xterm") command-line interface application.

So if I compile the thing as a Windows GUI application,
the pre-processor turns all occurences of printf() into
gui_printf(), which is declared in "p_output.h" and defined
in a file called "p_output.c" which is linked into your
program.

gui_printf() is declared with the exact same "signature"
as "printf()", and defined as follows:

int gui_printf(char *format,...) {
unsigned print_length;

p_line_buffer[0]=NUL;
va_list ap;

va_start(ap,format);
vsprintf(p_line_buffer,format,ap);
va_end(ap);

print_length=(int)strlen(p_line_buffer);

print_line_buffer();

return print_length;
}

Note that the trick here is the use of the "vsprintf()"
function to handle all the functionality of "printf()" without
the nasty consequence of actually sending the output to
the "console". Instead, the formatted output is "printed"
to a buffer, and then the buffer is "printed" to the
Windows control by the "print_line_buffer()" function.

Now this is where you have to figure out where you're
coming from and where you "want to go today". What "control"
do you "print" to? Well, it's been a while since I looked
directly at the winapi package, but I think it's called
the "memo" control. In any event, it's the one Microsoft
uses in "Notepad" for displaying and editing relatively
small (36K limit) text-only files (my development package
supplies a "visual component" class called "TMemo" that
I use for this purpose, so unless you use the same package
the calls and configuration of this "object" won't make
too much sense).

But you'll probably want to implement some type of "scrolling"
functionality to allow you to freely and asynchronously "print"
to the control in the same way that "printf()" prints to
the "console". One thing is for sure: if you use the "memo" control,
your program will blow up to smithereens if you exceed the 36K text
limit, so unless you are sure you won't exceed that amount of
text, you'll have to "scroll out" old text from the "memo" control
buffer in order to "scroll in" new text.

This actually can be implemented by creating a "console buffer"
that ties into the calls to the "memo" control (or whatever it's called),
but I think you'll always wind up with (I've wound up with) some
fairly small "flickering" when scrolling large amounts of text because
the control was not designed to scroll asynchronous amounts of
text in the first place, just display a discrete single block of text.

For me, it's OK, but I think to get rid of that artifact
completely, you would have to go back to scratch and
work with rudimentary calls like "WM_PAINT" or whatever
and build your own console "work-alike"...
 
M

Mark McIntyre

Hello all,

I'm looking for a sample program in C to print out lines not to the
standard MS Dos Box but into a different control e.g. text control.

Assuming you're using Windows, you need to ask in a Windows
programming group, GUI interfaces are not part of hte C language.
--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
 
M

Mark McIntyre

A handle is an opaque pointer.

So you claim. Its impossible to verify that here, since its not part
of standard C.

You /know/ this is offtopic, why are you persisting in being such a
jerk?
This is very common in windows systems, and since the Mac,
opaque pointers are part of the life of C programmers.

So what? Cola and cake part of the life of C programmers. Are either
of those topical here?
--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
 
D

Default User

Mark McIntyre wrote:

So what? Cola and cake part of the life of C programmers. Are either
of those topical here?


I didn't know there was going to be cake today. What kind?




Brian
 
K

Kenny McCormack

So you claim. Its impossible to verify that here, since its not part
of standard C.

You /know/ this is offtopic, why are you persisting in being such a
jerk?


So what? Cola and cake part of the life of C programmers. Are either
of those topical here?

You guys really need to get a grip.
 
R

Richard Bos

jacob navia said:
tizi_de a écrit :

Many people have done that, a "printf" in a control.
It is not VERY hard to do, but maybe the simplest thing
is to create the control, then call SetWindowText with
the handle of the control and the text you want to put into it.

(I am assuming is a static text control or an edit field)

Not necessarily correct, and very unlikely to be sufficient. Thus jacob
proves once more both the inadvisability of answering off-topic
questions in comp.lang.c, and the lack of depth of his own knowledge.

Richard
 
C

CBFalconer

Old said:
You could consider linking to n1124 , as there are important
differences between n869 and the actual C99 text.

However N1124 doesn't offer a text version. Bad.
 
K

Keith Thompson

CBFalconer said:
However N1124 doesn't offer a text version. Bad.

Using Adobe Reader, I was able to load n1124.pdf and export it as
text. Other PDF readers can probably do the same thing. I haven't
really tried using the resulting text version; I just use the pdf.
 
K

Keith Thompson

Keith Thompson said:
Using Adobe Reader, I was able to load n1124.pdf and export it as
text. Other PDF readers can probably do the same thing. I haven't
really tried using the resulting text version; I just use the pdf.

And Ghostview's seems to give a cleaner text conversion than Adobe
Reader does.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,785
Messages
2,569,624
Members
45,318
Latest member
LuisWestma

Latest Threads

Top