[英]win32 picture control stop repainting
First, I have a picture control with a bitmap1 loaded in a dialog box: 首先,我在对话框中加载了一个带有bitmap1的图片控件:
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. 其次,在某些时候,我使用StretchBlt在图片控件中绘制了一个bitmap2。
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. bitmap2已成功绘制,但是在某些情况下(例如,当我最小化对话框时),图片控件不再显示bitmap2,而是显示bitmap1。
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. 感谢@Mark和@Edward的回答。 The problem was this: 问题是这样的:
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. CopyImage是制作HBITMAP副本的真正简单方法。 Take in consideration that this is a sample and hbitmapglobal must be freed at some point. 考虑到这是一个示例,必须在某个时候释放hbitmapglobal。
Normally all the painting occurs in the WM_PAINT
handler. 通常,所有绘制都发生在WM_PAINT
处理程序中。
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. 在WM_PAINT
处理程序中检查变量,并在那里进行绘制。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.