tags:

views:

111

answers:

1

i copied this code and got an error. plzz tell me how should i declare hDC??? coding:

#include "BitmapEx.h"
CBitmapEx bitmapEx;
bitmapEx.Load(_T("Enter bitmap source file path here..."));
bitmapEx.Rotate(45);
bitmapEx.Sepia();
bitmapEx.Scale(50, 50);
bitmapEx.Draw(hDC);
bitmapEx.Save(_T("Enter bitmap destination file path here..."));

error C2065: 'hDC' : undeclared identifier

+1  A: 

Drawing a bitmap requires a handle to a device context, a HDC. A device context determines where the bitmap pixels end up. Like the screen or the printer, maybe inside another bitmap. By far the most common case, the only time it makes sense to draw a bitmap is when the window that displays the bitmap needs to be painted. That should happen in the WM_PAINT message notification handler for the window. You get the HDC by calling BeginPaint(), PAINTSTRUCT.hdc member.

Everything you need to know about this is available in Petzold's Programming Windows book. This doesn't sound like typical school material. Consider the possibility that you've misunderstood the teacher's assignment. Talk to her, that's what she's there for.

Hans Passant
ok i will try to read this book. no i dont misundrestood the assignment. i m in BSCS-II. he told us to make image analyser using MFC with c++ as a project. i already learned to display a bitmap using GetDC etc. i think CDC cannot be used with BitmapEx, so i have to use HDC. am i right?
Sweety Khan
CDC has the m_hDC member, the device context handle you need.
Hans Passant
someone plzz correct this code i m still unable to correctly declare hDC :(
Sweety Khan