开放一个VC打印机接口,这接口比较容易..
//定义一个打印作业 DOCINFO ENPrinterA9::di={sizeof(DOCINFO),"printer",NULL};ENPrinterA9::ENPrinterA9(HWND hwnd,LPDIRECT3DDEVICE9 pd3dDevice,ENd3d *d3dOb){ memset(this,0x00,sizeof(ENPrinterA9)); hWnd=hwnd; m_pd3dDevice=pd3dDevice; // Direct3D设备指针(下级) ENd3dOb=d3dOb; }void ENPrinterA9::ENPrinterA9Ini(){ int i=0; // 得到设备字符串存入数组szprinter中 GetProfileString("windows","device",",,,",szprinter,200); // 将设备字符串分解 if(NULL!=(szDevice=strtok(szprinter,",")) && NULL!=(szDriver=strtok(NULL,",")) && NULL!=(szOutput=strtok(NULL,","))) { // 创建一个打印机设备句柄 if((hdcprint=CreateDC(szDriver,szDevice,szOutput,NULL))!=0) { } else { MessageBox(hWnd, "没有默认打印机,或者没有安装打印机", "FREE_OK", MB_OK); } } else { cout<<"没有检测到打印机"<<endl; } }void ENPrinterA9::ENPrinterA9Free(){// if(hdcprint)// { RestoreDC(hdcprint,-1); //恢复打印机设备句柄 EndDoc(hdcprint); //结束一个打印作业 // 用API函数DeleteDC销毁一个打印机设备句柄 DeleteDC(hdcprint); // }// delete szDriver;// delete szDevice;// delete szOutput;}void ENPrinterA9::PrinterData(int posx,int height,char *data){ //设置开始打印 StartDoc(hdcprint,&di); int i,j,k; StartPage(hdcprint); //打印机走纸,开始打印 SaveDC(hdcprint); //保存打印机设备句柄 int len=strlen(data); TextOut(hdcprint,posx,height,data,len); RestoreDC(hdcprint,-1); //恢复打印机设备句柄 EndDoc(hdcprint); //结束一个打印作业 EndPage(hdcprint); //打印机停纸,停止打印 }