Announcement

Collapse
No announcement yet.

Blinking pic problem

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Blinking pic problem

    I am using gdiplus to draw a jpg image to the screen at wm_paint, then drawing lines on top of that using the Windows moveto and lineto. It works great, but the problem is that it blinks every time it redraws!! I don't see anywhere that the redrawing can be removed:

    Code:
             call gdipcreatefromhdc(hdc&,graphics&)
    
             quality&=%qualitymodehigh
    
             call gdipgraphicsclear(graphics&,&hc0c0c0c0)
             call gdipsetinterpolationmode(graphics&,quality&)
             call gdipdrawimagerecti(graphics&,img&,0,0,xsz&,ysz&)
    
             call gdipdeletegraphics(graphics&)
    Any ideas??
    Jim Seekamp

  • #2
    try drawing onto a memory dc then bitblt the bitmap over in the wm_paint?

    Comment


    • #3
      Great idea (why didn't I think of that?)
      Thanks
      Jim Seekamp

      Comment


      • #4
        Not working... not sure if I have to do a selectobject or not, but if so, I have no bitmap handle to select!!
        Any ideas?

        Code:
               case %wm_paint
                 hdc&=beginpaint(hwnd&,ps)
        
                 hbgdc&=createcompatibledc(hdc&)
        
                 ''initialize graphics class
                 call gdipcreatefromhdc(hbgdc&,graphics&)
        
                 quality&=%qualitymodehigh
        
                 call gdipgraphicsclear(graphics&,&hc0c0c0c0)
                 call gdipsetinterpolationmode(graphics&,quality&)
                 call gdipdrawimagerecti(graphics&,img&,0,0,xsz&,ysz&)
        
                 call gdipdeletegraphics(graphics&)
                 bitblt hdc&,0,0,xsz&,ysz&,hbgdc&,0,0,%srccopy
                 deletedc hbgdc&
        
                 ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
                 ''draw red square on top of image
        
                 hpen&=createpen(%ps_solid,1,%red)
                 selectobject hdc&,hpen&
        
                 moveto hdc&,navrc.nleft,navrc.ntop
                 lineto hdc&,navrc.nright,navrc.ntop
                 lineto hdc&,navrc.nright,navrc.nbottom
                 lineto hdc&,navrc.nleft,navrc.nbottom
                 lineto hdc&,navrc.nleft,navrc.ntop
        
                 deleteobject hpen&
        
                 endpaint hwnd&,ps
        Jim Seekamp

        Comment


        • #5
          The problem is the WM_ERASEBKGND message.

          When you process WM_PAINT, the BeginPaint API function generates the WM_ERASEBKGND message, where the windows background is drawn.

          This is useful for controls like text controls, where the background is drawn during WM_ERASEBKGND and then WM_PAINT draws all the other stuff on top of the background.

          You can handle it two ways.

          Do your background drawing in WM_ERASEBKGND and simply do nothing in WM_PAINT

          or

          Trap WM_ERAASEBKGND and don't let it gets processed by Windows (ie. don't pass it to DefWindowProc or back to the dialog in a dialog procedure. Then do all your drawing in WM_PAINT.
          Chris Boss
          Computer Workshop
          Developer of "EZGUI"
          http://cwsof.com
          http://twitter.com/EZGUIProGuy

          Comment


          • #6
            Or you could use a 32-bit DIB as double buffer.

            ...
            Patrice Terrier
            www.zapsolution.com
            www.objreader.com
            Addons: GDImage.DLL 32/64-bit (Graphic library), WinLIFT.DLL 32/64-bit (Skin Engine).

            Comment


            • #7
              Now all I'm getting are the red lines drawn in wm_paint - nothing appears from wm_erasebkgnd

              I first did it the way it is below without doing the background dc and the bitblt and it worked, but the blinking was still there, so I put the bitblt back in hoping to get rid of the blinking, but now nothing comes up from the background image...
              Any ideas?

              Code:
                     case %wm_erasebkgnd
                       hdc&=getdc(hwnd&)  ''beginpaint(hwnd&,ps)
              
                       hbgdc&=createcompatibledc(hdc&)
              
                       ''initialize graphics class
                       call gdipcreatefromhdc(hbgdc&,graphics&)
              
                       ''quality&=100
                       quality&=%qualitymodehigh
              
                       call gdipgraphicsclear(graphics&,&hc0c0c0c0)
                       call gdipsetinterpolationmode(graphics&,quality&)
                       call gdipdrawimagerecti(graphics&,img&,0,0,xsz&,ysz&)
              
                       call gdipdeletegraphics(graphics&)
              
                       bitblt hdc&,0,0,xsz&,ysz&,hbgdc&,0,0,%srccopy
              
                       deletedc hdc&
                       deletedc hbgdc&
              
                       exit function
                     case %wm_paint
                       hdc&=beginpaint(hwnd&,ps)
              
                       '''initialize graphics class
                       'call gdipcreatefromhdc(hbgdc&,graphics&)
                       '
                       '''quality&=100
                       'quality&=%qualitymodehigh
                       '
                       'call gdipgraphicsclear(graphics&,&hc0c0c0c0)
                       'call gdipsetinterpolationmode(graphics&,quality&)
                       'call gdipdrawimagerecti(graphics&,img&,0,0,xsz&,ysz&)
                       '
                       'call gdipdeletegraphics(graphics&)
              
                       ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
                       ''draw red square representing position
              
                       hpen&=createpen(%ps_solid,1,%red)
                       selectobject hdc&,hpen&
              
                       moveto hdc&,navrc.nleft,navrc.ntop
                       lineto hdc&,navrc.nright,navrc.ntop
                       lineto hdc&,navrc.nright,navrc.nbottom
                       lineto hdc&,navrc.nleft,navrc.nbottom
                       lineto hdc&,navrc.nleft,navrc.ntop
              
                       deleteobject hpen&
              
                       endpaint hwnd&,ps
              Jim Seekamp

              Comment


              • #8
                Jim, suggestion - post compileable source code. It would then take people 1 minute to get into test mode!

                Comment


                • #9
                  Don't know if my old compileable example posted here will help (post #15). It does the drawing in WM_ERASEBKGND as Chris Boss suggested above.

                  Comment


                  • #10
                    This is what ended up working... I had to do 2 things: use the device context passed by wm_erasebkgnd and I had to set %null as the window class's background. (wclass.hbrbackground=%null) Works like a charm with no blinking!
                    Thanks for the helpful insights Chris and Chris!
                    Jim

                    Code:
                           case %wm_erasebkgnd
                             hdc&=wparam&
                    
                             ''initialize graphics class
                             call gdipcreatefromhdc(hdc&,graphics&)
                    
                             ''quality&=100
                             quality&=%qualitymodehigh
                    
                             'call gdipgraphicsclear(graphics&,&hc0c0c0c0)
                             call gdipsetinterpolationmode(graphics&,quality&)
                             call gdipdrawimagerecti(graphics&,img&,0,0,xsz&,ysz&)
                    
                             call gdipdeletegraphics(graphics&)
                    
                             ''''''''''''''''''''''''''''''''''''''''''''''''
                             ''draw red rectangle
                    
                             hpen&=createpen(%ps_solid,1,%red)
                             selectobject hdc&,hpen&
                    
                             moveto hdc&,navrc.nleft,navrc.ntop
                             lineto hdc&,navrc.nright,navrc.ntop
                             lineto hdc&,navrc.nright,navrc.nbottom
                             lineto hdc&,navrc.nleft,navrc.nbottom
                             lineto hdc&,navrc.nleft,navrc.ntop
                    
                             deleteobject hpen&
                    
                             exit function
                           case %wm_paint
                             hdc&=beginpaint(hwnd&,ps)
                    
                             endpaint hwnd&,ps
                    Jim Seekamp

                    Comment

                    Working...
                    X