我在对话框一静态控件上显示一个位图,想让位图和窗口一起缩放,使用StretchBit(),结果窗口放大,位图跟着放大,这没有问题。
问题出在窗口缩小时,位图的边框却失真,又有重叠。但是在这时最小化窗口再恢复,位图的边框又恢复正常。
怎样才能使位图跟随窗口放大缩小都没问题呢?我总不能每次用鼠标按住窗口边框缩小窗口后,再最小化一次窗口,再恢复吧!?
问题出在窗口缩小时,位图的边框却失真,又有重叠。但是在这时最小化窗口再恢复,位图的边框又恢复正常。
怎样才能使位图跟随窗口放大缩小都没问题呢?我总不能每次用鼠标按住窗口边框缩小窗口后,再最小化一次窗口,再恢复吧!?
窗口缩小时的重叠是因为原大底图没有擦掉,
你又画上了新的小图
我是放在OnPaint()中了,但是怎样在缩小的时候擦掉底图呢?
HWND hWnd, // handle of window with changed update region
CONST RECT *lpRect,
// address of rectangle coordinates
BOOL bErase // erase-background flag
);
Parameters
hWnd
Handle to the window whose update region has changed. If this parameter is NULL, the system invalidates and redraws all windows, and sends theWM_ERASEBKGND and WM_NCPAINT messages to the window procedure before the function returns.
lpRect
Pointer to a RECT structure that contains the client coordinates of the rectangle to be added to the update region. If this parameter is NULL, the entire client area is added to the update region.
bErase
Specifies whether the background within the update region is to be erased when the update region is processed. If this parameter is TRUE, the background is erased when the BeginPaint function is called. If this parameter is FALSE, the background remains unchanged.
Return Values
Invalidate();
CPaintDC dc(this);
dc.MoveTo (0,0);
dc.LineTo (cx,cy);
我放在OnSize()和OnPaint()中都不行,位图只是闪了一下,然后就被擦掉了,看不到,缩放窗口时能看见位图在闪动中缩放,可鼠标一停,位图便Invalidate了.
我是这样安排的:
1)在OnInitDialog()中画位图,不过实在内存中画,并不显示;
2)在OnPaint()中用StretchBlt()在对话框一静态控件上显示位图;
3)在OnSize()中设置位图显示的大小;并调用Invalidate();擦出客户区;结果是这样的:对话框一开始显示时,我在内存中画的图能显示出来,But,当我用鼠标按住边框缩放对话框时,位图跟着闪动缩放,当鼠标停下时,位图却消失!这是什么原因?