467,145 Members | 988 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,145 developers. It's quick & easy.

Problems displaying output from vc++ program

Hi, I've got a simple vc++ program that basically just runs a daemon in
the background and sends update messages to a logfile as it goes along.

What I'd like to do is see these log messages also displayed in a
window - either a dos window or a 'proper' window with a text field
etc...

I can easily create a window with a text field, but I can't find any
way to attach it to my project so I can write to it from there (I'm
looking to just 'add' it to my project somehow so I can then say
mywindow.mytextfield.text = "and another thing ...\n"; or something
like that).

Alternativley I'd be happy with a dos window popping up that displays
the messages, but using cout << "and another thing ..." << endl;
doesn't make a dos window appear.

Any ideas on how to make either of these solutions work would be very
welcome - 2 vc++ developers have failed to get this working for me, so
I'll be most impressed if you manage it!!

Dec 23 '05 #1
  • viewed: 1006
Share:
1 Reply
"royzeb" <ro******@yahoo.co.uk> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
Hi, I've got a simple vc++ program that basically just runs a daemon in
the background and sends update messages to a logfile as it goes along.

What I'd like to do is see these log messages also displayed in a
window - either a dos window or a 'proper' window with a text field
etc...

I can easily create a window with a text field, but I can't find any
way to attach it to my project so I can write to it from there (I'm
looking to just 'add' it to my project somehow so I can then say
mywindow.mytextfield.text = "and another thing ...\n"; or something
like that).

Alternativley I'd be happy with a dos window popping up that displays
the messages, but using cout << "and another thing ..." << endl;
doesn't make a dos window appear.

Any ideas on how to make either of these solutions work would be very
welcome - 2 vc++ developers have failed to get this working for me, so
I'll be most impressed if you manage it!!


Well, when you set out to build an application under Windows you have two
choices, and within them two more.

First, are you to build a "native" application or one that runs under the
..Net framework?

Second, does your application uses ("proper") windows for its user interface
or does it display a character-at-a-time to a console?

If you choose to target the .Net environment, and if you choose a windowed
rather than console application, then you can have the easy I/O model that
seems to be your first choice.

If you choose a native application (which I expect is what you did) you are
in for a bit more work. And as you are asking about how to create a console,
my guess is that you created a native, windowed application (one that starts
at WinMain) but did not create any windows. Of course, I could be wrong.

If that is so, you can create a console with a call to AllocConsole(). You
could use WriteConsole() to direct text there. If you want to use ordinary C
and C++ I/O then you add this little bit of voodoo to your application:

#include <io.h>
#include <stdio.h>
#include <fstream.h>

int fd;
FILE *fp;
HANDLE hCon;

AllocConsole();
hCon = GetStdHandle(STD_OUTPUT_HANDLE);

fd = _open_osfhandle(reinterpret_cast<long>(hCon), 0);
fp = _fdopen(fd, "w");

*stdout = *fp;
setvbuf(stdout, NULL, _IONBF, 0);

Regards,
Will
Dec 23 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Ryan D. Lucey | last post: by
5 posts views Thread by Hendrik Schober | last post: by
2 posts views Thread by electrixnow | last post: by
5 posts views Thread by Mike Krell | last post: by
3 posts views Thread by Wilson | last post: by
8 posts views Thread by mickey22 | last post: by
9 posts views Thread by =?Utf-8?B?SG93YXJkIFNtaXRo?= | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.