Error displaying CFrameWnd
-
Hi I'm a beginner in VC. I created a CObject-derived class (CGraphPlotter below).One of its functions create an CFrameWnd object, draw something and then try to display it on the frame.Below is the extract.. But it runs into exception error and i think the problem lies with ShowWindow().I don't know what to do.Invalidate doesnt work too.Can anyone help?Thks.
void CGraphPlotter::CreatePlot(CString title) { RECT rect; POINT pt; RECT windowSize; CFrameWnd *pwndPlot = new CFrameWnd; windowSize.left = 0; windowSize.top = 0; windowSize.bottom = 300; windowSize.right = 600; pwndPlot->Create(NULL,title,WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX,windowSize,NULL,NULL,0,NULL); pwndPlot->GetClientRect(&rect); pt.x=rect.right; pt.y=rect.bottom; CPaintDC dc(pwndPlot); CPen plotPen; CPen *pOldPen; POINT pt; plotPen.CreatePen(PS_SOLID,0,RGB(200,0,0)); pOldPen=dc.SelectObject(&plotPen); double m_sampleData[5]; int m_sampleXAxis[5]; dc.MoveTo(0,0); for(int i=0;i<4;i++) { pt.x=m_sampleXAxis[i]; pt.y = m_sampleData[i]; dc.LineTo(pt); } pwndPlot->ShowWindow(SW_SHOW); }
-
Hi I'm a beginner in VC. I created a CObject-derived class (CGraphPlotter below).One of its functions create an CFrameWnd object, draw something and then try to display it on the frame.Below is the extract.. But it runs into exception error and i think the problem lies with ShowWindow().I don't know what to do.Invalidate doesnt work too.Can anyone help?Thks.
void CGraphPlotter::CreatePlot(CString title) { RECT rect; POINT pt; RECT windowSize; CFrameWnd *pwndPlot = new CFrameWnd; windowSize.left = 0; windowSize.top = 0; windowSize.bottom = 300; windowSize.right = 600; pwndPlot->Create(NULL,title,WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX,windowSize,NULL,NULL,0,NULL); pwndPlot->GetClientRect(&rect); pt.x=rect.right; pt.y=rect.bottom; CPaintDC dc(pwndPlot); CPen plotPen; CPen *pOldPen; POINT pt; plotPen.CreatePen(PS_SOLID,0,RGB(200,0,0)); pOldPen=dc.SelectObject(&plotPen); double m_sampleData[5]; int m_sampleXAxis[5]; dc.MoveTo(0,0); for(int i=0;i<4;i++) { pt.x=m_sampleXAxis[i]; pt.y = m_sampleData[i]; dc.LineTo(pt); } pwndPlot->ShowWindow(SW_SHOW); }
you have to write the painting code in OnDraw. If you write before, the next time the window paints, whatever you did will get erased. To do that, you have to create a class CPlotterWnd derived from CFrameWnd and override the OnDraw... although drawing in a frame window is not eh correct way. Framewindow is used to host other windows like views, which inturn display the data. If you have access to MSDN, it explains it quite well. .. or you have to get a book on MFC. My article on a reference-counted smart pointer that supports polymorphic objects and raw pointers
-
you have to write the painting code in OnDraw. If you write before, the next time the window paints, whatever you did will get erased. To do that, you have to create a class CPlotterWnd derived from CFrameWnd and override the OnDraw... although drawing in a frame window is not eh correct way. Framewindow is used to host other windows like views, which inturn display the data. If you have access to MSDN, it explains it quite well. .. or you have to get a book on MFC. My article on a reference-counted smart pointer that supports polymorphic objects and raw pointers
I've gone and read up on MSDN.I understood the concept much better and i hope to use the correct way. My application is a SDI and i want to display a graph in the CPlotterWnd(CFrameWnd-derived). Am i right to interpret that i should probably derive CGraphPlotter from CView instead? And to associate them together, can i CREATE CPlotterWnd in CGraphPlotter? thks
-
I've gone and read up on MSDN.I understood the concept much better and i hope to use the correct way. My application is a SDI and i want to display a graph in the CPlotterWnd(CFrameWnd-derived). Am i right to interpret that i should probably derive CGraphPlotter from CView instead? And to associate them together, can i CREATE CPlotterWnd in CGraphPlotter? thks
yes. you are better off creating a view for that. If that is the only view that you want, implement your graph plotting in the default view. But, if you want multiple views that look different from the same data, you can create multiple view classes. MSDN has some doumentation on using multiple view types with SDI applications. Or you can create another view class, host it inside another frame derived class... and create the framewindow, when you click a menu item or a toolbar button. This way, you can create multiple windows showing the same data in different display formats. But, read up on the multiple view handling on SDI before you go out and implement it this way. My article on a reference-counted smart pointer that supports polymorphic objects and raw pointers