aardio中调用系统默认打印机系列
编辑时间:2018-07-21 作者:楚鸟 浏览量:4135 来源:网友发表

话不多说,直接上代码吧。

//打印
import win.ui;
/*DSG{{*/
var winform = win.form(text="调用打印机";right=759;bottom=469)
winform.add(
btnEnumPrinters={cls=
"button";text="枚举打印机";left=441;top=193;right=692;bottom=261;z=4};
btnPrint={cls=
"button";text="调用API打印";left=441;top=32;right=692;bottom=100;z=1};
btnPrintDefault={cls=
"button";text="默认打印机输出";left=442;top=274;right=693;bottom=342;z=5};
btnWbPrint={cls=
"button";text="使用HTML打印";left=444;top=108;right=695;bottom=176;z=2};
edit={cls=
"edit";left=40;top=36;right=417;bottom=429;edge=1;multiline=1;z=3}
)
/*}}*/
 
winform.btnPrint.oncommand = 
function(id,event){
    
import win.dlg.print;
    
var printDlg = win.dlg.print(winform);
    
if(!printDlg.doModal()) return;
 
    
//开始打印
    class DOCINFO {
        int cbSize = 20;
        ustring docName;
        ustring output;
        ustring datatype;
        INT fwType;
    }
    ::Gdi32.StartDoc(printDlg.hdc,DOCINFO());
    ::Gdi32.StartPage(printDlg.hdc);
 
    
//GDI+绘图
    import gdip.graphics;
    
import gdip.family;
    
var graphics = gdip.graphics(printDlg.hdc);
    
var brush = gdip.solidBrush(0xFFFF0000);
    
var family = gdip.family("宋体");
    
var strformat = gdip.stringformat(); 
    
var curFont = family.createFont(  15,2/*_GdipFontStyleItalic*/, 2/*_GdipUnitPixel*/)
    graphics.drawString( 
"Hellow world! 打印测试!!"  , curFont
    ,  gdip.RECTF(15,15,500,150), strformat,brush);
    brush.delete()
    curFont.delete()
    strformat.delete();
    family.delete(); 
      
    
//结束打印    
    ::Gdi32.EndPage(printDlg.hdc);
    ::Gdi32.EndDoc(printDlg.hdc); 
    printDlg.free()   
}
 
winform.btnWbPrint.oncommand = 
function(id,event){
    
import web.mshtml;
    wbPrint = web.mshtml();
    wbPrint.write(
"测试一下")
    wbPrint.getDoc().execCommand(
"print")
}
 
winform.btnEnumPrinters.oncommand = 
function(id,event){
 
    Winspool = raw.loadDll(
"Winspool.drv");
     
    
var needed = {INT value}
    
var returned = {INT value}
    Winspool.EnumPrinters(2
/*_PRINTER_ENUM_LOCAL*/null, 4, null, 0, needed, returned) ;
             
    
var buffer = raw.buffer(needed.value)
    Winspool.EnumPrinters(2
/*_PRINTER_ENUM_LOCAL*/null, 4, buffer, #buffer, needed, returned) ;
     
    
var info4 = raw.convert(buffer,{
        struct printers[] = {
            {
                ustring  printerName;
                ustring  serverName;
                INT   attributes;
            };
            length = returned.value;
        }
    })
     
    
for(i=1;#info4.printers;1){ 
        winform.edit.print(info4.printers[ i ].printerName,info4.printers[ i ].attributes)
    } 
}
 
winform.btnPrintDefault.oncommand = 
function(id,event){
 
    Winspool = raw.loadDll(
"Winspool.drv");
     
    
var buffer = raw.buffer(1024)
    
var length = { INT value = 1024};
    
if(!Winspool.GetDefaultPrinter(buffer,length) )return;
     
    
var hdcPrint = ::Gdi32.CreateDC(null, buffer, nullnull);
     
    
class DOCINFO {
        int cbSize = 20;
        ustring docName;
        ustring output;
        ustring datatype;
        INT fwType;
    }
    ::Gdi32.StartDoc(hdcPrint,DOCINFO());
    ::Gdi32.StartPage(hdcPrint);
 
    ::Gdi32.TextOut(hdcPrint,20,20,
"测试打印",4);
   
    ::Gdi32.EndPage(hdcPrint);
    ::Gdi32.EndDoc(hdcPrint); 
    ::Gdi32.DeleteDC(hdcPrint);
}
 
winform.show() 
win.loopMessage();



文章转自:http://www.stm32cube.com/article/156

来说两句吧