MFC的MoveWindow(int X, int Y, int Width,int Height,FALSE)导致闪烁问题
我对 MFC(VC++) MoveWindow() 方法有问题,我的规格是:
- .net Runtime 3.5
- VS 2008
- Windows XP
我通过 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 );
}
谢谢,
Ali
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;
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 );
}
Thanks,
Ali
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否多次使用 MoveWindow 还是只想调整一次大小?这张图是你自己画的吗?如果是的话,您可以自己使用双缓冲来减少闪烁。否则,尝试使用 WM_CLIPSIBLINGS 和 WM_CLIPCHILDREN,有时这也有帮助。如果您多次或多个窗口调整大小而出现问题,请使用 BeginDeferWindowPos()。
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().