Flicker Problem .. No MFC

Flicker Problem .. No MFC

Post by Pete » Mon, 14 Jul 2003 10:50:02



My problem is while doing some BITBLT'ing
I am getting too much flickering,.. I've tried
WM_SETREDRAW to false, then back on
after my BITBLT'ing.. but no luck.. I am also
now trying some kind of off screen temp DC thing
but I cant get that to work right either.. anyone
know of a solution to flickering bitblts?I have my
WM_PAINT and my bitblt'ing routine pasted below..

Plus I have seen a solution using MFC, but I would rather not.

Thanks for any ideas or help or reference material..
Pete

void repaint(HWND hWnd, HDC hdc){

 HBITMAP hBitmap,hOldBitmap;
 HDC hDCTemp;
 BITMAP bmp;

 hBitmap=LoadBitmap(g_hInst,MAKEINTRESOURCE(IDB_BITMAP1));
 hDCTemp=CreateCompatibleDC(hdc);
 hOldBitmap=(HBITMAP)SelectObject(hDCTemp,hBitmap);
GetObject(hBitmap,sizeof(bmp),&bmp);

BitBlt(hdc,0,0,240,252,hDCTemp,0,0,SRCCOPY);

//// This is where my animation and BITBLT's occur
//// the ones that are causing the flicker anyway...

 SelectObject(hDCTemp,hBitmap);
 DeleteDC(hDCTemp);
 DeleteObject(hBitmap);

Quote:}

// here's the WM_PAINT routine.. it calls repaint ..
  case WM_PAINT:
   hdc = BeginPaint(hWnd, &ps);
   //SendMessage(hWnd,WM_SETREDRAW,false,0);
      repaint(hWnd, hdc);
    //SendMessage(hWnd,WM_SETREDRAW,true,0);
   EndPaint(hWnd, &ps);
   break;
 
 
 

Flicker Problem .. No MFC

Post by Doug Forste » Tue, 15 Jul 2003 07:30:19


Hi Pete,

Flickering is commonly caused by background erasing. If your bitmap paints
the entire screen you can handle WM_ERASEBKGND and just do nothing. Also
loading bitmaps is a fairly slow operation preferably not done during
WM_PAINT handling. Better to load the bitmap once and hang on to it for
painting. You mention animation but you don't show any code for this so
there may be other issues

Cheers

Doug Forster


Quote:> My problem is while doing some BITBLT'ing
> I am getting too much flickering,.. I've tried
> WM_SETREDRAW to false, then back on
> after my BITBLT'ing.. but no luck.. I am also
> now trying some kind of off screen temp DC thing
> but I cant get that to work right either.. anyone
> know of a solution to flickering bitblts?I have my
> WM_PAINT and my bitblt'ing routine pasted below..

> Plus I have seen a solution using MFC, but I would rather not.

> Thanks for any ideas or help or reference material..
> Pete

> void repaint(HWND hWnd, HDC hdc){

>  HBITMAP hBitmap,hOldBitmap;
>  HDC hDCTemp;
>  BITMAP bmp;

>  hBitmap=LoadBitmap(g_hInst,MAKEINTRESOURCE(IDB_BITMAP1));
>  hDCTemp=CreateCompatibleDC(hdc);
>  hOldBitmap=(HBITMAP)SelectObject(hDCTemp,hBitmap);
> GetObject(hBitmap,sizeof(bmp),&bmp);

> BitBlt(hdc,0,0,240,252,hDCTemp,0,0,SRCCOPY);

> //// This is where my animation and BITBLT's occur
> //// the ones that are causing the flicker anyway...

>  SelectObject(hDCTemp,hBitmap);
>  DeleteDC(hDCTemp);
>  DeleteObject(hBitmap);
> }

> // here's the WM_PAINT routine.. it calls repaint ..
>   case WM_PAINT:
>    hdc = BeginPaint(hWnd, &ps);
>    //SendMessage(hWnd,WM_SETREDRAW,false,0);
>       repaint(hWnd, hdc);
>     //SendMessage(hWnd,WM_SETREDRAW,true,0);
>    EndPaint(hWnd, &ps);
>    break;


 
 
 

Flicker Problem .. No MFC

Post by Pete » Tue, 15 Jul 2003 10:06:53


