Author Topic: stdout in GUI apps  (Read 10942 times)

SartriX

  • Guest
stdout in GUI apps
« on: May 08, 2005, 12:11:08 am »
This is something I always liked back in the old days with Visual Cafe (java)... Even if you made a GUI-based application, it would still dump whatever messages you sent to stdout into the same textbox that holds the compiler- and run- messages. Hidden when the app was built and distributed, but a great way of outputting quick debug info while you executed inside the IDE.

Would you be so kind to add this to C::B ? :)

Offline Profic

  • Multiple posting newcomer
  • *
  • Posts: 56
stdout in GUI apps
« Reply #1 on: May 08, 2005, 12:35:01 am »
AFAIK it's impossible in Windows (but I can mistake :)), as GUI applications do not have stdout opend by default, so to make thing like you described one at least need to write library and link it to all GUI application, while not touching non-GUI ones.
Moreover even if such library became written it might do tricky and non-portable think to init itself...

PS. I didn't want to say that it's impossible at all :), but that's very hard to implement in portable (as C::B is portable) way
May be you are looking for wxLog (er, not shure about name) and friends?
Not fear, nor tears can reach me now, the light seems so clear as the night fades away (c) Tristania - Beyond The Veil

Offline rickg22

  • Lives here!
  • ****
  • Posts: 2283
stdout in GUI apps
« Reply #2 on: May 08, 2005, 01:06:37 am »
I *GOT* an idea. And i've been thinking about using it in codeblocks itself! The idea:

Using a *SEPARATE* log program. Actually a DDE / TCP server. The communication is done with a simple wxWidgets class (wxServer / wxClient). The program to be debugged would create a client class, that it would test for the server. The server would simply accept the messages and print them accordingly.

It shouldn't (repeat: SHOULDn't) be hard to implement. Any volunteer? :D

Anonymous

  • Guest
stdout in GUI apps
« Reply #3 on: May 08, 2005, 09:42:45 am »
Actually.. I like Profic's idea if you'ld simply combine it with a log-box (along with the tabs for compiler/warnings/debug/etc at the bottom of C::B) which you can just assign a (log)file too and effectively just does a tail -f on it to display the contents as it grows. Anyone can just use their own way of logging, the only thing C::B needs is the tail -f box.

Offline Profic

  • Multiple posting newcomer
  • *
  • Posts: 56
stdout in GUI apps
« Reply #4 on: May 10, 2005, 12:05:42 pm »
Seems I was mistaken :)
A simple program (listed below) compiled with mingw's gcc works fine - std::cerr do nothing if ran by double clicking it while outputing to file if ran as test0.exe 2>err.txt in cmd's prompt.
If it works so with others compilers to, it is easy to implement such thing by redirecting stderr to one of tabs below editor window.
Nevertheless this feature seems be reasonable even if program do not work well with all compilers, as most programs use its stderr fo logging debug info :)

Code (filename test0.cpp)
Code
#include <iostream>
#include <sstream>
#include <typeinfo>
#include <windows.h>

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) {
std::stringstream l_str;
l_str << std::cerr.rdstate() << " : ";
std::basic_streambuf<char>* l_strbuf = std::cerr.rdbuf();
l_str << static_cast<void*>(l_strbuf) << " : ";
l_str << typeid(l_strbuf).name() << " : ";

std::cerr << "before MessageBox()" << std::endl;
MessageBoxA(NULL, l_str.str().c_str(), "std::cerr status", MB_OK);
std::cerr << "after MessageBox()" << std::endl;
}


PS: "Preview" button stopped working - it redirect me to index page of c::b site
Not fear, nor tears can reach me now, the light seems so clear as the night fades away (c) Tristania - Beyond The Veil