开发者

MFC's MoveWindow (int X, int Y, int Width,int Height,FALSE) causing Flicker issue

I have problem with MFC's(VC++) MoveWindow() Method, My specs are:

  • .net Runtime 3.5
  • VS 2008
  • Windows XP

I am displaying images through MoveWindow() method, it first displays image and then adjust it according to the parameter passed. During adjustment a minor (visible) flicker effect occurs. I am guessing this issue is due to MoveWindow method. Please suggest me whats wrong. Please let me know if you need any more info.

** code updated :07 Sep, 2011

void CTMLead::ResizeWndToRatio(float fHeight, float fWidth)
{
    CPoint  TopLeft;
    float   Width;
    float   Height;
    floa开发者_运维问答t   Ratio;
    int     Cx;
    int     Cy;
    CString tempFileName;
    tempFileName = m_strFilename;

    //  Should we use the current window dimensions?
    if((fHeight <= 0) || (fWidth <= 0))
    {
        fHeight = (float)m_iHeight;
        fWidth = (float)m_iWidth;
    }
    ASSERT((fHeight > 0) && (fWidth > 0));
    if((fHeight <= 0) || (fWidth <= 0)) return;

    //  Compute the aspect ratio of the current viewport
    Ratio = fHeight / fWidth;

    //  Find the center point of the maximum viewing area
    Cx = (m_rcMax.right / 2) + m_rcMax.left;
    Cy = (m_rcMax.bottom / 2) + m_rcMax.top;

    //  If we use the maximum width allowed, is the height still small
    //  enough to fit on the screen?
    if((m_rcMax.right * Ratio) < m_rcMax.bottom)
    {
        //  Use the full width allowed and adjust the height
        Width  = (float)m_rcMax.right;
        Height = Width * Ratio;
    }
    else
    {   
        //  Use the maximum height available and adjust the width
        Height = (float)m_rcMax.bottom;
        Width = Height / Ratio;
    }

    //  Calculate the new coordinates of the upper left corner
    TopLeft.x = Cx - (ROUND(Width) / 2);
    TopLeft.y = Cy - (ROUND(Height) / 2);

    //  Update the size and offset
    m_iLeft   = TopLeft.x;
    m_iTop    = TopLeft.y;
    m_iWidth  = ROUND(Width);
    m_iHeight = ROUND(Height);

    m_fImageWidth=m_iWidth; 
    m_fImageHeight=m_iHeight;
    SetDstRect(0.0f, 0.0f, m_fImageWidth, m_fImageHeight);

    MoveWindow  (m_iLeft, m_iTop, m_iWidth, m_iHeight, FALSE );
}

Thanks,

Ali


Do you use MoveWindow multiple times or do you just want to resize once? Are you drawing the image yourself? If you are, you can use double buffering yourself to reduce flicker. Otherwise, try playing with WM_CLIPSIBLINGS and WM_CLIPCHILDREN, that helps too sometimes. If you are resizing multiple times or multiple windows and that is the problem, use BeginDeferWindowPos().

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