Re: Can I use a jpg picture as view's background?(WCE.NET 4.2 eVC+

Many thanks for your advice. I think I know what to do now, but may I ask one
more question that when I select one Bitmap into a memory DC like this:
HBITMAP hOldBitmap = (HBITMAP)::SelectObject(memDc.GetSafeHdc(),
And then do some drawing on the memory DC:
It will keep the drawing in the bitmap, as a result, the bitmap is
dirtyed by the drawing. Though I never seen any document telling that this
will happen, it really happens to me. Would you please tell me how to do it
without dirty the bitmap?
I have tried to draw the ICON directly into the DC instead of
memory DC, and it won't dirty the bitmap. But I am not so sure it is a best


"Andrey Yatsyk [eMVP]" wrote:

You can draw image part instead of all image by changing xSrc, ySrc,
nSrcWidth, nSrcHeight params in StretchBlt. Set the rect of bitmap to copy
pixels from, and coordinates where to draw bitmap area by x and y.

"Jack Chen" <JackChen@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
Thanks Andrey, but the question is how can I perform drawing of changed
Can you give me some instructions. I really have no idea how to do it
I have read CDC and CBitmap for times.

"Andrey Yatsyk [eMVP]" wrote:

You can perform drawing of changed part of view in mouse handler but not
calling RedrawWindow or you can invalidate changed rectangle by
InvalidateRect and then call UpdateWindow .

Also why do you use StretchBlt instead of BitBlt when no stretching is



"Jack Chen" <JackChen@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
Hello every one~
What I wanted to do is as follows:
1) Display a JPG format picture in a view.(I have done)
2) Display some ICONs from resource above the picture in the view using
DrawIconEx() method.
3) The ICON can be draged.

When I drag the ICON using OnLButtonDown() to check if the mouse is
one of the ICONs and if so, Set some flag and use OnMouseMove() to set
new position of the ICON draged,and then redraw all the view the and
with new position. But this way seem not so effective since the only
difference from the former view is one ICON's position have been
just need to erase the former ICON, and draw the ICON with new
how I can fill the area that I erased with the correct part of the
Is there some better solutions for me?

void CX6View::OnDraw(CDC* pDC)
if (m_hBitmap) {
BITMAP info;
::GetObject(m_hBitmap, sizeof(BITMAP), &info);
CDC memDc;
HBITMAP hOldBitmap = (HBITMAP)::SelectObject(memDc.GetSafeHdc(),
HICON hIcon = pImageList->ExtractIcon(1);
VERIFY(pDC->StretchBlt( 0, 0, info.bmWidth, info.bmHeight, &memDc, 0,
info.bmWidth, info.bmHeight, SRCCOPY));
::SelectObject(memDc.GetSafeHdc(), hOldBitmap);
VERIFY( memDc.DeleteDC() );