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

If you want to preserve bitmap from dirtying you need to have another dc
with selected bitmap of same size as original bitmap.

dcMem.SelectBitmap(hMemBitmap); // back buffer

dcBitmap.SelectBitmap(hBitmap); // dc with original bitmap

dcMem.BitBlt(:..&dcBitmap:.); // draw bitmap to back buffer

dcMem.DrawIcon(:.) //draw icon to back buffer

dc.BitBlt(:.&dcMem:.) // blit back buffer to screen

In this case dcBitmap will not be dirty



"Jack Chen" <JackChen@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
Many thanks for your advice. I think I know what to do now, but may I ask
more question that when I select one Bitmap into a memory DC like this:
HBITMAP hOldBitmap =
And then do some drawing on the memory DC:
It will keep the drawing in the bitmap, as a result, the bitmap
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
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


"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
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
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
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
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,
info.bmWidth, info.bmHeight, SRCCOPY));
::SelectObject(memDc.GetSafeHdc(), hOldBitmap);
VERIFY( memDc.DeleteDC() );


Relevant Pages

  • Re: Toolbar bitmap grief!
    ... compatible with my toolbar. ... Then send me the URL to this refresh icon or tell me how you converted it? ... You say change the background color, well by default for a toolbar bitmap ...
  • Re: Some issues on Tk
    ... I use the "wm iconbitmap" command to change the icon of the main ... wm iconbitmap window ?bitmap? ... If bitmap is specified, then it names a bitmap in the standard ...
  • Re: colored text and bitmap in CListBox
    ... Either way, if he uses LBS_HASSTRINGS in his listbox or stores them himself, ... for example, it would have a command to draw a string, then a bitmap, then ... then another bitmap, etc. ... would therefore display no icon, a circle-i, ...
  • Re: colored text and bitmap in CListBox
    ... for example, it would have a command to draw a string, then a bitmap, then ... then another bitmap, etc. ... would therefore display no icon, a circle-i, ... class Icon: public MessageObject { ...
  • Re: converting from an icon to a bitmnap
    ... // Create an empty bitmap ... // Load icon from stream ... // get IPictureDisp pointer ... So I try to render my icon to a bitmap by something like that. ...