简体   繁体   中英

win32 picture control stop repainting

First, I have a picture control with a bitmap1 loaded in a dialog box:

SendMessage(hWnd, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)LoadImage(NULL, sbitmap1.c_str(), IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE));

Second, at some point I draw a bitmap2 in the picture control using StretchBlt.

hdcImage = GetDC(hWnd)  
hMemDC = CreateCompatibleDC( hdcImage );    
hOldbm = (HBITMAP)SelectObject( hMemDC, hbitmap2 );
SetStretchBltMode( hdcImage, COLORONCOLOR);
StretchBlt( hdcImage, left, top, width, height, hMemDC, 0, 0, w, h, SRCCOPY );
SelectObject( hMemDC, hOldbm );

The bitmap2 is successfully painted but in certain occasions (for example when I minimize the dialog) the picture control no longer shows bitmap2 but bitmap1 instead.

I think the problem is the repaint event. Is there a way to stop the repaint event or change the bitmap that this event is going to paint?

Edit:

Thanks @Mark and @Edward for your answers. The problem was this:

  1. after using StretchBlt you need to do SendMessage STM_SETIMAGE
  2. for SendMessage STM_SETIMAGE use a global HBITMAP (preferably)

Something like this:

hbitmapglobal = (HBITMAP)CopyImage(hbitmap2, IMAGE_BITMAP, abs(width), abs(height), LR_COPYRETURNORG);
SendMessage(hWnd, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hbitmapglobal);

CopyImage is the real simple way to make a copy of a HBITMAP. Take in consideration that this is a sample and hbitmapglobal must be freed at some point.

Normally all the painting occurs in the WM_PAINT handler.

I would suggest setting up (global) variables when you need to paint the second bitmap and invalidate the rectangle of the picture control.

Check for the variable in the WM_PAINT handler and do the painting there.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM