Author Topic: How can I add a console window into message pane ??  (Read 6214 times)

zlly20

  • Guest
How can I add a console window into message pane ??
« on: February 16, 2006, 04:19:28 pm »
Because my program can print out some message to console for debugging purpose.
but I can't find anywhere in C::B to add a console into message pane.. Is this possible in C::B????

Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2162
Re: How can I add a console window into message pane ??
« Reply #1 on: February 16, 2006, 06:14:30 pm »
I like using a log
Code: [Select]
    pMyLog = 0;
    #if LOGGING
        wxWindow* pcbWindow = frame;
        /*wxLogWindow**/ pMyLog = new wxLogWindow(pcbWindow,"wxScroll Log");
        wxLog::SetActiveTarget(pMyLog);
        wxLogMessage("Logging wxScroll");
        pMyLog->Flush();
        pMyLog->GetFrame()->Move(20,20);
#endif

But you can use a console:
Code: [Select]
#include <cstdlib>
#include <iostream>
#include <windows.h>
using namespace std;
#define NOT !
    FILE* phOut = NULL;
    FILE* phIn = NULL;
    FILE* phErr = NULL;
    HANDLE hConsole = NULL;
    HANDLE hConsoleIn, hConsoleOut, hConsoleErr;
    DWORD  oldMode, newMode;
//----------------------------------------------------
int createConsole(VOID)
//----------------------------------------------------
{// create a console for debugging and lurking

    if(phOut) {fclose(phOut); phErr=NULL;}
    if (phIn) {fclose(phIn); phErr=NULL;}
    if (phErr) {fclose(phErr); phErr=NULL;}

    if (hConsole) FreeConsole();
    hConsole=0;
    hConsoleIn=NULL;

    hConsole = (HANDLE)AllocConsole();
    if (NOT hConsole) return FALSE;
    if (hConsole)
     { hConsoleIn=GetStdHandle(STD_INPUT_HANDLE);
       hConsoleOut=GetStdHandle(STD_OUTPUT_HANDLE);
       hConsoleErr=GetStdHandle(STD_ERROR_HANDLE);
     }


    phIn=freopen("CONIN$", "r", stdin);
    phOut=freopen("CONOUT$", "a", stdout);

    //-next line doent work for cerr. it's opening a diskfile
    //-freopen("CONERR$", "a", stderr);

    phErr=freopen("CONOUT$", "a", stderr);

    //clear any errors that occured while console was closed
    cout.clear();
    cerr.clear();
    cin.clear();
    clog.clear();

//    cout<<"phIn:"<<phIn<<endl;
//    cout<<"phOut:"<<phOut<<endl;
//    cout<<"phErr:"<<phErr<<endl;
//
//     cout<<"Std Input Handle :"<<hConsoleIn<<endl;
//     cout<<"Std Output Handle:"<<hConsoleOut<<endl;
//     cout<<"Std Error Handle :"<<hConsoleErr<<endl;

    ios::sync_with_stdio();

    //preserve console input mode
    if (! GetConsoleMode(hConsoleIn,&oldMode))
     { cout<<"GetConsoleMode";
     }
    //-cout<<"ConsoleMode"<<hex<<oldMode<<dec<<endl;

    //turn off echo and full line mode
    newMode= oldMode & ~(ENABLE_ECHO_INPUT | ENABLE_LINE_INPUT );
    if (! SetConsoleMode(hConsoleIn,newMode))
     { cout<<"SetConsoleMode";
     }

//    debugging:
//    cout << "Test: cout output" << endl;
//    cerr<<"Test: cerr<<Line from \n";
//    printf("Test: printf line of output\n");

    return (int)hConsole;

}//createConsole
//-------------------------------------------------
// ----------------------------------------------------------------------------
////-void CodeBlocksApp::InitDebugConsole()
//void InitDebugConsole()
//// ----------------------------------------------------------------------------
//{
//    AllocConsole();
//    HANDLE myhandle = GetStdHandle(STD_OUTPUT_HANDLE);
// COORD co = {80,2000};
// SetConsoleScreenBufferSize(myhandle, co);
// fprintf(stdout,"CONSOLE DEBUG ACTIVATED\n");
// // wxLogWindow *myerr = new wxLogWindow(NULL,"debug");
//}
//


Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: How can I add a console window into message pane ??
« Reply #2 on: February 16, 2006, 06:20:28 pm »
If you build your program as console application, it will have a console. Whatever you print will appear there.

It is not possible to dock it inside Code::Blocks, though.
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

Offline cecilio

  • Multiple posting newcomer
  • *
  • Posts: 17
Re: How can I add a console window into message pane ??
« Reply #3 on: June 30, 2007, 05:28:46 pm »
Hi, could you elaborate more on first solution? In submitted code
Code: [Select]
    pMyLog = 0;
    #if LOGGING
        wxWindow* pcbWindow = frame;
        /*wxLogWindow**/ pMyLog = new wxLogWindow(pcbWindow,"wxScroll Log");
        wxLog::SetActiveTarget(pMyLog);
        wxLogMessage("Logging wxScroll");
        pMyLog->Flush();
        pMyLog->GetFrame()->Move(20,20);
#endif

what is 'frame'?. How do you get that pointer?.

Thank you

Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2162
Re: How can I add a console window into message pane ??
« Reply #4 on: June 30, 2007, 07:12:26 pm »
Hi, could you elaborate more on first solution? In submitted code
Code: [Select]
    pMyLog = 0;
    #if LOGGING
        wxWindow* pcbWindow = frame;
        /*wxLogWindow**/ pMyLog = new wxLogWindow(pcbWindow,"wxScroll Log");
        wxLog::SetActiveTarget(pMyLog);
        wxLogMessage("Logging wxScroll");
        pMyLog->Flush();
        pMyLog->GetFrame()->Move(20,20);
#endif

what is 'frame'?. How do you get that pointer?.

Thank you

From the wxWidgets documentation
Code: [Select]
::wxGetActiveWindow
wxWindow * wxGetActiveWindow()

Gets the currently active window (implemented for MSW and GTK only currently, always returns NULL in the other ports).

Include files

<wx/window.h>

or
Code: [Select]
::wxGetTopLevelParent
wxWindow * wxGetTopLevelParent(wxWindow *win)

Returns the first top level parent of the given window, or in other words, the frame or dialog containing it, or NULL.

Include files

<wx/window.h>

Most likely, you just created a frame from your wxApp. Use that pointer.
Look at the samples in wxWidgets.


Use the CodeBlocks wizard to create a wxWidgets graphics program.
It creates a wxApp and a wxFrame for you.
« Last Edit: June 30, 2007, 07:15:24 pm by Pecan »

Offline cecilio

  • Multiple posting newcomer
  • *
  • Posts: 17
Re: How can I add a console window into message pane ??
« Reply #5 on: July 02, 2007, 05:27:08 pm »
Thank you. So it is a window in my app. I though 'frame' was a pointer to a Code::Blocks message pane!

Best regards,
Cecilio