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(),
m_hBitmap);
And then do some drawing on the memory DC:
::DrawIconExmemDc.GetSafeHdc),m_x,m_y,hIcon,16,16,0,NULL,
DI_NORMAL);
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
way.

Jack

"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.
--
Andrey

"Jack Chen" <JackChen@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:65253112-009A-4822-A1EC-9FB96F94BE66@xxxxxxxxxxxxxxxx
Thanks Andrey, but the question is how can I perform drawing of changed
part?
Can you give me some instructions. I really have no idea how to do it
though
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
performed?

--

Andrey



"Jack Chen" <JackChen@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:9C5E610D-13EC-47E7-8B0B-F24AA09FF8D8@xxxxxxxxxxxxxxxx
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
above
one of the ICONs and if so, Set some flag and use OnMouseMove() to set
the
new position of the ICON draged,and then redraw all the view the and
the
ICON
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
changed.
I
just need to erase the former ICON, and draw the ICON with new
position.But
how I can fill the area that I erased with the correct part of the
picture?
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;
VERIFY(memDc.CreateCompatibleDC(pDC));
HBITMAP hOldBitmap = (HBITMAP)::SelectObject(memDc.GetSafeHdc(),
m_hBitmap);
HICON hIcon = pImageList->ExtractIcon(1);
::DrawIconEx(memDc.GetSafeHdc(),m_x,m_y,hIcon,16,16,0,NULL,DI_NORMAL);
::DestroyIcon(hIcon);
VERIFY(pDC->StretchBlt( 0, 0, info.bmWidth, info.bmHeight, &memDc, 0,
0,
info.bmWidth, info.bmHeight, SRCCOPY));
::SelectObject(memDc.GetSafeHdc(), hOldBitmap);
VERIFY( memDc.DeleteDC() );
}







.