⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 print.cpp

📁 C语言编程中算法数据结构中的树行代码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
      lengthDoc = startPos;
    } else {
      lengthPrinted = startPos;
      lengthDoc = endPos;
    }

    if (lengthPrinted < 0)
      lengthPrinted = 0;
    if (lengthDoc > lengthDocMax)
      lengthDoc = lengthDocMax;
  }

  // We must substract the physical margins from the printable area
  frPrint.hdc = hdc;
  frPrint.hdcTarget = hdc;
  frPrint.rc.left = rectMargins.left - rectPhysMargins.left;
  frPrint.rc.top = rectMargins.top - rectPhysMargins.top;
  frPrint.rc.right = ptPage.x - rectMargins.right - rectPhysMargins.left;
  frPrint.rc.bottom = ptPage.y - rectMargins.bottom - rectPhysMargins.top;
  frPrint.rcPage.left = 0;
  frPrint.rcPage.top = 0;
  frPrint.rcPage.right = ptPage.x - rectPhysMargins.left - rectPhysMargins.right - 1;
  frPrint.rcPage.bottom = ptPage.y - rectPhysMargins.top - rectPhysMargins.bottom - 1;
  frPrint.rc.top += headerLineHeight + headerLineHeight / 2;
  frPrint.rc.bottom -= footerLineHeight + footerLineHeight / 2;
  // Print each page
  pageNum = 1;

  while (lengthPrinted < lengthDoc) {
    printPage = (!(pdlg.Flags & PD_PAGENUMS) ||
                 (pageNum >= pdlg.nFromPage) && (pageNum <= pdlg.nToPage));

    wsprintf(pageString, pszPageFormat, pageNum);

    if (printPage) {

      // Show wait cursor...
      SendMessage(hwnd,SCI_SETCURSOR,SC_CURSORWAIT,0);

      // Display current page number in Statusbar
      StatusUpdatePrintPage(pageNum);

      StartPage(hdc);

      SetTextColor(hdc, RGB(0,0,0));
      SetBkColor(hdc, RGB(255,255,255));
      SelectObject(hdc, fontHeader);
      UINT ta = SetTextAlign(hdc, TA_BOTTOM);
      RECT rcw = {frPrint.rc.left, frPrint.rc.top - headerLineHeight - headerLineHeight / 2,
                  frPrint.rc.right, frPrint.rc.top - headerLineHeight / 2};
      rcw.bottom = rcw.top + headerLineHeight;

      if (iPrintHeader < 3)
      {
        ExtTextOut(hdc, frPrint.rc.left + 5, frPrint.rc.top - headerLineHeight / 2,
                      /*ETO_OPAQUE*/0, &rcw, pszDocTitle,
                      lstrlen(pszDocTitle), NULL);
      }

      // Print date in header
      if (iPrintHeader == 0 || iPrintHeader == 1)
      {
        SIZE sizeInfo;
        SelectObject(hdc,fontFooter);
        GetTextExtentPoint32(hdc,dateString,lstrlen(dateString),&sizeInfo);
        ExtTextOut(hdc, frPrint.rc.right - 5 - sizeInfo.cx, frPrint.rc.top - headerLineHeight / 2,
                      /*ETO_OPAQUE*/0, &rcw, dateString,
                      lstrlen(dateString), NULL);
      }

      if (iPrintHeader < 3)
      {
        SetTextAlign(hdc, ta);
        pen = CreatePen(0, 1, RGB(0,0,0));
        penOld = (HPEN)SelectObject(hdc, pen);
        MoveToEx(hdc, frPrint.rc.left, frPrint.rc.top - headerLineHeight / 4, NULL);
        LineTo(hdc, frPrint.rc.right, frPrint.rc.top - headerLineHeight / 4);
        SelectObject(hdc, penOld);
        DeleteObject(pen);
      }
    }

    frPrint.chrg.cpMin = lengthPrinted;
    frPrint.chrg.cpMax = lengthDoc;

    lengthPrinted = SendMessage(hwnd,SCI_FORMATRANGE,printPage,(LPARAM)&frPrint);

    if (printPage) {
      SetTextColor(hdc, RGB(0,0,0));
      SetBkColor(hdc, RGB(255,255,255));
      SelectObject(hdc, fontFooter);
      UINT ta = SetTextAlign(hdc, TA_TOP);
      RECT rcw = {frPrint.rc.left, frPrint.rc.bottom + footerLineHeight / 2,
                  frPrint.rc.right, frPrint.rc.bottom + footerLineHeight + footerLineHeight / 2};

      if (iPrintFooter == 0)
      {
        SIZE sizeFooter;
        GetTextExtentPoint32(hdc,pageString,lstrlen(pageString),&sizeFooter);
        ExtTextOut(hdc, frPrint.rc.right - 5 - sizeFooter.cx, frPrint.rc.bottom + footerLineHeight / 2,
                      /*ETO_OPAQUE*/0, &rcw, pageString,
                      lstrlen(pageString), NULL);

        SetTextAlign(hdc, ta);
        pen = ::CreatePen(0, 1, RGB(0,0,0));
        penOld = (HPEN)SelectObject(hdc, pen);
        SetBkColor(hdc, RGB(0,0,0));
        MoveToEx(hdc, frPrint.rc.left, frPrint.rc.bottom + footerLineHeight / 4, NULL);
        LineTo(hdc, frPrint.rc.right, frPrint.rc.bottom + footerLineHeight / 4);
        SelectObject(hdc, penOld);
        DeleteObject(pen);
      }

      EndPage(hdc);
    }
    pageNum++;

    if ((pdlg.Flags & PD_PAGENUMS) && (pageNum > pdlg.nToPage))
      break;
  }

  SendMessage(hwnd,SCI_FORMATRANGE, FALSE, 0);

  EndDoc(hdc);
  DeleteDC(hdc);
  if (fontHeader) {
    DeleteObject(fontHeader);
  }
  if (fontFooter) {
    DeleteObject(fontFooter);
  }

  // Reset Statusbar to default mode
  StatusSetSimple(hwndStatus,FALSE);

  // Remove wait cursor...
  SendMessage(hwnd,SCI_SETCURSOR,SC_CURSORNORMAL,0);

  return TRUE;
}


