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
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. MFC Programming using SDI

MFC Programming using SDI

Scheduled Pinned Locked Moved C / C++ / MFC
c++helptutorial
4 Posts 3 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.
  • C Offline
    C Offline
    charu123
    wrote on last edited by
    #1

    HI, I am new to mFC programming . I ahve been trying to create an application where a figure is drawn with a default colour and then user can select from a range of colours in the menu. The problem wid my application is that it is not accepting the new colour when i check it. It is supposed to draw the new figure in a different colour when I select a colour from the menu. I might be going wrong somewhr. could anyone tell me how to go about doing what I am trying to implement. Thanks U get wht u Give

    D 1 Reply Last reply
    0
    • C charu123

      HI, I am new to mFC programming . I ahve been trying to create an application where a figure is drawn with a default colour and then user can select from a range of colours in the menu. The problem wid my application is that it is not accepting the new colour when i check it. It is supposed to draw the new figure in a different colour when I select a colour from the menu. I might be going wrong somewhr. could anyone tell me how to go about doing what I am trying to implement. Thanks U get wht u Give

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      Are you drawing the figure in the OnDraw() or OnPaint() method? Where are you storing the new color value? Is it being used?


      "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

      C 1 Reply Last reply
      0
      • D David Crow

        Are you drawing the figure in the OnDraw() or OnPaint() method? Where are you storing the new color value? Is it being used?


        "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

        C Offline
        C Offline
        charu123
        wrote on last edited by
        #3

        I am using the ondraw function. I have a variable called color in the doc class and a function which returns the current colour. I ma calling this function in the ondraw function to get the colour. Below is the code of ondraw function and the doc class.. void CFiguresdiView::OnDraw(CDC* pDC) { CFiguresdiDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); // TODO: add draw code for native data here COLORREF m_nColor = pDoc->GetCurrentColor(); CBrush brush (m_nColor); int x1 = 100; int y1 = 100; int x2 = 300; int y2 = 400; CRect rect (x1, y1, x2, y2); pDC->FillRect (rect, &brush); } In the document class i ahve the following code. COLORREF CFiguresdiDoc::GetCurrentColor() { return m_nColor; } void CFiguresdiDoc::OnColorsRed() { m_nColor=RGB (255,0,0); } void CFiguresdiDoc::OnColorsGreen() { m_nColor = RGB(0,255,0);// TODO: Add your command handler code here } void CFiguresdiDoc::OnUpdateColorsGreen(CCmdUI* pCmdUI) { pCmdUI->SetCheck (m_nColor == RGB (0, 255, 0)); } void CFiguresdiDoc::OnUpdateColorsRed(CCmdUI* pCmdUI) { pCmdUI->SetCheck (m_nColor == RGB (0, 255, 255));// TODO: Add your command update UI handler code here } m_nColor is of type COLORREF. i AHVE SET THE DEFAULT COLOR AS RED . It is set in the onNew Document function. IF i try doing the same thing on OnButtonDown event of mouse in the client area the color does change. I am not able to figure out how i can click on the colour in the menu and as soon as i click the menu option the Figure gets redrawn with the chosen colour. I probably need to write some message map but i cant figure out how. Thanks david

        A 1 Reply Last reply
        0
        • C charu123

          I am using the ondraw function. I have a variable called color in the doc class and a function which returns the current colour. I ma calling this function in the ondraw function to get the colour. Below is the code of ondraw function and the doc class.. void CFiguresdiView::OnDraw(CDC* pDC) { CFiguresdiDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); // TODO: add draw code for native data here COLORREF m_nColor = pDoc->GetCurrentColor(); CBrush brush (m_nColor); int x1 = 100; int y1 = 100; int x2 = 300; int y2 = 400; CRect rect (x1, y1, x2, y2); pDC->FillRect (rect, &brush); } In the document class i ahve the following code. COLORREF CFiguresdiDoc::GetCurrentColor() { return m_nColor; } void CFiguresdiDoc::OnColorsRed() { m_nColor=RGB (255,0,0); } void CFiguresdiDoc::OnColorsGreen() { m_nColor = RGB(0,255,0);// TODO: Add your command handler code here } void CFiguresdiDoc::OnUpdateColorsGreen(CCmdUI* pCmdUI) { pCmdUI->SetCheck (m_nColor == RGB (0, 255, 0)); } void CFiguresdiDoc::OnUpdateColorsRed(CCmdUI* pCmdUI) { pCmdUI->SetCheck (m_nColor == RGB (0, 255, 255));// TODO: Add your command update UI handler code here } m_nColor is of type COLORREF. i AHVE SET THE DEFAULT COLOR AS RED . It is set in the onNew Document function. IF i try doing the same thing on OnButtonDown event of mouse in the client area the color does change. I am not able to figure out how i can click on the colour in the menu and as soon as i click the menu option the Figure gets redrawn with the chosen colour. I probably need to write some message map but i cant figure out how. Thanks david

          A Offline
          A Offline
          Anonymous
          wrote on last edited by
          #4

          Use: InvalidateRect(NULL);

          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