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. upper drawing layer

upper drawing layer

Scheduled Pinned Locked Moved C / C++ / MFC
graphicsperformancehelptutorialannouncement
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.
  • M Offline
    M Offline
    MKUser
    wrote on last edited by
    #1

    If i draw some image, lines, rectangles etc. in OnPain() of dialog box then it takes some time. Suppose i draw image,rectangle on mouse click and release event. I can call repaint from mouse click/release function and it's working fine. But suppose if i want to draw some lines on mouse move function then i need to call repaint from mouse move function and it gives flickering problem. To solve this i plan to draw image, rectangle etc in a memory device context on mouse click/release functions. and for mouse move first i'll draw data from memory device context and then i'll draw line on top of it. But it's not working. Can someone give any example to solve that problem.

    Manoj Kumar Chauhan

    S I K 3 Replies Last reply
    0
    • M MKUser

      If i draw some image, lines, rectangles etc. in OnPain() of dialog box then it takes some time. Suppose i draw image,rectangle on mouse click and release event. I can call repaint from mouse click/release function and it's working fine. But suppose if i want to draw some lines on mouse move function then i need to call repaint from mouse move function and it gives flickering problem. To solve this i plan to draw image, rectangle etc in a memory device context on mouse click/release functions. and for mouse move first i'll draw data from memory device context and then i'll draw line on top of it. But it's not working. Can someone give any example to solve that problem.

      Manoj Kumar Chauhan

      S Offline
      S Offline
      ShilpiP
      wrote on last edited by
      #2

      Which device context you are using on window mouse message handler and are you using ::ReleaseCapture funtion after releasing mouse.If possible pls give me code to understand your problem.

      Yes U Can ...If U Can ,Dream it , U can do it ...ICAN

      M 1 Reply Last reply
      0
      • S ShilpiP

        Which device context you are using on window mouse message handler and are you using ::ReleaseCapture funtion after releasing mouse.If possible pls give me code to understand your problem.

        Yes U Can ...If U Can ,Dream it , U can do it ...ICAN

        M Offline
        M Offline
        MKUser
        wrote on last edited by
        #3

        The code is simple. Just Create a dialog base application. Add a static control on dialog box. Make a class for this static control(derived from CStatic). Now draw in this class. In Onpaint() of this class draw some image,rectangle, lines etc. Add all mouse functions in this class. Call Invalidate() from mouse click/release functions. Upto now there is no problem. Now call Invalidate() from mouse move function. You'll see flickering. To solve it take an offscreen buffer. Create image/rectangle in offscreen buffer and draw it on view when Invalidate() is call from mouse click/release function. Otherwise form mouse move function, dont create offscreen buffer, just use previously created offscreen buffer and draw it on view. Then draw lines. I'm not using any capture function like ReleaseCapture(). When i dtied this then i can see only lines. I cant see any image/rectangle. What i want I want a 2 layers. bottom layer should contains image and rectangle and top layer contains only lines.

        Manoj Kumar Chauhan

        S 1 Reply Last reply
        0
        • M MKUser

          The code is simple. Just Create a dialog base application. Add a static control on dialog box. Make a class for this static control(derived from CStatic). Now draw in this class. In Onpaint() of this class draw some image,rectangle, lines etc. Add all mouse functions in this class. Call Invalidate() from mouse click/release functions. Upto now there is no problem. Now call Invalidate() from mouse move function. You'll see flickering. To solve it take an offscreen buffer. Create image/rectangle in offscreen buffer and draw it on view when Invalidate() is call from mouse click/release function. Otherwise form mouse move function, dont create offscreen buffer, just use previously created offscreen buffer and draw it on view. Then draw lines. I'm not using any capture function like ReleaseCapture(). When i dtied this then i can see only lines. I cant see any image/rectangle. What i want I want a 2 layers. bottom layer should contains image and rectangle and top layer contains only lines.

          Manoj Kumar Chauhan

          S Offline
          S Offline
          ShilpiP
          wrote on last edited by
          #4

          are you using CClientDC device context or CPaintDC on OnMouseMove function ? And when i see your code it is clear for me where is the problem?

          Yes U Can ...If U Can ,Dream it , U can do it ...ICAN

          M 1 Reply Last reply
          0
          • M MKUser

            If i draw some image, lines, rectangles etc. in OnPain() of dialog box then it takes some time. Suppose i draw image,rectangle on mouse click and release event. I can call repaint from mouse click/release function and it's working fine. But suppose if i want to draw some lines on mouse move function then i need to call repaint from mouse move function and it gives flickering problem. To solve this i plan to draw image, rectangle etc in a memory device context on mouse click/release functions. and for mouse move first i'll draw data from memory device context and then i'll draw line on top of it. But it's not working. Can someone give any example to solve that problem.

            Manoj Kumar Chauhan

            I Offline
            I Offline
            Iain Clarke Warrior Programmer
            wrote on last edited by
            #5

            1/ Are you sure you're just invalidating the CMyStatic control? If you're also invalidating the dialog box, then you'll get flickering. 2/ If your code is working, but not with the memory context, then have a look at Keith Rule's CMemDC article. I've used his CMemDC in many places, and it's great. Just do a search for his name. He didn't write many articles, but it's a golden one. Iain.

            Iain Clarke appearing in spite of being begged not to by CPallini.

            M 1 Reply Last reply
            0
            • S ShilpiP

              are you using CClientDC device context or CPaintDC on OnMouseMove function ? And when i see your code it is clear for me where is the problem?

              Yes U Can ...If U Can ,Dream it , U can do it ...ICAN

              M Offline
              M Offline
              MKUser
              wrote on last edited by
              #6

              I'm not using any device context in mousemove. From mouse move i'm calling Invalidate. And in Ontain, i'm using CDC to create memory device context. If your code is working fine then please send here if you can.Or please mail to my id gkv_manoj@yahoo.com

              Manoj Kumar Chauhan

              1 Reply Last reply
              0
              • I Iain Clarke Warrior Programmer

                1/ Are you sure you're just invalidating the CMyStatic control? If you're also invalidating the dialog box, then you'll get flickering. 2/ If your code is working, but not with the memory context, then have a look at Keith Rule's CMemDC article. I've used his CMemDC in many places, and it's great. Just do a search for his name. He didn't write many articles, but it's a golden one. Iain.

                Iain Clarke appearing in spite of being begged not to by CPallini.

                M Offline
                M Offline
                MKUser
                wrote on last edited by
                #7

                Yes i'm updating only static control not dialog box. Thanks i'll search Keith Rule's CMemDC

                Manoj Kumar Chauhan

                1 Reply Last reply
                0
                • M MKUser

                  If i draw some image, lines, rectangles etc. in OnPain() of dialog box then it takes some time. Suppose i draw image,rectangle on mouse click and release event. I can call repaint from mouse click/release function and it's working fine. But suppose if i want to draw some lines on mouse move function then i need to call repaint from mouse move function and it gives flickering problem. To solve this i plan to draw image, rectangle etc in a memory device context on mouse click/release functions. and for mouse move first i'll draw data from memory device context and then i'll draw line on top of it. But it's not working. Can someone give any example to solve that problem.

                  Manoj Kumar Chauhan

                  K Offline
                  K Offline
                  kingori
                  wrote on last edited by
                  #8

                  Yes you get a flickering problem coz when you call OnPaint() or Invalidate() you are redrawing the whole window. try this Create your function e.g MyDrawing(int x,int y) { CClientDC dc(this); dc.SetTextColor(RGB(0,0,255)); dc.TextOut(x,y,"my text"); } in you Mouse Move Handler { .... MyDrawing(point.x,point.y); } then play around with rectangles

                  M 1 Reply Last reply
                  0
                  • K kingori

                    Yes you get a flickering problem coz when you call OnPaint() or Invalidate() you are redrawing the whole window. try this Create your function e.g MyDrawing(int x,int y) { CClientDC dc(this); dc.SetTextColor(RGB(0,0,255)); dc.TextOut(x,y,"my text"); } in you Mouse Move Handler { .... MyDrawing(point.x,point.y); } then play around with rectangles

                    M Offline
                    M Offline
                    MKUser
                    wrote on last edited by
                    #9

                    It will work but we need to call Invalidate() also b'se if everytime i draw text at different position then previous text will also visible.

                    Manoj Kumar Chauhan

                    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