James C
James C

Reputation: 919

Creating a simple window to output information ( log style ) for debugging - wxWidgets

I am learning to create GUI applications with wxWidgets, and since I am still unfamiliar with many of the features and inner workings, I would like to get some information on the processes straight away.

To clarify, if I was creating a simple console application, I could simply printf/cout relevant results, flags,... of the operations to screen, which would help me debug and follow the program flow. But since I am creating a GUI application I don't have a console opened for that. That's why I would like to open, along with the main application, a separate window that would be used to output the debugging information in a log style.

What widget/control could I use to accomplish this task, that is also relatively simple to use ?

Edit: Additional info
I am coding in C++, using wxWidgets 3.0.1 with CodeBlocks 13.12 IDE on a W7 system.

Upvotes: 1

Views: 1455

Answers (3)

VZ.
VZ.

Reputation: 22688

Use wxLogDebug() and view the output under debugger or using a tool such as DebugView under Windows and just directly in the terminal from which you run the application under Unix (including OS X).

If you want to use this for something other than strictly debugging, consider using wxLogVerbose() and wxLogWindow.

Upvotes: 3

Cheers and hth. - Alf
Cheers and hth. - Alf

Reputation: 145239

The easiest is to build your program as a console subsystem executable.

You can build a program as GUI or console subsystem executable regardless of the code.

If you absolutely don't want to do that, then you can just pipe the output of the GUI subsystem program to a console program that copies input to output. Creating a little cat program, or using a *nix-utilities variant, is nice for that. Or you can possibly just use find /v "".


Here's an example Windows API level program:

#include <windows.h>
#include <iostream>
using namespace std;

auto main() -> int
{
    cout << "Well I'm starting up!" << endl;

    auto const infobox = MB_ICONINFORMATION | MB_SETFOREGROUND;
    MessageBox( 0, "Just click OK, OK?", "Blah!", infobox );

    cout << "Yay, I'm finished!" << endl;
}

Building as console subsystem (that's the default for g++) and running:

C:\my\pwd\examples\winhello>g++ w2.cpp

C:\my\pwd\examples\winhello>a
Well I'm starting up!
    Here a message box pops up. Nothing more happens until it's dismissed.
Yay, I'm finished!

C:\my\pwd\examples\winhello>_

Building as GUI subsystem and running:

C:\my\pwd\examples\winhello>g++ w2.cpp -mwindows

C:\my\pwd\examples\winhello>a | find /v ""
Well I'm starting up!
    Here a message box pops up. Nothing more happens until it's dismissed.
Yay, I'm finished!

C:\my\pwd\examples\winhello>_

Note: clog maps to the standard error stream, so to present such output via piping you need to e.g. do a 2>&1.

Upvotes: 0

Non-maskable Interrupt
Non-maskable Interrupt

Reputation: 3911

How about using OutputDebugString with a debugger if you are on Windows 7?

If you really want to do show message in the application itself, try something like a listbox and rotate it for a limited number of messages.

Upvotes: 2

Related Questions