C 使程序崩溃的图像的纵横比

C 使程序崩溃的图像的纵横比,c,windows,winapi,preview-pane,C,Windows,Winapi,Preview Pane,这是一段代码,当控件转到int WindowRatio=WidthOfPrewPane/HeightOfPrewPane时,该代码将保持崩溃图像的纵横比; 有人能说出原因吗 int WidthOfPreviewPane = RECTWIDTH(m_rcParent); int HeightOfPreviewPane = RECTHEIGHT(m_rcParent) ; int ImageRatio = WidthOfImage / HeightOfImage; int WindowRati

这是一段代码,当控件转到int WindowRatio=WidthOfPrewPane/HeightOfPrewPane时,该代码将保持崩溃图像的纵横比; 有人能说出原因吗

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);

}
int-widthofprovpane=RECTWIDTH(m_rcParent);
前面板的内部高度=矩形高度(m_rcParent);
int ImageRatio=图像的宽度/高度;
int WindowRatio=前置平面的宽度/前置平面的高度;
if(窗口比率>图像比率和前置平面宽度<图像宽度)
{
m_iFinalHeight=前置平面的高度;
m_iFinalWidth=m_iFinalHeight*成像比;
MessageBox(空,L“1”,L“错误”,
MB_i错误| MB_正常);
}
else if(窗口比率<图像比率和前置平面宽度<图像宽度)
{
m_iFinalWidth=前置平面的宽度;
m_iFinalHeight=m_iFinalWidth/成像比;
MessageBox(空,L“2”,L“错误”,
MB_i错误| MB_正常);
}
else if(窗口比率>图像比率和前置平面宽度>图像宽度)
{
m_iFinalHeight=图像的高度;
m_iFinalWidth=图像的宽度;
MessageBox(空,L“3”,L“错误”,
MB_i错误| MB_正常);
}
else if(窗口比率<图像比率和前置平面宽度>图像宽度)
{
m_iFinalHeight=图像的高度;
m_iFinalWidth=图像的宽度;
MessageBox(空,L“4”,L“错误”,
MB_i错误| MB_正常);
}

这个算法的逻辑是正确的,最后我发现WidthOfPrewPane和HeightOfPrewPane=0,因为我写这段代码的函数最后被初始化了,所以这两个函数在我调试它们的时候没有初始化,我把它们放在if条件下避免了这个问题,这会让控件消失如果它们的值不是0,并且运行良好,则返回内部。 看到这个了吗-

 if(WidthOfPreviewPane!= 0 && HeightOfPreviewPane!=0 )
            {
                  conditions here......

            }

这就解决了。

假设windows?您是否尝试在调试器中运行代码?窗口(m_rcParent)是否可见,否则大小为0,导致在运行问题行之前执行devisionbyzerocheck以查看
HeightOfPreviewPane
的值是否为
HeightOfPreviewPane
0
?检查它。是的,它PreviewPane的宽度和PreviewPane的高度都为零。我的预览窗格完全打开的可能性如何。是的,算法完全正确。有一个小问题,因为我必须设置窗口位置。它由if(PreviewPane的宽度!=0和PreviewPane的高度!=0)解决这对anniekim有很大的帮助