当前位置:首页 » 多媒体相关

我的程序要的A3横向的纸,而这个打印机经他们共享后要打A4的纸,这怎么解决?


不可能我程序要打印时,就去调打印机属性吧!

推荐阅读

  • 新旧一起降 硕泰克6200/9600显卡调价 [详细内容]
  • IT [详细内容]
  • IT [详细内容]
  • 红色威龙来袭 捷波移动9600显卡发售 [详细内容]
  • 解决短信选项没有回复,增加至新名片和直... [详细内容]
  • IT [详细内容]
  • 添个选择 双敏新款9600PRO悄然入村 [详细内容]
  • 网友回答:
    网友:lihonggen0

    option   explicit  
       
      public   enum   printerorientationconstants  
              orientportrait   =   1  
              orientlandscape   =   2  
      end   enum  
       
      private   type   devmode  
              dmdevicename   as   string   *   32  
              dmspecversion   as   integer  
              dmdriverversion   as   integer  
              dmsize   as   integer  
              dmdriverextra   as   integer  
              dmfields   as   long  
              dmorientation   as   integer  
              dmpapersize   as   integer  
              dmpaperlength   as   integer  
              dmpaperwidth   as   integer  
              dmscale   as   integer  
              dmcopies   as   integer  
              dmdefaultsource   as   integer  
              dmprintquality   as   integer  
              dmcolor   as   integer  
              dmduplex   as   integer  
              dmyresolution   as   integer  
              dmttoption   as   integer  
              dmcollate   as   integer  
              dmformname   as   string   *   32  
              dmunusedpadding   as   integer  
              dmbitsperpel   as   integer  
              dmpelswidth   as   long  
              dmpelsheight   as   long  
              dmdisplayflags   as   long  
              dmdisplayfrequency   as   long  
      end   type  
       
      private   type   printer_defaults  
              pdatatype   as   string  
              pdevmode   as   long  
              desiredaccess   as   long  
      end   type  
       
      private   type   printer_info_2  
              pservername   as   long  
              pprintername   as   long  
              psharename   as   long  
              pportname   as   long  
              pdrivername   as   long  
              pcomment   as   long  
              plocation   as   long  
              pdevmode   as   long  
              psepfile   as   long  
              pprintprocessor   as   long  
              pdatatype   as   long  
              pparameters   as   long  
              psecuritydescriptor   as   long  
              attributes   as   long  
              priority   as   long  
              defaultpriority   as   long  
              starttime   as   long  
              untiltime   as   long  
              status   as   long  
              cjobs   as   long  
              averageppm   as   long  
      end   type  
       
      *******************  
        idmpaper值       纸张    
        8                         a3        
        9                         a4        
        11                       a5        
        13                       b5        
      *******************  
       
      private   const   dm_in_buffer   as   long   =   8  
      private   const   dm_out_buffer   as   long   =   2  
      private   const   dm_orientation   as   long   =   &h1  
      private   const   dm_papersize   =   &h2&  
       
      private   const   printer_access_administer   as   long   =   &h4  
      private   const   printer_access_use   as   long   =   &h8  
      private   const   standard_rights_required   as   long   =   &hf0000  
      private   const   printer_all_access   =   (standard_rights_required   _  
              or   _  
              printer_access_administer   or   printer_access_use)  
       
      private   declare   sub   copymemory   lib   "kernel32"   alias   _  
              "rtlmovememory"   _  
              (hpvdest   as   any,   hpvsource   as   any,   byval   _  
              cbcopy   as   long)  
       
      private   declare   function   openprinter   lib   "winspool.drv"   alias   _  
              "openprintera"   (byval   pprintername   as   string,   phprinter   as   _  
              long,   pdefault   as   any)   as   long  
       
      private   declare   function   closeprinter   lib   "winspool.drv"   _  
              (byval   hprinter   as   long)   as   long  
       
      private   declare   function   documentproperties   lib   "winspool.drv"   _  
              alias   "documentpropertiesa"   (byval   hwnd   as   long,   byval   hprinter   _  
              as   long,   _  
              byval   pdevicename   as   string,   pdevmodeoutput   as   _  
              any,   _  
              pdevmodeinput   as   any,   _  
              byval   fmode   as   long)   as   long  
       
      private   declare   function   getprinter   lib   "winspool.drv"   _  
              alias   "getprintera"   (byval   hprinter   as   long,   byval   level   as   long,   _  
              pprinter   as   any,   byval   cbbuf   as   long,   pcbneeded   as   long)   as   _  
              long  
       
      private   declare   function   setprinter   lib   "winspool.drv"   _  
              alias   "setprintera"   (byval   hprinter   as   long,   byval   level   as   long,   _  
              pprinter   as   any,   byval   command   as   long)   as   long  
       
      在打印或预览之前直接调用setdefaultprinterorientation   打印走向常数。注意:红色注释部分用于改变纸张的大小。  
      function   setdefaultprinterorientation(byval   eorientation   as   _  
              printerorientationconstants,   idmpaper   as   integer)   as   boolean  
       
              dim   bdevmode()   as   byte  
              dim   bprinterinfo2()   as   byte  
              dim   hprinter   as   long  
              dim   lresult   as   long  
              dim   nsize   as   long  
              dim   sprnname   as   string  
              dim   dm   as   devmode  
              dim   olddm   as   devmode  
              dim   pd   as   printer_defaults  
              dim   pi2   as   printer_info_2  
       
                获取默认打印机的设备名称  
              sprnname   =   printer.devicename  
                由于要调用setprinter,所以  
                如果是在nt下就要求printer_all_access  
              pd.desiredaccess   =   printer_all_access  
       
                获取打印机句柄  
              if   openprinter(sprnname,   hprinter,   pd)   then  
                       
                        获取printer_info_2结构要求的字节数  
       
                      call   getprinter(hprinter,   2&,   0&,   0&,   nsize)  
                      redim   bprinterinfo2(1   to   nsize)   as   byte  
                      lresult   =   getprinter(hprinter,   2,   bprinterinfo2(1),   nsize,   nsize)  
                      call   copymemory(pi2,   bprinterinfo2(1),   len(pi2))  
                      nsize   =   documentproperties(0&,   hprinter,   sprnname,   0&,   0&,   0)  
                                  redim   bdevmode(1   to   nsize)  
                      if   pi2.pdevmode   then  
                              call   copymemory(bdevmode(1),   byval   pi2.pdevmode,   len(dm))  
                      else  
                              call   documentproperties(0&,   hprinter,   sprnname,   bdevmode(1),   0&,   dm_out_buffer)  
                      end   if  
                       
                      call   copymemory(dm,   bdevmode(1),   len(dm))  
                      call   copymemory(olddm,   bdevmode(1),   len(olddm))  
                      with   dm  
                                设置新的走向  
                              .dmorientation   =   eorientation  
                              .dmfields   =   dm_orientation  
                              .dmpapersize   =   idmpaper       将纸张大小设为idmpaper,请自行更改所需大小  
                              .dmpaperlength   =   idmpaperlength  
                              .dmpaperwidth   =   idmpaperwidth  
                              .dmfields   =   dm_papersize     必须,否则无法设置纸张大小  
                      end   with  
                       
                      call   copymemory(bdevmode(1),   dm,   len(dm))  
       
                      call   documentproperties(0&,   hprinter,   sprnname,   _  
                                      bdevmode(1),   bdevmode(1),   dm_in_buffer   or   _  
                                      dm_out_buffer)  
                       
                      pi2.pdevmode   =   varptr(bdevmode(1))  
                       
                      lresult   =   setprinter(hprinter,   2,   pi2,   0&)  
                       
                      call   closeprinter(hprinter)  
                      setdefaultprinterorientation   =   true  
              else  
                      setdefaultprinterorientation   =   false  
              end   if  
       
      end   function  
       
       
       
     

    .

    讨论区

    Login