我在对话框一静态控件上显示一个位图,想让位图和窗口一起缩放,使用StretchBit(),结果窗口放大,位图跟着放大,这没有问题。
    问题出在窗口缩小时,位图的边框却失真,又有重叠。但是在这时最小化窗口再恢复,位图的边框又恢复正常。
    怎样才能使位图跟随窗口放大缩小都没问题呢?我总不能每次用鼠标按住窗口边框缩小窗口后,再最小化一次窗口,再恢复吧!?

解决方案 »

  1.   

    很显然你应该在OnDraw里面StretchBlt()
    窗口缩小时的重叠是因为原大底图没有擦掉,
    你又画上了新的小图
      

  2.   

    对话框那里有OnDraw()啊?
    我是放在OnPaint()中了,但是怎样在缩小的时候擦掉底图呢?
      

  3.   

    用InvalidateRect()The InvalidateRect function adds a rectangle to the specified window's update region. The update region represents the portion of the window's client area that must be redrawn. BOOL InvalidateRect(
      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
      

  4.   

    试一下吧, 把它放在OnSize里面做.
    Invalidate();
    CPaintDC dc(this);
    dc.MoveTo (0,0);
    dc.LineTo (cx,cy);
      

  5.   

    我应该把Invalidate(TRUE);放在哪里呢?
    我放在OnSize()和OnPaint()中都不行,位图只是闪了一下,然后就被擦掉了,看不到,缩放窗口时能看见位图在闪动中缩放,可鼠标一停,位图便Invalidate了.
      

  6.   

    放在StretchBit()后面试试,别的地方不要加。
      

  7.   

    如果放在Stretchblt()的后面,那岂不是现实位图后就被Invalidate()给擦掉了吗?这样不行.
    我是这样安排的:
    1)在OnInitDialog()中画位图,不过实在内存中画,并不显示;
    2)在OnPaint()中用StretchBlt()在对话框一静态控件上显示位图;
    3)在OnSize()中设置位图显示的大小;并调用Invalidate();擦出客户区;结果是这样的:对话框一开始显示时,我在内存中画的图能显示出来,But,当我用鼠标按住边框缩放对话框时,位图跟着闪动缩放,当鼠标停下时,位图却消失!这是什么原因?