我遇到MFC(VC ++)MoveWindow()方法的问题,我的规格是:
我通过MoveWindow()方法显示图像,它首先显示图像,然后根据传递的参数进行调整。在调整期间,发生轻微(可见)闪烁效应。我猜这个问题是由于MoveWindow方法造成的。请问我错了什么。如果您需要更多信息,请与我们联系。
**代码更新时间:2011年9月7日
void CTMLead::ResizeWndToRatio(float fHeight, float fWidth)
{
CPoint TopLeft;
float Width;
float Height;
float 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 );
}
谢谢,
阿里
答案 0 :(得分:1)
您是多次使用MoveWindow还是只想调整一次?你自己画图像吗?如果是,您可以自己使用双缓冲来减少闪烁。否则,尝试使用WM_CLIPSIBLINGS和WM_CLIPCHILDREN,这有时也会有所帮助。如果要调整多次或多个窗口的大小,这就是问题所在,请使用BeginDeferWindowPos()。