I like using a log
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:
#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");
//}
//
Hi, could you elaborate more on first solution? In submitted code
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
Hi, could you elaborate more on first solution? In submitted code
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
::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
::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.