BOOL CAccelView::OnPreparePrinting (CPrintInfo* pInfo)
{
    //
    // Compute the page count.
    //
    if (!pInfo->m_bPreview) {
        CPrintInfo pi;
        if (AfxGetApp ()->GetPrinterDeviceDefaults (&pi.m_pPD->m_pd)) {
            HDC hDC = pi.m_pPD->m_pd.hDC;
            if (hDC == NULL)
                hDC = pi.m_pPD->CreatePrinterDC ();
            if (hDC != NULL) {
                CDC dc;
                dc.Attach (hDC);
                int nWidth = dc.GetDeviceCaps (HORZRES);  // Page width
                int nHeight = dc.GetDeviceCaps (VERTRES); // Page height

                // TODO: Compute nPageCount from nWidth and nHeight

                pInfo->SetMaxPage (nPageCount);
                ::DeleteDC (dc.Detach ());
            }
        }
    }

    //
    // Display the Print dialog and create a printer DC.
    //
    return DoPreparePrinting (pInfo);
}
