Click here to Skip to main content
15,923,789 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionSpying Messages Pin
hamidreza_buddy23-Sep-05 23:44
hamidreza_buddy23-Sep-05 23:44 
AnswerRe: Spying Messages Pin
khan++24-Sep-05 0:10
khan++24-Sep-05 0:10 
QuestiononKeyDown() problem Pin
hamidreza_buddy23-Sep-05 22:55
hamidreza_buddy23-Sep-05 22:55 
AnswerRe: onkeydown() problem Pin
khan++23-Sep-05 23:10
khan++23-Sep-05 23:10 
GeneralRe: onkeydown() problem Pin
hamidreza_buddy23-Sep-05 23:31
hamidreza_buddy23-Sep-05 23:31 
QuestionScaling Bitmapp Pin
Anonymous23-Sep-05 22:35
Anonymous23-Sep-05 22:35 
AnswerRe: Scaling Bitmapp Pin
khan++23-Sep-05 22:58
khan++23-Sep-05 22:58 
AnswerRe: Scaling Bitmapp Pin
Achim Klein24-Sep-05 0:38
Achim Klein24-Sep-05 0:38 
Hi,

here is some copy-and-paste code:
// ----------
// ZoomBitmap
// ----------
/**
 * Returns a new bitmap that fits proportionally into the specified rectangle.
 *
 * @return The returned CBitmap is created by using the new operator. You have to delete it yourself.
 */
CBitmap* CMyDialog::ZoomBitmap(CBitmap* pBitmap, const CRect& FitInto)
{
	// check size
	if (FitInto.IsRectEmpty()) return 0;

	// get current bitmap rect
	CRect bmpRect = doGetBitmapRect(pBitmap);

	// check size
	if (bmpRect.IsRectEmpty()) return 0;

	// get zoomed bitmap rect
	CRect zoomedRect = doGetZoomedBitmapRect(pBitmap, FitInto);

	// check size
	if (zoomedRect.IsRectEmpty()) return 0;

	// get device context
	CDC* pDC = GetDC();

	// check device context
	if (pDC == 0) return 0;

	// create memory device context (source bitmap)
	CDC* memDC1 = new CDC;
	if (memDC1->CreateCompatibleDC(pDC) == 0)
	{
		delete memDC1;

		ReleaseDC(pDC);

		return 0;
	}

	// create memory device context (zoomed bitmap)
	CDC* memDC2 = new CDC;
	if (memDC2->CreateCompatibleDC(pDC) == 0)
	{
		delete memDC1;
		delete memDC2;

		ReleaseDC(pDC);

		return 0;
	}

	// create new bitmap
	CBitmap* zoomed = new CBitmap;

	// initialize bitmap
	if (zoomed->CreateCompatibleBitmap(pDC, zoomedRect.Width(), zoomedRect.Height()) == 0)
	{
		delete memDC1;
		delete memDC2;
		delete zoomed;

		ReleaseDC(pDC);

		return 0;
	}

	// not needed anymore
	ReleaseDC(pDC);

	// select bitmaps
	CBitmap* old1 = memDC1->SelectObject(pBitmap);
	CBitmap* old2 = memDC2->SelectObject(zoomed);

	// stretch bitmap
	memDC2->SetStretchBltMode(HALFTONE);
	BOOL result = memDC2->StretchBlt
	(
		0,			// specifies the x-coordinate (in logical units) of the upper-left corner of the destination rectangle
		0,			// specifies the y-coordinate (in logical units) of the upper-left corner of the destination rectangle
		zoomedRect.Width(),	// specifies the width (in logical units) of the destination rectangle
		zoomedRect.Height(),	// specifies the height (in logical units) of the destination rectangle
		memDC1,			// specifies the source device context
		0,			// specifies the x-coordinate (in logical units) of the upper-left corner of the source rectangle
		0,			// specifies the x-coordinate (in logical units) of the upper-left corner of the source rectangle
		bmpRect.Width(),	// specifies the width (in logical units) of the source rectangle
		bmpRect.Height(),	// specifies the height (in logical units) of the source rectangle
		SRCCOPY			// specifies the raster operation to be performed
	);

	// check operation
	if (result == FALSE)
	{
		// free memory
		delete zoomed;

		// reset pointer
		zoomed = 0;
	}

	// reselect old bitmaps
	memDC2->SelectObject(old2);
	memDC1->SelectObject(old1);

	// delete temporary device contexts
	delete memDC2;
	delete memDC1;

	// the zoomed bitmap
	return zoomed;
}


Regards
Achim Klein


We can do no great things, only small things with great love. - Mother Theresa
GeneralRe: Scaling Bitmapp Pin
John R. Shaw24-Sep-05 9:16
John R. Shaw24-Sep-05 9:16 
QuestionFile Search Pin
nvamshi23-Sep-05 21:04
nvamshi23-Sep-05 21:04 
AnswerRe: File Search Pin
khan++23-Sep-05 21:16
khan++23-Sep-05 21:16 
AnswerRe: File Search Pin
ThatsAlok23-Sep-05 21:28
ThatsAlok23-Sep-05 21:28 
Questionread buffer problem Pin
meiyueh23-Sep-05 20:38
meiyueh23-Sep-05 20:38 
AnswerRe: read buffer problem Pin
billiam90423-Sep-05 21:48
billiam90423-Sep-05 21:48 
QuestionInfo on KEY_EXECUTE and DeleteKeyEx Pin
reg-user23-Sep-05 20:11
sussreg-user23-Sep-05 20:11 
AnswerRe: Info on KEY_EXECUTE and DeleteKeyEx Pin
khan++23-Sep-05 20:55
khan++23-Sep-05 20:55 
GeneralRe: Info on KEY_EXECUTE and DeleteKeyEx Pin
reg-user23-Sep-05 21:06
sussreg-user23-Sep-05 21:06 
GeneralRe: Info on KEY_EXECUTE and DeleteKeyEx Pin
khan++23-Sep-05 21:13
khan++23-Sep-05 21:13 
QuestionDebugging in an activeX control Pin
aasstt23-Sep-05 19:41
aasstt23-Sep-05 19:41 
AnswerRe: Debugging in an activeX control Pin
khan++23-Sep-05 20:40
khan++23-Sep-05 20:40 
Questionglobal buffer or passing by reference? Pin
billiam90423-Sep-05 16:20
billiam90423-Sep-05 16:20 
AnswerRe: global buffer or passing by reference? Pin
khan++23-Sep-05 20:44
khan++23-Sep-05 20:44 
GeneralRe: global buffer or passing by reference? Pin
billiam90423-Sep-05 22:00
billiam90423-Sep-05 22:00 
GeneralRe: global buffer or passing by reference? Pin
khan++23-Sep-05 22:54
khan++23-Sep-05 22:54 
GeneralRe: global buffer or passing by reference? Pin
billiam90424-Sep-05 13:05
billiam90424-Sep-05 13:05 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.