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. CView::OnDraw - related question

CView::OnDraw - related question

Scheduled Pinned Locked Moved C / C++ / MFC
questionc++
9 Posts 4 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.
  • T Offline
    T Offline
    tagopi
    wrote on last edited by
    #1

    Hello Everybody, I am new to MFC. I used the application wizard to create a SDI application, I was able to replace the existing menu and toolbar. In this, I added a dialog with some controls. Now, what I need is, whatever the details I got from the dialog controls, I need to display the document view. On CView::OnDraw,I added the code like this. CSDITestDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); if (!pDoc) return; pDC->TextOut(20, 20, L"test sdi", 10); This text is writing only once in the beginning. On closing the dialog, this function is not called, how can I do that? I tried with UpdateAllViews and OnUpdate also. Thanks in advance. A. Gopinath.

    S L C 3 Replies Last reply
    0
    • T tagopi

      Hello Everybody, I am new to MFC. I used the application wizard to create a SDI application, I was able to replace the existing menu and toolbar. In this, I added a dialog with some controls. Now, what I need is, whatever the details I got from the dialog controls, I need to display the document view. On CView::OnDraw,I added the code like this. CSDITestDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); if (!pDoc) return; pDC->TextOut(20, 20, L"test sdi", 10); This text is writing only once in the beginning. On closing the dialog, this function is not called, how can I do that? I tried with UpdateAllViews and OnUpdate also. Thanks in advance. A. Gopinath.

      S Offline
      S Offline
      Sivaraman Dhamodharan
      wrote on last edited by
      #2

      On CView::OnDraw,I added the code like this Really?

      Programming Article

      T 1 Reply Last reply
      0
      • S Sivaraman Dhamodharan

        On CView::OnDraw,I added the code like this Really?

        Programming Article

        T Offline
        T Offline
        tagopi
        wrote on last edited by
        #3

        Ok, I understood what you are trying to say. I added this line only in the existing function. pDC->TextOut(20, 20, L"test sdi", 10); Also, I would request you to read the "How to answer the question", especially, 3rd point.

        1 Reply Last reply
        0
        • T tagopi

          Hello Everybody, I am new to MFC. I used the application wizard to create a SDI application, I was able to replace the existing menu and toolbar. In this, I added a dialog with some controls. Now, what I need is, whatever the details I got from the dialog controls, I need to display the document view. On CView::OnDraw,I added the code like this. CSDITestDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); if (!pDoc) return; pDC->TextOut(20, 20, L"test sdi", 10); This text is writing only once in the beginning. On closing the dialog, this function is not called, how can I do that? I tried with UpdateAllViews and OnUpdate also. Thanks in advance. A. Gopinath.

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

          You need to show some more of your code, as it is not obvious where these different events occur. Pleas also use <pre> tags around your codeblocks so they are readable, like this:

          CSDITestDoc* pDoc = GetDocument();
          ASSERT_VALID(pDoc);
          if (!pDoc)
          return;

          pDC->TextOut(20, 20, L"test sdi", 10);

          T 1 Reply Last reply
          0
          • L Lost User

            You need to show some more of your code, as it is not obvious where these different events occur. Pleas also use <pre> tags around your codeblocks so they are readable, like this:

            CSDITestDoc* pDoc = GetDocument();
            ASSERT_VALID(pDoc);
            if (!pDoc)
            return;

            pDC->TextOut(20, 20, L"test sdi", 10);

            T Offline
            T Offline
            tagopi
            wrote on last edited by
            #5

            Thanks for you reply. Actually, I created one MFC Application using the Template, and its SDI. So, it creates list of files, Doc, View, etc. For View, i select the base class as CView (in the wizard itself). I removed the default created menu and included my menu list. Now, i added a simple dialog, and for that, I created a class also derived from CDialog. Following are the .h and .cpp file contents .h file

            class CSelectOptionsDlg : public CDialog
            {
            public:
            CSelectOptionsDlg(CWnd* pParent = NULL);
            virtual BOOL OnInitDialog();

            public:
            enum {IDD = IDD_SELECTOPTIONSDLG};

            public:
            void OnOkClicked();

            DECLARE\_MESSAGE\_MAP()  
            

            };

            .cpp

            CSelectOptionsDlg::CSelectOptionsDlg(CWnd* pParent)
            : CDialog(CSelectOptionsDlg::IDD, pParent)
            {

            }

            BEGIN_MESSAGE_MAP(CSelectOptionsDlg, CDialog)

            ON\_COMMAND(IDOK, OnOkClicked)
            

            END_MESSAGE_MAP()

            void CSelectOptionsDlg::OnOkClicked()
            {
            AfxMessageBox("Ok clicked");

            EndDialog(1);	
            

            }

            BOOL CSelectOptionsDlg::OnInitDialog()
            {
            CDialog::OnInitDialog();
            return TRUE;
            }

            As I mentioned earlier, if i add this line in OnDraw, its drawing on the first time only,

            pDC->TextOut(20, 20, L"test sdi", 10);

            Also, in MainFrm.cpp file,

            BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
            ON_WM_CREATE()
            ON_COMMAND(ID_START, OnStartPlan )
            ON_COMMAND(ID_STOP, OnStopPlan )
            ON_COMMAND(ID_SELECTOPTIONS, OnSelectOption )
            ON_COMMAND(ID_EXIT, OnExit )
            END_MESSAGE_MAP()

            void CMainFrame::OnSelectOption()
            {
            CSelectOptionsDlg cSODlg;
            cSODlg.DoModal();
            }

            doing like this. OnDraw is not calling everytime. What I need is, whenever i click ok and close the dialog, OnDraw need to be called. How can i do that? Any help. Thanks.

            L 1 Reply Last reply
            0
            • T tagopi

              Thanks for you reply. Actually, I created one MFC Application using the Template, and its SDI. So, it creates list of files, Doc, View, etc. For View, i select the base class as CView (in the wizard itself). I removed the default created menu and included my menu list. Now, i added a simple dialog, and for that, I created a class also derived from CDialog. Following are the .h and .cpp file contents .h file

              class CSelectOptionsDlg : public CDialog
              {
              public:
              CSelectOptionsDlg(CWnd* pParent = NULL);
              virtual BOOL OnInitDialog();

              public:
              enum {IDD = IDD_SELECTOPTIONSDLG};

              public:
              void OnOkClicked();

              DECLARE\_MESSAGE\_MAP()  
              

              };

              .cpp

              CSelectOptionsDlg::CSelectOptionsDlg(CWnd* pParent)
              : CDialog(CSelectOptionsDlg::IDD, pParent)
              {

              }

              BEGIN_MESSAGE_MAP(CSelectOptionsDlg, CDialog)

              ON\_COMMAND(IDOK, OnOkClicked)
              

              END_MESSAGE_MAP()

              void CSelectOptionsDlg::OnOkClicked()
              {
              AfxMessageBox("Ok clicked");

              EndDialog(1);	
              

              }

              BOOL CSelectOptionsDlg::OnInitDialog()
              {
              CDialog::OnInitDialog();
              return TRUE;
              }

              As I mentioned earlier, if i add this line in OnDraw, its drawing on the first time only,

              pDC->TextOut(20, 20, L"test sdi", 10);

              Also, in MainFrm.cpp file,

              BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
              ON_WM_CREATE()
              ON_COMMAND(ID_START, OnStartPlan )
              ON_COMMAND(ID_STOP, OnStopPlan )
              ON_COMMAND(ID_SELECTOPTIONS, OnSelectOption )
              ON_COMMAND(ID_EXIT, OnExit )
              END_MESSAGE_MAP()

              void CMainFrame::OnSelectOption()
              {
              CSelectOptionsDlg cSODlg;
              cSODlg.DoModal();
              }

              doing like this. OnDraw is not calling everytime. What I need is, whenever i click ok and close the dialog, OnDraw need to be called. How can i do that? Any help. Thanks.

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

              As far as I recall from my MFC days, a Window's OnDraw() procedure will get called when the dialog closes, so this should happen automatically. Unfortunately that's the part of the code that you did not show us. You may like to add some breakpoints and use your debugger to see the flow of code when the dialog closes.

              T 1 Reply Last reply
              0
              • L Lost User

                As far as I recall from my MFC days, a Window's OnDraw() procedure will get called when the dialog closes, so this should happen automatically. Unfortunately that's the part of the code that you did not show us. You may like to add some breakpoints and use your debugger to see the flow of code when the dialog closes.

                T Offline
                T Offline
                tagopi
                wrote on last edited by
                #7

                Hello Richard, I debug the whole code by putting breakpoints in all the functions, after closing the dialog, its not going anywhere in the code, remains on the application itself. I am attaching the code herewith. Please download and check. http://www.4shared.com/zip/eDwcyehu/SDITest.html[^] Thanks.

                L 1 Reply Last reply
                0
                • T tagopi

                  Hello Richard, I debug the whole code by putting breakpoints in all the functions, after closing the dialog, its not going anywhere in the code, remains on the application itself. I am attaching the code herewith. Please download and check. http://www.4shared.com/zip/eDwcyehu/SDITest.html[^] Thanks.

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

                  Sorry, I cannot download that. you need to check that your OnDraw() function is being activated properly. If necessary you may need to add a call to UploadAllViews() after the dialog closes.

                  1 Reply Last reply
                  0
                  • T tagopi

                    Hello Everybody, I am new to MFC. I used the application wizard to create a SDI application, I was able to replace the existing menu and toolbar. In this, I added a dialog with some controls. Now, what I need is, whatever the details I got from the dialog controls, I need to display the document view. On CView::OnDraw,I added the code like this. CSDITestDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); if (!pDoc) return; pDC->TextOut(20, 20, L"test sdi", 10); This text is writing only once in the beginning. On closing the dialog, this function is not called, how can I do that? I tried with UpdateAllViews and OnUpdate also. Thanks in advance. A. Gopinath.

                    C Offline
                    C Offline
                    chaau
                    wrote on last edited by
                    #9

                    To force the window to redraw (any window, not only view) you need to call CWnd::Invalidate()[^] method. Calling it will trigger all the drawing routines

                    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