2013-07-19 3 views
0

이 코드는 컨트롤이 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); 

} 
+0

가정? 디버거에서 코드를 실행하려고 시도 했습니까? 창문 (m_rcParent)이 보이는지 확인합니다. 그렇지 않으면 크기가 0이므로 devisionbyzero가 발생합니다. – dmaij

+0

'HeightOfPreviewPane'의 값이 문제 행보다 먼저 실행되는지 확인합니다. –

+2

은'HeightOfPreviewPane'가 '0'입니까? 확인해 봐. –

답변

0

이 너 한테의 논리는 결국 내가 그들을 디버깅 할 때 WidthOfPreviewPane와 나는이 코드를 작성한있는 기능이 마지막에 초기화 그 때문에 HeightOfPreviewPane = 0 그래서이 2 시간을 초기화되지 않은 것을 발견 올바른지 그리고 나는 그 값이 0이 아니고 잘 작동한다면 컨트롤을 내부로 들여 보낼 if 조건에 넣음으로써 문제를 피할 수 있습니다. 참조 -

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

      } 

및 해결 된 사항.

관련 문제