Problems displaying output from vc++ program

  • Thread starter Thread starter royzeb
  • Start date Start date
R

royzeb

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!!
 
royzeb said:
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
 
Back
Top