screen flickering in MFC

This is a discussion on screen flickering in MFC within the Windows Programming forums, part of the Platform Specific Boards category; My program is basically a level editor for a game I'm working on, and whenever I scroll the map, it ...

  1. #1
    Registered User
    Join Date
    Aug 2001
    Posts
    4

    Question screen flickering in MFC

    My program is basically a level editor for a game I'm working on, and whenever I scroll the map, it flickers and I can see things being drawn. I know that this is because I need to create a dc in memory, draw to that, and then blt that to the main dc.

    I tried using CMemoryDC and CreateCompatibleDC(), but I can't figure out how to create a DC in memory the same size as the main dc. Any suggestions would be appreciated...

  2. #2
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,859
    When you start the program get the screen size and create the DC's then.

    I think it is more the size of the bitmap in the DC.

    hdcTemp=GetDC(NULL);
    iWidth =GetDeviceCaps(hdcTemp,HORZRES);
    iHeight =GetDeviceCaps(hdcTemp,VERTRES);
    ReleaseDC(hWnd,hdcTemp);
    hBMPBackground=CreateCompatibleBitmap(hdc,iWidth,i Height);
    hSystemBMP=SelectObject(hdcDisplay,hBMPBackground) ;
    OR
    GetObject(hBitmap,sizeof(BITMAP),&Bitmap);
    Where the BITMAP structure contains width and height.

  3. #3
    Registered User Esss's Avatar
    Join Date
    Aug 2001
    Posts
    133
    whenever I scroll the map, it flickers
    The flicker is mostly due to the background being erased before it is drawn. If your drawing covers the whole view area, you can avoid the erasing by handling the WM_ERASEBKGND message:

    PHP Code:
    BOOL CMyView::OnEraseBkgnd(CDC *)
    {
        return 
    TRUE;

    Ess
    Like a rat in a maze who says,
    "Watch me choose my own direction"
    Are you under the illusion
    The path is winding your way?
    - Rush

  4. #4
    Registered User
    Join Date
    Aug 2001
    Posts
    4
    Thanks for the advice - exactly what I needed.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Feedback: Functional Specification Wording
    By Ragsdale85 in forum C++ Programming
    Replies: 0
    Last Post: 01-18-2006, 04:56 PM
  2. char copy
    By variable in forum C Programming
    Replies: 8
    Last Post: 02-06-2005, 10:18 PM
  3. i am not able to figure ot the starting point of this
    By youngashish in forum C++ Programming
    Replies: 7
    Last Post: 10-07-2004, 03:41 AM
  4. MFC Dialog App Screen Refresh Question
    By Scotth10 in forum Windows Programming
    Replies: 2
    Last Post: 10-18-2002, 03:07 PM
  5. WIndows programming?
    By hostensteffa in forum Windows Programming
    Replies: 7
    Last Post: 06-07-2002, 09:52 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21