如题。

解决方案 »

  1.   

    SendMessage(hTargetView, WM_COMMAND, (WPARAM)ID_FILE_PRINT_DIRECT, 0);
      

  2.   

    void CPrintWndDlg::Print()
    {
    CDC printDC;
    CPrintDialog printDlg(FALSE);
    DOCINFO docInfo; if(printDlg.DoModal()==IDOK)
    {
    HDC hDC;
    hDC=printDlg.GetPrinterDC();
    if(!printDC.Attach(hDC))
    return;
    }
    else
    {
    printDC.Detach();
    return;
    }

    memset(&docInfo,0,sizeof(docInfo));
    docInfo.cbSize=sizeof(DOCINFO);
    docInfo.lpszDocName="Print Window";
    if(printDC.StartDoc(&docInfo)<=0)
    {
    printDC.Detach();
    return;
    }
    printDC.StartPage();

    //这里进行你的打印工作 printDC.EndPage();
    printDC.EndDoc(); printDC.Detach();}
    上面的代码取得一个打印机的DC:-)
      

  3.   

    你可以使用下面的函数来获得打印机的句并
    HDC GetPrinterDC (void)
    {
         DWORD            dwNeeded, dwReturned ;
         HDC              hdc ;
         PRINTER_INFO_4 * pinfo4 ;
         PRINTER_INFO_5 * pinfo5 ;      if (GetVersion () & 0x80000000)         // Windows 98
         {
              EnumPrinters (PRINTER_ENUM_DEFAULT, NULL, 5, NULL,
                            0, &dwNeeded, &dwReturned) ;          pinfo5 = malloc (dwNeeded) ;          EnumPrinters (PRINTER_ENUM_DEFAULT, NULL, 5, (PBYTE) pinfo5,
                            dwNeeded, &dwNeeded, &dwReturned) ;          hdc = CreateDC (NULL, pinfo5->pPrinterName, NULL, NULL) ;          free (pinfo5) ;
         }
         else                                    // Windows NT
         {
              EnumPrinters (PRINTER_ENUM_LOCAL, NULL, 4, NULL,
                            0, &dwNeeded, &dwReturned) ;          pinfo4 = malloc (dwNeeded) ;          EnumPrinters (PRINTER_ENUM_LOCAL, NULL, 4, (PBYTE) pinfo4,
                            dwNeeded, &dwNeeded, &dwReturned) ;          hdc = CreateDC (NULL, pinfo4->pPrinterName, NULL, NULL) ;          free (pinfo4) ;
         }
         return hdc ;   
    }
      

  4.   

    然后
    BOOL PrintMyPage (HWND hwnd)
    {
         static DOCINFO di = { sizeof (DOCINFO), TEXT ("Print3: Printing") } ;
       //  BOOL           bSuccess = TRUE ;
         HDC            hdcPrn ;
         int            xPage, yPage ;
         
         if (NULL == (hdcPrn = GetPrinterDC()))
              return FALSE ;
         
         xPage = GetDeviceCaps (hdcPrn, HORZRES) ;
         yPage = GetDeviceCaps (hdcPrn, VERTRES) ;
         
         EnableWindow (hwnd, FALSE) ;
         
      //   bUserAbort = FALSE ;
       //  hDlgPrint = CreateDialog (hInst, TEXT ("PrintDlgBox"), 
       //                            hwnd, PrintDlgProc) ;
         
       //  SetAbortProc (hdcPrn, AbortProc) ;
         
         if (StartDoc (hdcPrn, &di) > 0)
         {
              if (StartPage (hdcPrn) > 0)
              {
                   PageGDICalls (hdcPrn, xPage, yPage) ;//draw
                   
                   if (EndPage (hdcPrn) > 0)
                        EndDoc (hdcPrn) ;
              //     else
             //           bSuccess = FALSE ;
              }
         }
      //   else
      //        bSuccess = FALSE ;  //   if (!bUserAbort)
       //  {
       //       EnableWindow (hwnd, TRUE) ;
       //       DestroyWindow (hDlgPrint) ;
       //  }
         
         DeleteDC (hdcPrn) ;
         
         return TRUE;//bSuccess && !bUserAbort ;
    }