Hello,
I’m running root 4.02 on windows and trying to simply draw a histogram in an MFC application in another window. i have done this several times before by running a TApplication object in the background, but seem to be having trouble updating this particular application to do so and am guessing that it’s something so simple that i’m just overlooking it again and again. basically, the application will either run and just not draw anything (although the canvas will pop up with the appropriate title) or if i change it to try to read a histogram from a file then it will crash when it calls canvas->Update(). The project is a bit too convoluted to post in its entirety, but hopefully the example code from the dialog section is enough to get an idea of what is going on:
/* copied from an example from bellenot*/
VOID CALLBACK MyTimerProc(HWND hwnd, UINT message, UINT idTimer, DWORD dwTime)
{
static bool inloop = false;
if(inloop) return;
inloop = true;
gApplication->StartIdleing();
gSystem->InnerLoop();
gApplication->StopIdleing();
inloop = false;
}
// set up the background TApplication:
CEgViewerDlg::CEgViewerDlg(CWnd* pParent /*=NULL*/)
: CDialog(CEgViewerDlg::IDD, pParent)
{
........
m_app = new TApplication("App",0,0);
}
BOOL CEgViewerDlg::OnInitDialog()
{
CDialog::OnInitDialog();
........
SetTimer(1, 5, (TIMERPROC) MyTimerProc);
}
//button to draw histogram
void CEgViewerDlg::OnDraw() {
UpdateData( TRUE );
m_dc = new TCanvas("can","the canvas"); // member variable
m_dc->Clear();
m_dc->cd();
// just a test histogram to see if it works
TH1F* h1 = new TH1F("h1","test histogram",50,0,50);
h1->SetDirectory(0);
for(int i=0;i<50;i++){
h1-Fill(i,rand());
}
h1-Draw("hist");//
UpdateData(FALSE);
m_dc-Update();
}
Any ideas would be greatly appreciated!
-Reese