I did, i have it cut out, and put comments
in there, that section would of just added space,
all it is a few bitblts to the DC "hdc"
the comments say "this is where my animation takes place.."


> Hi Pete,

> Flickering is commonly caused by background erasing. If your bitmap paints
> the entire screen you can handle WM_ERASEBKGND and just do nothing. Also
> loading bitmaps is a fairly slow operation preferably not done during
> WM_PAINT handling. Better to load the bitmap once and hang on to it for
> painting. You mention animation but you don't show any code for this so
> there may be other issues

> Cheers

> Doug Forster



> > My problem is while doing some BITBLT'ing
> > I am getting too much flickering,.. I've tried
> > WM_SETREDRAW to false, then back on
> > after my BITBLT'ing.. but no luck.. I am also
> > now trying some kind of off screen temp DC thing
> > but I cant get that to work right either.. anyone
> > know of a solution to flickering bitblts?I have my
> > WM_PAINT and my bitblt'ing routine pasted below..

> > Plus I have seen a solution using MFC, but I would rather not.

> > Thanks for any ideas or help or reference material..
> > Pete

> > void repaint(HWND hWnd, HDC hdc){

> >  HBITMAP hBitmap,hOldBitmap;
> >  HDC hDCTemp;
> >  BITMAP bmp;

> >  hBitmap=LoadBitmap(g_hInst,MAKEINTRESOURCE(IDB_BITMAP1));
> >  hDCTemp=CreateCompatibleDC(hdc);
> >  hOldBitmap=(HBITMAP)SelectObject(hDCTemp,hBitmap);
> > GetObject(hBitmap,sizeof(bmp),&bmp);

> > BitBlt(hdc,0,0,240,252,hDCTemp,0,0,SRCCOPY);

> > //// This is where my animation and BITBLT's occur
> > //// the ones that are causing the flicker anyway...

> >  SelectObject(hDCTemp,hBitmap);
> >  DeleteDC(hDCTemp);
> >  DeleteObject(hBitmap);
> > }

> > // here's the WM_PAINT routine.. it calls repaint ..
> >   case WM_PAINT:
> >    hdc = BeginPaint(hWnd, &ps);
> >    //SendMessage(hWnd,WM_SETREDRAW,false,0);
> >       repaint(hWnd, hdc);
> >     //SendMessage(hWnd,WM_SETREDRAW,true,0);
> >    EndPaint(hWnd, &ps);
> >    break;

 
 
 

Flicker Problem .. No MFC

Post by Pete » Tue, 15 Jul 2003 10:10:27


I could do invalidaterect to the area i've redrawn, but
anytime I specify a rect, it says it must be a const .. and
of course my rect wont be const.... anyone know the
proper way to do invalidaterect with a specified rect
instead of entire screen?

Pete


> Hi Pete,

> Flickering is commonly caused by background erasing. If your bitmap paints
> the entire screen you can handle WM_ERASEBKGND and just do nothing. Also
> loading bitmaps is a fairly slow operation preferably not done during
> WM_PAINT handling. Better to load the bitmap once and hang on to it for
> painting. You mention animation but you don't show any code for this so
> there may be other issues

> Cheers

> Doug Forster



> > My problem is while doing some BITBLT'ing
> > I am getting too much flickering,.. I've tried
> > WM_SETREDRAW to false, then back on
> > after my BITBLT'ing.. but no luck.. I am also
> > now trying some kind of off screen temp DC thing
> > but I cant get that to work right either.. anyone
> > know of a solution to flickering bitblts?I have my
> > WM_PAINT and my bitblt'ing routine pasted below..

> > Plus I have seen a solution using MFC, but I would rather not.

> > Thanks for any ideas or help or reference material..
> > Pete

> > void repaint(HWND hWnd, HDC hdc){

> >  HBITMAP hBitmap,hOldBitmap;
> >  HDC hDCTemp;
> >  BITMAP bmp;

> >  hBitmap=LoadBitmap(g_hInst,MAKEINTRESOURCE(IDB_BITMAP1));
> >  hDCTemp=CreateCompatibleDC(hdc);
> >  hOldBitmap=(HBITMAP)SelectObject(hDCTemp,hBitmap);
> > GetObject(hBitmap,sizeof(bmp),&bmp);

> > BitBlt(hdc,0,0,240,252,hDCTemp,0,0,SRCCOPY);

> > //// This is where my animation and BITBLT's occur
> > //// the ones that are causing the flicker anyway...

> >  SelectObject(hDCTemp,hBitmap);
> >  DeleteDC(hDCTemp);
> >  DeleteObject(hBitmap);
> > }

