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. How to move cirlce in MFC?

How to move cirlce in MFC?

Scheduled Pinned Locked Moved C / C++ / MFC
questionc++tutorial
10 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.
  • S Offline
    S Offline
    Shirani
    wrote on last edited by
    #1

    Hey how can i move CClientDC object in client window using mouse ? i did it but it show last cicle on screen. If i do Invalidate to TRUE it moves the circle but did'nt show properly in Dialog box. if((nFlags & MK_LBUTTON)==MK_LBUTTON) { CClientDC obj(this); x=(point.x)-50; y=(point.y)-50; obj.Ellipse(x,y,x+100,y+100); } Invalidate(FALSE); So what should i do ???

    Regards: Xohaib Shirani

    CPalliniC 1 Reply Last reply
    0
    • S Shirani

      Hey how can i move CClientDC object in client window using mouse ? i did it but it show last cicle on screen. If i do Invalidate to TRUE it moves the circle but did'nt show properly in Dialog box. if((nFlags & MK_LBUTTON)==MK_LBUTTON) { CClientDC obj(this); x=(point.x)-50; y=(point.y)-50; obj.Ellipse(x,y,x+100,y+100); } Invalidate(FALSE); So what should i do ???

      Regards: Xohaib Shirani

      CPalliniC Online
      CPalliniC Online
      CPallini
      wrote on last edited by
      #2

      You've to put the drawing stuff inside the WM_PAINT handler. Then you'll ask for an update (outside of the above handler) whenever appropriate (for instance using a timer if you need to move continuosly). :)

      If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
      This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke

      In testa che avete, signor di Ceprano?

      S 1 Reply Last reply
      0
      • CPalliniC CPallini

        You've to put the drawing stuff inside the WM_PAINT handler. Then you'll ask for an update (outside of the above handler) whenever appropriate (for instance using a timer if you need to move continuosly). :)

        If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
        This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke

        S Offline
        S Offline
        Shirani
        wrote on last edited by
        #3

        CPaintDC obj(this); x=(point.x)-50; y=(point.y)-50; obj.Ellipse(x,y,x+100,y+100); it didn't work.And i also tried this by defining CPaintDC obj in OnPaint fucntion x=(point.x)-50; y=(point.y)-50; CDC *ptr=CDialog::GetDC(); ptr->Ellipse(x,y,x+100,y+100); these both are not working.

        Regards: Xohaib Shirani

        CPalliniC 1 Reply Last reply
        0
        • S Shirani

          CPaintDC obj(this); x=(point.x)-50; y=(point.y)-50; obj.Ellipse(x,y,x+100,y+100); it didn't work.And i also tried this by defining CPaintDC obj in OnPaint fucntion x=(point.x)-50; y=(point.y)-50; CDC *ptr=CDialog::GetDC(); ptr->Ellipse(x,y,x+100,y+100); these both are not working.

          Regards: Xohaib Shirani

          CPalliniC Online
          CPalliniC Online
          CPallini
          wrote on last edited by
          #4

          What do you mean with: "doesn't work"? Please detail. :) BTW you have to use CPaintDC dc(this); inside the OnPaint handler.

          If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
          This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke

          In testa che avete, signor di Ceprano?

          S 1 Reply Last reply
          0
          • CPalliniC CPallini

            What do you mean with: "doesn't work"? Please detail. :) BTW you have to use CPaintDC dc(this); inside the OnPaint handler.

            If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
            This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke

            S Offline
            S Offline
            Shirani
            wrote on last edited by
            #5

            Yes dear i add CPaintDC obj(this); but it doesn't work properly. It leave the last effect of circle mean it moves the circle but the some effects of circle remain on the screen.

            Regards: Xohaib Shirani

            CPalliniC 1 Reply Last reply
            0
            • S Shirani

              Yes dear i add CPaintDC obj(this); but it doesn't work properly. It leave the last effect of circle mean it moves the circle but the some effects of circle remain on the screen.

              Regards: Xohaib Shirani

              CPalliniC Online
              CPalliniC Online
              CPallini
              wrote on last edited by
              #6

              Shirani wrote:

              It leave the last effect of circle mean it moves the circle but the some effects of circle remain on the screen.

              :confused: Do you properly invalidate the painting area?

              If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
              This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke

              In testa che avete, signor di Ceprano?

              S 1 Reply Last reply
              0
              • CPalliniC CPallini

                Shirani wrote:

                It leave the last effect of circle mean it moves the circle but the some effects of circle remain on the screen.

                :confused: Do you properly invalidate the painting area?

                If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke

                S Offline
                S Offline
                Shirani
                wrote on last edited by
                #7

                yes if i invalidate the painting area it hides the circle after moving it, You can check it by urself.

                Regards: Xohaib Shirani

                CPalliniC R 2 Replies Last reply
                0
                • S Shirani

                  yes if i invalidate the painting area it hides the circle after moving it, You can check it by urself.

                  Regards: Xohaib Shirani

                  CPalliniC Online
                  CPalliniC Online
                  CPallini
                  wrote on last edited by
                  #8

                  I made a test, and, of course ;P , it works well.

                  If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                  This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke

                  In testa che avete, signor di Ceprano?

                  1 Reply Last reply
                  0
                  • S Shirani

                    yes if i invalidate the painting area it hides the circle after moving it, You can check it by urself.

                    Regards: Xohaib Shirani

                    R Offline
                    R Offline
                    Rajkumar R
                    wrote on last edited by
                    #9

                    Where you are calling Invalidate, is it after painting in the OnPaint Handler? And are you still drawing in the move handler? In the Move Handler just update the position to member variable and invalidate the client region, invalidate will cause the paint to happen, And in your OnPaint Handler draw the ellipse, don't call invalidate in OnPaint Handler. If you are not painting the background by overriding the OnEraseBkgnd method, then also previous ellipse remains on the DC.

                    S 1 Reply Last reply
                    0
                    • R Rajkumar R

                      Where you are calling Invalidate, is it after painting in the OnPaint Handler? And are you still drawing in the move handler? In the Move Handler just update the position to member variable and invalidate the client region, invalidate will cause the paint to happen, And in your OnPaint Handler draw the ellipse, don't call invalidate in OnPaint Handler. If you are not painting the background by overriding the OnEraseBkgnd method, then also previous ellipse remains on the DC.

                      S Offline
                      S Offline
                      Shirani
                      wrote on last edited by
                      #10

                      i invalidate in OnmouseMove handler not in onPaint function

                      Regards: Xohaib Shirani

                      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