【发布时间】:2013-07-19 12:31:11
【问题描述】:
这是此代码用于保持图像的纵横比的代码,当控件转到 int WindowRatio = WidthOfPreviewPane / HeightOfPreviewPane; 时它会崩溃; 谁能告诉我为什么??
int WidthOfPreviewPane = RECTWIDTH(m_rcParent);
int HeightOfPreviewPane = RECTHEIGHT(m_rcParent) ;
int ImageRatio = WidthOfImage / HeightOfImage;
int WindowRatio = WidthOfPreviewPane / HeightOfPreviewPane;
if (WindowRatio > ImageRatio && WidthOfPreviewPane< WidthOfImage)
{
m_iFinalHeight = HeightOfPreviewPane;
m_iFinalWidth = m_iFinalHeight * ImageRatio;
MessageBox(NULL, L"1",L"Error",
MB_ICONERROR | MB_OK);
}
else if (WindowRatio < ImageRatio && WidthOfPreviewPane< WidthOfImage)
{
m_iFinalWidth = WidthOfPreviewPane;
m_iFinalHeight = m_iFinalWidth / ImageRatio;
MessageBox(NULL, L"2",L"Error",
MB_ICONERROR | MB_OK);
}
else if(WindowRatio > ImageRatio && WidthOfPreviewPane> WidthOfImage)
{
m_iFinalHeight = HeightOfImage;
m_iFinalWidth = WidthOfImage;
MessageBox(NULL, L"3",L"Error",
MB_ICONERROR | MB_OK);
}
else if(WindowRatio < ImageRatio && WidthOfPreviewPane> WidthOfImage)
{
m_iFinalHeight = HeightOfImage;
m_iFinalWidth = WidthOfImage;
MessageBox(NULL, L"4",L"Error",
MB_ICONERROR | MB_OK);
}
【问题讨论】:
-
假设窗口?您是否尝试在调试器中运行代码?窗口(m_rcParent)是否可见,否则大小为 0 导致 devisionbyzero
-
在问题行运行前检查
HeightOfPreviewPane的值是多少 -
是
HeightOfPreviewPane0?检查一下。 -
是的 WidthOfPreviewPane 和 HeightOfPreviewPane 都为零..我的预览窗格怎么可能完全打开..
-
是的,算法是绝对正确的,有一个小问题,因为我必须设置窗口位置..它由 if(WidthOfPreviewPane!= 0 && HeightOfPreviewPane!=0 ) 解决,只有让光标离开当条件正确时在里面。这是一个很大的帮助 anniekim
标签: c windows winapi preview-pane