Microsoft KB Archive/151856

= CMEMDC.EXE Memory Bitmap for Scrolling in CScrollV =

Article ID: 151856

Article Last Modified on 11/21/2006

-

APPLIES TO

 Microsoft Foundation Class Library 4.2, when used with:  Microsoft Visual C++ 4.0 Standard Edition

 Microsoft Visual C++ 4.1 Subscription 

-



This article was previously published under Q151856



SUMMARY
Scrolling a complex image in a CScrollView can be very slow and jerky since OnDraw is called for every WM_VSCROLL and WM_HSCROLL message. While only part of the window is invalidated and redrawn, the whole painting code gets called every time.

This CMemDC sample demonstrates drawing to a memory bitmap instead of the screen. The complex, time-consuming drawing code only needs to be performed when the image changes and in OnInitialUpdate. During OnPaint, the only work that needs to be done is a simple BitBlt from the memory bitmap to the screen.

The sample code draws a complex pattern on its client area. A menu option toggle allows the user to see the speed difference between using and not using the offscreen bitmap. Printing and print preview are supported through the normal printing code, and do not use the memory bitmap.

While CMemDC is a 32-bit sample, the same technique can be used in 16-bit MFC applications.

The following files are available for download from the Microsoft Download Center:

Cmemdc.exe

For additional information about how to download Microsoft Support files, click the following article number to view the article in the Microsoft Knowledge Base:

119591 How to Obtain Microsoft Support Files from Online Services

Microsoft scanned this file for viruses. Microsoft used the most current virus-detection software that was available on the date that the file was posted. The file is stored on security-enhanced servers that help to prevent any unauthorized changes to the file.

NOTE: Use the -d option when running CMEMDC.EXE to decompress the file and recreate the proper directory structure.



MORE INFORMATION
This sample is a MFC implementation of the Windows SDK sample, MemDC. For more information, please see the following article in the Microsoft Knowledge Base:

130805 SAMPLE: Drawing to a Memory Bitmap for Faster Performance

Additional query words: 4.00 4.10

Keywords: kbdownload kbdocview kbfile KB151856

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.