0

here is the code this code is to maintain the aspect ratio of the image it crashes when the control goes to int WindowRatio = WidthOfPreviewPane / HeightOfPreviewPane; can anyone give idea why ??

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

}
Xearinox
  • 3,224
  • 2
  • 24
  • 38
Sss
  • 1,519
  • 8
  • 37
  • 67
  • Assuming windows? Have you tried to run the code in the debugger? Is the window (m_rcParent) visible, otherwise the size is 0 causing a devisionbyzero – dmaij Jul 19 '13 at 12:34
  • check to see what the value of `HeightOfPreviewPane` is before the problem line is run – Justin L. Jul 19 '13 at 12:35
  • 2
    is `HeightOfPreviewPane` `0`? check it. – Annie Kim Jul 19 '13 at 12:36
  • yes it WidthOfPreviewPane and HeightOfPreviewPane both are zero ..how it is possible my preview pane is fully open.. – Sss Jul 19 '13 at 12:43
  • yes the algo is absolutey correct there was a little problem because i had to set window position..it is solved by if(WidthOfPreviewPane!= 0 && HeightOfPreviewPane!=0 ) which ony let the cursor go inside when the condition is correct.that was a big help anniekim – Sss Jul 19 '13 at 14:00

1 Answers1

0

the logic of this algo is correct finally i found that WidthOfPreviewPane and HeightOfPreviewPane=0 its because the function in which i have written this code was initialized at last so these 2 were not initialized that time when i debugged them and i avoided thid problem by putting them in in a if condition which will let the control go inside if their value is not 0 and it worked nicely. see this-

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

            }

and thats solved.

Sss
  • 1,519
  • 8
  • 37
  • 67