//=============================================================================
//
//  EditPrintSetup() - Code from SciTE
//
//  Custom controls: 30 Zoom
//                   31 Spin
//                   32 Header
//                   33 Footer
//                   34 Colors
//
extern "C" UINT_PTR CALLBACK PageSetupHook(HWND hwnd, UINT uiMsg, WPARAM wParam, LPARAM lParam)
{
  switch (uiMsg)
  {
    case WM_INITDIALOG:
      {
        char tch[512];
        char *p1,*p2;

        SendDlgItemMessage(hwnd,30,EM_LIMITTEXT,32,0);

        SendDlgItemMessage(hwnd,31,UDM_SETRANGE,0,MAKELONG((short)20,(short)-10));
        SendDlgItemMessage(hwnd,31,UDM_SETPOS,0,MAKELONG((short)iPrintZoom,0));

        // Set header options
        GetString(IDS_PRINT_HEADER,tch,COUNTOF(tch));
        lstrcat(tch,"|");
        p1 = tch;
        while (p2 = strchr(p1,'|')) {
          *p2++ = '\0';
          if (*p1)
            SendDlgItemMessage(hwnd,32,CB_ADDSTRING,0,(LPARAM)p1);
          p1 = p2; }
        SendDlgItemMessage(hwnd,32,CB_SETCURSEL,(WPARAM)iPrintHeader,0);

        // Set footer options
        GetString(IDS_PRINT_FOOTER,tch,COUNTOF(tch));
        lstrcat(tch,"|");
        p1 = tch;
        while (p2 = strchr(p1,'|')) {
          *p2++ = '\0';
          if (*p1)
            SendDlgItemMessage(hwnd,33,CB_ADDSTRING,0,(LPARAM)p1);
          p1 = p2; }
        SendDlgItemMessage(hwnd,33,CB_SETCURSEL,(WPARAM)iPrintFooter,0);

        // Set color options
        GetString(IDS_PRINT_COLOR,tch,COUNTOF(tch));
        lstrcat(tch,"|");
        p1 = tch;
        while (p2 = strchr(p1,'|')) {
          *p2++ = '\0';
          if (*p1)
            SendDlgItemMessage(hwnd,34,CB_ADDSTRING,0,(LPARAM)p1);
          p1 = p2; }
        SendDlgItemMessage(hwnd,34,CB_SETCURSEL,(WPARAM)iPrintColor,0);

        // Make combos handier
        SendDlgItemMessage(hwnd,32,CB_SETEXTENDEDUI,TRUE,0);
        SendDlgItemMessage(hwnd,33,CB_SETEXTENDEDUI,TRUE,0);
        SendDlgItemMessage(hwnd,34,CB_SETEXTENDEDUI,TRUE,0);
        SendDlgItemMessage(hwnd,1137,CB_SETEXTENDEDUI,TRUE,0);
        SendDlgItemMessage(hwnd,1138,CB_SETEXTENDEDUI,TRUE,0);
      }
      break;

    case WM_COMMAND:
      if (LOWORD(wParam) == IDOK)
      {
        LONG lPos = SendDlgItemMessage(hwnd,31,UDM_GETPOS,0,0);
        if (HIWORD(lPos) == 0)
          iPrintZoom = (int)(short)LOWORD(lPos);
        else
          iPrintZoom = 0;

        iPrintHeader = SendDlgItemMessage(hwnd,32,CB_GETCURSEL,0,0);
        iPrintFooter = SendDlgItemMessage(hwnd,33,CB_GETCURSEL,0,0);
        iPrintColor  = SendDlgItemMessage(hwnd,34,CB_GETCURSEL,0,0);
      }
      break;

    default:
      break;
  }
  return(0);
}