> > // here's the WM_PAINT routine.. it calls repaint ..
> >   case WM_PAINT:
> >    hdc = BeginPaint(hWnd, &ps);
> >    //SendMessage(hWnd,WM_SETREDRAW,false,0);
> >       repaint(hWnd, hdc);
> >     //SendMessage(hWnd,WM_SETREDRAW,true,0);
> >    EndPaint(hWnd, &ps);
> >    break;

 
 
 

Flicker Problem .. No MFC

Post by Doug Forste » Tue, 15 Jul 2003 10:28:14


Hi Pete,

A const parameter just means the called procedure can't change it. You can
still supply different rectangles. The last parameter to InvalidateRect also
controls whether or not the background is erased.

RECT rc;
rc.top = mytop;
rc.left = myleft;
rc.bottom = mybottom;
rc.right = myright;
InvalidateRect(hwnd, &rc, FALSE);

or the MFC equivalent if you are using MFC

Cheers

Doug Forster


> I could do invalidaterect to the area i've redrawn, but
> anytime I specify a rect, it says it must be a const .. and
> of course my rect wont be const.... anyone know the
> proper way to do invalidaterect with a specified rect
> instead of entire screen?

> Pete



> > Hi Pete,

> > Flickering is commonly caused by background erasing. If your bitmap
paints
> > the entire screen you can handle WM_ERASEBKGND and just do nothing. Also
> > loading bitmaps is a fairly slow operation preferably not done during
> > WM_PAINT handling. Better to load the bitmap once and hang on to it for
> > painting. You mention animation but you don't show any code for this so
> > there may be other issues

> > Cheers

> > Doug Forster



> > > My problem is while doing some BITBLT'ing
> > > I am getting too much flickering,.. I've tried
> > > WM_SETREDRAW to false, then back on
> > > after my BITBLT'ing.. but no luck.. I am also
> > > now trying some kind of off screen temp DC thing
> > > but I cant get that to work right either.. anyone
> > > know of a solution to flickering bitblts?I have my
> > > WM_PAINT and my bitblt'ing routine pasted below..

> > > Plus I have seen a solution using MFC, but I would rather not.

> > > Thanks for any ideas or help or reference material..
> > > Pete

> > > void repaint(HWND hWnd, HDC hdc){

> > >  HBITMAP hBitmap,hOldBitmap;
> > >  HDC hDCTemp;
> > >  BITMAP bmp;

> > >  hBitmap=LoadBitmap(g_hInst,MAKEINTRESOURCE(IDB_BITMAP1));
> > >  hDCTemp=CreateCompatibleDC(hdc);
> > >  hOldBitmap=(HBITMAP)SelectObject(hDCTemp,hBitmap);
> > > GetObject(hBitmap,sizeof(bmp),&bmp);

> > > BitBlt(hdc,0,0,240,252,hDCTemp,0,0,SRCCOPY);

> > > //// This is where my animation and BITBLT's occur
> > > //// the ones that are causing the flicker anyway...

> > >  SelectObject(hDCTemp,hBitmap);
> > >  DeleteDC(hDCTemp);
> > >  DeleteObject(hBitmap);
> > > }

> > > // here's the WM_PAINT routine.. it calls repaint ..
> > >   case WM_PAINT:
> > >    hdc = BeginPaint(hWnd, &ps);
> > >    //SendMessage(hWnd,WM_SETREDRAW,false,0);
> > >       repaint(hWnd, hdc);
> > >     //SendMessage(hWnd,WM_SETREDRAW,true,0);
> > >    EndPaint(hWnd, &ps);
> > >    break;

 
 
 

Flicker Problem .. No MFC

Post by Pete » Tue, 15 Jul 2003 11:24:22


Thanks for the invalidate tip,
I finally got it to only repaint the small square I need to redraw
and the flickering has gone away.. thanks!!

pete


> Hi Pete,

> A const parameter just means the called procedure can't change it. You can
> still supply different rectangles. The last parameter to InvalidateRect
also
> controls whether or not the background is erased.

