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 - painting on a secondary modeless dialog with OnPaint()

MFC - painting on a secondary modeless dialog with OnPaint()

Scheduled Pinned Locked Moved C / C++ / MFC
c++helpquestionannouncementcsharp
7 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.
  • B Offline
    B Offline
    Bonobo8
    wrote on last edited by
    #1

    Hello everybody, I'm new to MFC and after passing several hours trying to solve a problem (that might seem simple to most of you), I decided to post my question here in order to get your help and hints. I'm developing an MFC (C++) application using Visual Studio 2017. The application contains a main CDialog to communicate with a 2D Laser sensor using TCP/IP and to plot the points detected by the sensor on screen in real time (this is done on an IDC_PICTURE element with OnPaint() as the following:

    // I create the pDC, memDC and the compatible device/bitmap
    CDC* pDC = m_Picture.GetDC(); // m_picture is a member CStatic element in the main CDialog class
    CDC memDC;
    CBitmap bmp;
    memDC.CreateCompatibleDC(pDC);
    bmp.CreateCompatibleBitmap(pDC, PicW, PicH); // PicW, PicH are the width and height of the associated CRect member object in the class

    // After that, I get the points to plot in order to write them to my memDC

    //then, I copy the memDC to the device and delete the memDC, release the pDC
    pDC->StretchBlt(0, 0, PicW, PicH, &memDC, 0, 0, PicW, PicH, SRCCOPY);
    bmp.DeleteObject();
    memDC.DeleteDC();
    ReleaseDC(pDC);

    This previously mentioned code is working very well without problems with the main dialog. Long story short, my problem is the following: On that same dialog, I created a button that opens a secondary modeless dialog that contains another IDC_PICTURE element. The main goal of the secondary dialog is to plot a delayed version (t-n) of the points seen by the Laser sensor. My main problem is that I am not being able to show anything on the secondary IDC_PICTURE. Is it wrong to do the same thing applied on the main dialog (on another IDC_PICTURE, with anothe pDC and memDC)? The secondary dialog is defined in a separate class of which I have created an instance in the (first) main CDialog class. I have been looking everywhere on solutions that could look similar to my problem, but I haven't found anything. What exactly am I missing? PS. sorry if my problem description isn't clear enough. My code is getting too big to be copied/pasted.. I'd be very happy if you have any hints / questions that might make me find the solution.. Thanks in advance for your help!

    J L 2 Replies Last reply
    0
    • B Bonobo8

      Hello everybody, I'm new to MFC and after passing several hours trying to solve a problem (that might seem simple to most of you), I decided to post my question here in order to get your help and hints. I'm developing an MFC (C++) application using Visual Studio 2017. The application contains a main CDialog to communicate with a 2D Laser sensor using TCP/IP and to plot the points detected by the sensor on screen in real time (this is done on an IDC_PICTURE element with OnPaint() as the following:

      // I create the pDC, memDC and the compatible device/bitmap
      CDC* pDC = m_Picture.GetDC(); // m_picture is a member CStatic element in the main CDialog class
      CDC memDC;
      CBitmap bmp;
      memDC.CreateCompatibleDC(pDC);
      bmp.CreateCompatibleBitmap(pDC, PicW, PicH); // PicW, PicH are the width and height of the associated CRect member object in the class

      // After that, I get the points to plot in order to write them to my memDC

      //then, I copy the memDC to the device and delete the memDC, release the pDC
      pDC->StretchBlt(0, 0, PicW, PicH, &memDC, 0, 0, PicW, PicH, SRCCOPY);
      bmp.DeleteObject();
      memDC.DeleteDC();
      ReleaseDC(pDC);

      This previously mentioned code is working very well without problems with the main dialog. Long story short, my problem is the following: On that same dialog, I created a button that opens a secondary modeless dialog that contains another IDC_PICTURE element. The main goal of the secondary dialog is to plot a delayed version (t-n) of the points seen by the Laser sensor. My main problem is that I am not being able to show anything on the secondary IDC_PICTURE. Is it wrong to do the same thing applied on the main dialog (on another IDC_PICTURE, with anothe pDC and memDC)? The secondary dialog is defined in a separate class of which I have created an instance in the (first) main CDialog class. I have been looking everywhere on solutions that could look similar to my problem, but I haven't found anything. What exactly am I missing? PS. sorry if my problem description isn't clear enough. My code is getting too big to be copied/pasted.. I'd be very happy if you have any hints / questions that might make me find the solution.. Thanks in advance for your help!

      J Offline
      J Offline
      Jochen Arndt
      wrote on last edited by
      #2

      How is the painting triggered? I guess that you trigger it in the main dialog when new data has been received from the sensor. You have to do it similar for the second modeless dialog (e.g. by triggering a repaint after new data has been passed).

      B 1 Reply Last reply
      0
      • J Jochen Arndt

        How is the painting triggered? I guess that you trigger it in the main dialog when new data has been received from the sensor. You have to do it similar for the second modeless dialog (e.g. by triggering a repaint after new data has been passed).

        B Offline
        B Offline
        Bonobo8
        wrote on last edited by
        #3

        Thanks for your reply! Actually the painting is triggered using the OnTimer() function as follows:

        void CLMS511_interfaceDlg::OnTimer(UINT_PTR nIDEvent)
        {

        // TODO: Add your message handler code here and/or call default
        
        if (nIDEvent == 100)
        {
        	DrawData(); 
        }
        
        
        CDialog::OnTimer(nIDEvent);
        

        }

        I've done the same in the secondary dialog but it didn't change anything.. :/

        J 1 Reply Last reply
        0
        • B Bonobo8

          Hello everybody, I'm new to MFC and after passing several hours trying to solve a problem (that might seem simple to most of you), I decided to post my question here in order to get your help and hints. I'm developing an MFC (C++) application using Visual Studio 2017. The application contains a main CDialog to communicate with a 2D Laser sensor using TCP/IP and to plot the points detected by the sensor on screen in real time (this is done on an IDC_PICTURE element with OnPaint() as the following:

          // I create the pDC, memDC and the compatible device/bitmap
          CDC* pDC = m_Picture.GetDC(); // m_picture is a member CStatic element in the main CDialog class
          CDC memDC;
          CBitmap bmp;
          memDC.CreateCompatibleDC(pDC);
          bmp.CreateCompatibleBitmap(pDC, PicW, PicH); // PicW, PicH are the width and height of the associated CRect member object in the class

          // After that, I get the points to plot in order to write them to my memDC

          //then, I copy the memDC to the device and delete the memDC, release the pDC
          pDC->StretchBlt(0, 0, PicW, PicH, &memDC, 0, 0, PicW, PicH, SRCCOPY);
          bmp.DeleteObject();
          memDC.DeleteDC();
          ReleaseDC(pDC);

          This previously mentioned code is working very well without problems with the main dialog. Long story short, my problem is the following: On that same dialog, I created a button that opens a secondary modeless dialog that contains another IDC_PICTURE element. The main goal of the secondary dialog is to plot a delayed version (t-n) of the points seen by the Laser sensor. My main problem is that I am not being able to show anything on the secondary IDC_PICTURE. Is it wrong to do the same thing applied on the main dialog (on another IDC_PICTURE, with anothe pDC and memDC)? The secondary dialog is defined in a separate class of which I have created an instance in the (first) main CDialog class. I have been looking everywhere on solutions that could look similar to my problem, but I haven't found anything. What exactly am I missing? PS. sorry if my problem description isn't clear enough. My code is getting too big to be copied/pasted.. I'd be very happy if you have any hints / questions that might make me find the solution.. Thanks in advance for your help!

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

          Are you sure that the relevant Windows messages (e.g. WM_PAINT) are being correctly dispatched to the modeless dialog?

          B 1 Reply Last reply
          0
          • L Lost User

            Are you sure that the relevant Windows messages (e.g. WM_PAINT) are being correctly dispatched to the modeless dialog?

            B Offline
            B Offline
            Bonobo8
            wrote on last edited by
            #5

            I'm not sure, I actually don't know what this message is or how to handle it. I'll do the research and get back to you in case of need! Thanks alot!

            L 1 Reply Last reply
            0
            • B Bonobo8

              Thanks for your reply! Actually the painting is triggered using the OnTimer() function as follows:

              void CLMS511_interfaceDlg::OnTimer(UINT_PTR nIDEvent)
              {

              // TODO: Add your message handler code here and/or call default
              
              if (nIDEvent == 100)
              {
              	DrawData(); 
              }
              
              
              CDialog::OnTimer(nIDEvent);
              

              }

              I've done the same in the secondary dialog but it didn't change anything.. :/

              J Offline
              J Offline
              Jochen Arndt
              wrote on last edited by
              #6

              How have you done it in the second dialog? You must pass the data to the second dialog in some way. Then just draw there aftwerwards calling InvalidateWindow() and UpdateWindow(). Or do that from the main dialog using the member variable of the second dialog:

              m_pModeLessDialog->DrawData();

              Both (passing data and trigger redraw from the main dialog), requires that you have a member variable for the second dialog initialised in the button handler when the second dialog is created.

              1 Reply Last reply
              0
              • B Bonobo8

                I'm not sure, I actually don't know what this message is or how to handle it. I'll do the research and get back to you in case of need! Thanks alot!

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

                Bonobo8 wrote:

                I actually don't know what this message is or how to handle it.

                Then you are definitely going to have problems, especially if you are trying to paint the controls at other times. If you do not understand how Window painting works in Windows then you will continue to have problems. I suggest you look for some tutorials on how it is done.

                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