void CProgressWnd::SetWindowSize(int nNumTextLines, int nWindowWidth /*=390*/)
{
    int nMargin = 10;
    CSize EdgeSize(::GetSystemMetrics(SM_CXEDGE), ::GetSystemMetrics(SM_CYEDGE));

    CRect TextRect, CancelRect, ProgressRect;
    CSize CancelSize;

    // Set up a default size for the text area in case things go wrong
    TextRect.SetRect(nMargin,nMargin, nWindowWidth-2*nMargin, 100+2*nMargin);

    // Get DrawText to tell us how tall the text area will be (while we're at
    // it, we'll see how big the word "Cancel" is)
    CDC* pDC = GetDC();
    if (pDC)
	{
        CFont* pOldFont = pDC->SelectObject(&m_font);
        CString str = _T("M");
        for (int i = 0; i < nNumTextLines-1; i++)
			str += _T("\nM");
        pDC->DrawText(str, TextRect, DT_CALCRECT|DT_NOCLIP|DT_NOPREFIX);
        TextRect.right = TextRect.left + nWindowWidth;
        CancelSize = pDC->GetTextExtent(m_strCancelLabel + _T("  ")) +
                                             CSize(EdgeSize.cx*4, EdgeSize.cy*3);
        pDC->SelectObject(pOldFont);
        ReleaseDC(pDC);
    }
    
    // Work out how big (and where) the cancel button should be
    CancelRect.SetRect(TextRect.right-CancelSize.cx, TextRect.bottom+nMargin, 
                       TextRect.right, TextRect.bottom+nMargin + CancelSize.cy);


    // Work out how big (and where) the progress control should be
    ProgressRect.SetRect(TextRect.left, CancelRect.top + EdgeSize.cy, 
                         CancelRect.left-nMargin, CancelRect.bottom - EdgeSize.cy);


    // Resize the main window to fit the controls
    CSize ClientSize(nMargin + TextRect.Width() + nMargin,
                     nMargin + TextRect.Height() + nMargin + CancelRect.Height() + nMargin);

    CRect WndRect, ClientRect;
    GetWindowRect(WndRect); GetClientRect(ClientRect);
    WndRect.right = WndRect.left + WndRect.Width()-ClientRect.Width()+ClientSize.cx;
    WndRect.bottom = WndRect.top + WndRect.Height()-ClientRect.Height()+ClientSize.cy;
    MoveWindow(WndRect);

    // Now reposition the controls...
    m_wndProgress.MoveWindow(ProgressRect);
    m_CancelButton.MoveWindow(CancelRect);
    m_Text.MoveWindow(TextRect);
}
Ejemplo n.º 2
0
//=============================================================================
CXProgressWnd& CXProgressWnd::SetWindowSize(int nNumTextLines, int nWindowWidth /*=390*/)
//=============================================================================
{
	int nWidth = nWindowWidth;
	int nMargin = 10;

	CSize EdgeSize(::GetSystemMetrics(SM_CXEDGE), ::GetSystemMetrics(SM_CYEDGE));
	CSize CancelSize;

	CRect CancelRect, ProgressRect, AviRect;

 	AviRect.SetRectEmpty();
	if (IsWindow(m_avi.m_hWnd))
	{
		// we'll adjust the width later
		AviRect.SetRect(nMargin, nMargin, 
						nMargin + m_nAviHeight, nMargin + m_nAviHeight);
	}

	// set up a default size for the text area in case things go wrong
	m_TextRect.SetRect(nMargin, AviRect.bottom+nMargin, 
					   nWindowWidth-2*nMargin, AviRect.bottom+100+2*nMargin);

	m_TimeLeftRect.SetRectEmpty();

	// get DrawText to tell us how tall the text area will be (while we're at
	// it, we'll see how big the word "Cancel" is)
	CDC* pDC = GetDC();
	if (pDC)
	{
		CFont *pOldFont = pDC->SelectObject(&m_font);
		CString str = _T("M");
		for (int i = 0; i < nNumTextLines-1; i++)
			str += _T("\nM");
		pDC->DrawText(str, m_TextRect, DT_CALCRECT|DT_NOCLIP|DT_NOPREFIX);
		if (m_bTimeLeft)
			pDC->DrawText(_T("M"), 1, m_TimeLeftRect, 
					DT_CALCRECT|DT_NOCLIP|DT_NOPREFIX);
		nWidth = max(nWindowWidth, m_TextRect.Width()+2*nMargin);
		m_TextRect.right = nWidth - nMargin;
		CancelSize = pDC->GetTextExtent(m_strCancelLabel + _T("  "));
		CancelSize += CSize(EdgeSize.cx*11, EdgeSize.cy*5);
		pDC->SelectObject(pOldFont);
		ReleaseDC(pDC);
	}

	AviRect.right = m_TextRect.right;

	// Work out how big (and where) the progress control should be
	ProgressRect.SetRect(m_TextRect.left,  m_TextRect.bottom + nMargin, 
						 m_TextRect.right, m_TextRect.bottom + nMargin + CancelSize.cy);

	if (m_bTimeLeft)
	{
		// Work out how big (and where) the time left text should be
		int h = m_TimeLeftRect.Height();
		m_TimeLeftRect.SetRect(m_TextRect.left,  ProgressRect.bottom + nMargin, 
							   m_TextRect.right, ProgressRect.bottom + nMargin + h);
	}
	else
	{
		m_TimeLeftRect = ProgressRect;
	}

	// work out how big (and where) the cancel button should be
	CancelRect.SetRect(ProgressRect.right - CancelSize.cx, m_TimeLeftRect.bottom + nMargin, 
					   ProgressRect.right, m_TimeLeftRect.bottom + nMargin + CancelSize.cy);

	// resize the main window to fit the controls
	CSize ClientSize(nWidth, nMargin + CancelRect.bottom);

	CRect WndRect, ClientRect;
	GetWindowRect(WndRect); 
	GetClientRect(ClientRect);
	WndRect.right  = WndRect.left + WndRect.Width()  - ClientRect.Width()  + ClientSize.cx;
	WndRect.bottom = WndRect.top  + WndRect.Height() - ClientRect.Height() + ClientSize.cy;
	MoveWindow(WndRect);

	// now reposition the controls...
	if (IsWindow(m_avi.m_hWnd))
		m_avi.MoveWindow(AviRect);
// start modified code: added to allow dialog with only a message
	if (m_bEnableProgressBar)
// end modified code
		m_wndProgress.MoveWindow(ProgressRect);
// start modified code: added to allow dialog with only a message
	if (m_bEnableCancel)
// end modified code
		m_CancelButton.MoveWindow(CancelRect);
	return *this;
}