Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Error displaying CFrameWnd

Error displaying CFrameWnd

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestionlearning
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    raner
    wrote on last edited by
    #1

    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); }

    L 1 Reply Last reply
    0
    • R raner

      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); }

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      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

      R 1 Reply Last reply
      0
      • L Lost User

        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

        R Offline
        R Offline
        raner
        wrote on last edited by
        #3

        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

        L 1 Reply Last reply
        0
        • R raner

          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

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups