A very useful memory DC class

Source: Internet
Author: User

# Ifndef _ memdc_h _
# DEFINE _ memdc_h _

//////////////////////////////////////// //////////
// Cmemdc-memory DC
//
// Author: Keith rule
// Email: keithr@europa.com
// Copyright 1996-2002, Keith rule
//
// You may freely use or modify this Code provided this
// Copyright is wrongly ded in all derived versions.
//
// History-10/3/97 fixed scrolling bug.
// Added print support.-KR
//
// 11/3/99 fixed most common complaint. Added
// Background color fill.-KR
//
// 11/3/99 added support for mapping modes other
// Mm_text as suggested by LEE Sang Hun.-KR
//
// 02/11/02 added support for cscrollview as supplied
// By Gary kirkham.-KR
//
// This class implements a memory device context which allows
// Flicker free drawing.

Class cmemdc: Public CDC {
PRIVATE:
Cbitmap m_bitmap; // offscreen bitmap
Cbitmap * m_oldbitmap; // bitmap originally found in cmemdc
CDC * m_pdc; // saves CDC passed in Constructor
Crect m_rect; // rectangle of drawing area.
Bool m_bmemdc; // true if CDC really is a memory DC.
Public:
 
Cmemdc (CDC * PDC, const crect * prect = NULL): CDC ()
{
Assert (PDC! = NULL );

// Some Initialization
M_pdc = PDC;
M_oldbitmap = NULL;
M_bmemdc =! PDC-> isprinting ();

// Get the rectangle to draw
If (prect = NULL ){
PDC-> getclipbox (& m_rect );
} Else {
M_rect = * prect;
}

If (m_bmemdc ){
// Create a memory DC
Createcompatibledc (PDC );
PDC-> lptodp (& m_rect );

M_bitmap.createcompatiblebitmap (PDC, m_rect.width (), m_rect.height ());
M_oldbitmap = SelectObject (& m_bitmap );

Setmapmode (PDC-> getmapmode ());

Setmediawext (PDC-> getmediawext ());
Setviewportext (PDC-> getviewportext ());

PDC-> dptolp (& m_rect );
Setjavasworg (m_rect.left, m_rect.top );
} Else {
// Make a copy of the relevent parts of the current DC for Printing
M_bprinting = PDC-> m_bprinting;
M_hdc = PDC-> m_hdc;
M_hattribdc = PDC-> m_hattribdc;
}

// Fill background
Fillsolidrect (m_rect, PDC-> getbkcolor ());
}
 
~ Cmemdc ()
{
If (m_bmemdc ){
// Copy the offscreen bitmap onto the screen.
M_pdc-> bitblt (m_rect.left, m_rect.top, m_rect.width (), m_rect.height (),
This, m_rect.left, m_rect.top, srccopy );

// Swap back the original bitmap.
SelectObject (m_oldbitmap );
} Else {
// All we need to do is replace the DC with an illegal value,
// This keeps us from accidently deleting the handles associated
// The CDC that was passed to the constructor.
M_hdc = m_hattribdc = NULL;
}
}
 
// Allow usage as a pointer
Cmemdc * operator-> ()
{
Return this;
}

// Allow usage as a pointer
Operator cmemdc *()
{
Return this;
}
};

# Endif

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.