> RECT rc;
> rc.top = mytop;
> rc.left = myleft;
> rc.bottom = mybottom;
> rc.right = myright;
> InvalidateRect(hwnd, &rc, FALSE);

> or the MFC equivalent if you are using MFC

> Cheers

> Doug Forster



> > I could do invalidaterect to the area i've redrawn, but
> > anytime I specify a rect, it says it must be a const .. and
> > of course my rect wont be const.... anyone know the
> > proper way to do invalidaterect with a specified rect
> > instead of entire screen?

> > Pete



> > > Hi Pete,

> > > Flickering is commonly caused by background erasing. If your bitmap
> paints
> > > the entire screen you can handle WM_ERASEBKGND and just do nothing.
Also
> > > loading bitmaps is a fairly slow operation preferably not done during
> > > WM_PAINT handling. Better to load the bitmap once and hang on to it
for
> > > painting. You mention animation but you don't show any code for this
so
> > > there may be other issues

> > > Cheers

> > > Doug Forster



> > > > My problem is while doing some BITBLT'ing
> > > > I am getting too much flickering,.. I've tried
> > > > WM_SETREDRAW to false, then back on
> > > > after my BITBLT'ing.. but no luck.. I am also
> > > > now trying some kind of off screen temp DC thing
> > > > but I cant get that to work right either.. anyone
> > > > know of a solution to flickering bitblts?I have my
> > > > WM_PAINT and my bitblt'ing routine pasted below..

> > > > Plus I have seen a solution using MFC, but I would rather not.

> > > > Thanks for any ideas or help or reference material..
> > > > Pete

> > > > void repaint(HWND hWnd, HDC hdc){

> > > >  HBITMAP hBitmap,hOldBitmap;
> > > >  HDC hDCTemp;
> > > >  BITMAP bmp;

> > > >  hBitmap=LoadBitmap(g_hInst,MAKEINTRESOURCE(IDB_BITMAP1));
> > > >  hDCTemp=CreateCompatibleDC(hdc);
> > > >  hOldBitmap=(HBITMAP)SelectObject(hDCTemp,hBitmap);
> > > > GetObject(hBitmap,sizeof(bmp),&bmp);

> > > > BitBlt(hdc,0,0,240,252,hDCTemp,0,0,SRCCOPY);

> > > > //// This is where my animation and BITBLT's occur
> > > > //// the ones that are causing the flicker anyway...

> > > >  SelectObject(hDCTemp,hBitmap);
> > > >  DeleteDC(hDCTemp);
> > > >  DeleteObject(hBitmap);
> > > > }

> > > > // here's the WM_PAINT routine.. it calls repaint ..
> > > >   case WM_PAINT:
> > > >    hdc = BeginPaint(hWnd, &ps);
> > > >    //SendMessage(hWnd,WM_SETREDRAW,false,0);
> > > >       repaint(hWnd, hdc);
> > > >     //SendMessage(hWnd,WM_SETREDRAW,true,0);
> > > >    EndPaint(hWnd, &ps);
> > > >    break;

 
 
 

1. Flicker-Flicker-Flicker (Netscape and MS IEx)


Not sure if this is the same problem, but this is a solution direct
from MS:

If your screen is flashing when downloading files/pages on IE 3 B2,
there are 2 solutions:

1) Remove and reinstall until it quits (In rare cases, it may take
multiple uninstalls)

2) Delete the registry key:

HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Toolbar

NOTE: Please exercise caution when taking the registry modification
method.

--   FaveSave - Save Internet Explorer "Favorites" quickly   --
--    and easily from within any application in Windows 95   --
--     http://dialspace.dial.pipex.com/nmercier/index.htm    --

2. order of E Mail

3. Avoiding flickering in mfc views.

4. Outlook Express

5. Flickering with Direct3D and MFC

6. Folder Size - excludes subdirectories

7. MFC CMDIChildWnd flickering when activating other child window

8. converting wma format file to a wav format file to play on aol

9. MFC Subclassed control FLICKERS?

10. Problems using an MFC/ATL Multithreaded COM Obj with an MFC app

11. MFC ActiveX control inside another MFC ActiveX control - MFC Bug

12. Could it be to do with OE version nos?

13. XP and printing on Netware NOS