extern "C" void EditPrintSetup(HWND hwnd)
{
  PAGESETUPDLG pdlg = {
                          sizeof(PAGESETUPDLG), 0, 0, 0, 0, {0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, 0, 0, 0, 0, 0, 0
                      };

  pdlg.Flags = PSD_ENABLEPAGESETUPHOOK | PSD_ENABLEPAGESETUPTEMPLATE;
  pdlg.lpfnPageSetupHook = PageSetupHook;
  pdlg.lpPageSetupTemplateName = MAKEINTRESOURCE(IDD_PAGESETUP);

  pdlg.hwndOwner = GetParent(hwnd);
  pdlg.hInstance = g_hInstance;

  if (pagesetupMargin.left != 0 || pagesetupMargin.right != 0 ||
          pagesetupMargin.top != 0 || pagesetupMargin.bottom != 0) {
    pdlg.Flags |= PSD_MARGINS;

    pdlg.rtMargin.left = pagesetupMargin.left;
    pdlg.rtMargin.top = pagesetupMargin.top;
    pdlg.rtMargin.right = pagesetupMargin.right;
    pdlg.rtMargin.bottom = pagesetupMargin.bottom;
  }

  pdlg.hDevMode = hDevMode;
  pdlg.hDevNames = hDevNames;

  if (!PageSetupDlg(&pdlg))
    return;

  pagesetupMargin.left = pdlg.rtMargin.left;
  pagesetupMargin.top = pdlg.rtMargin.top;
  pagesetupMargin.right = pdlg.rtMargin.right;
  pagesetupMargin.bottom = pdlg.rtMargin.bottom;

  hDevMode = pdlg.hDevMode;
  hDevNames = pdlg.hDevNames;
}


//=============================================================================
//
//  EditPrintInit() - Setup default page margin if no values from registry
//
extern "C" void EditPrintInit()
{
  if (pagesetupMargin.left == -1 || pagesetupMargin.top == -1 ||
      pagesetupMargin.right == -1 || pagesetupMargin.bottom == -1)
  {
    char localeInfo[3];
    GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_IMEASURE, localeInfo, 3);

    if (localeInfo[0] == '0') {  // Metric system. '1' is US System
      pagesetupMargin.left = 2000;
      pagesetupMargin.top = 2000;
      pagesetupMargin.right = 2000;
      pagesetupMargin.bottom = 2000; }

    else {
      pagesetupMargin.left = 1000;
      pagesetupMargin.top = 1000;
      pagesetupMargin.right = 1000;
      pagesetupMargin.bottom = 1000; }
  }
}


// End of Print.cpp

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -