char szprinter[80];
char *szDevice,*szDriver,*szOutput;
HDC hdcprint; // 定义一个设备环境句柄
//定义一个打印作业
static DOCINFO di={sizeof(DOCINFO),"printer",NULL};
// 得到设备字符串存入数组szprinter中
GetProfileString("windows","device",",,,",szprinter,80);
// 将设备字符串分解
if(NULL!=(szDevice=strtok(szprinter,","))&&NULL!=(szDriver=strtok(NULL,","))&&NULL!=(szOutput=strtok(NULL,",")))
// 创建一个打印机设备句柄
if((hdcprint=CreateDC(szDriver,szDevice,szOutput,NULL))!=0){
if(StartDoc(hdcprint,&di)>0){ //开始执行一个打印作业
StartPage(hdcprint); //打印机走纸,开始打印
SaveDC(hdcprint); //保存打印机设备句柄
///////这里应该如何写啊,一些字体大小的设置和对齐方式
int y=1;
TextOut(hdcprint,10,y,m_ShopCName.c_str(),m_ShopCName.length());
y+=20;
TextOut(hdcprint,10,y,m_ShopEName.c_str(),m_ShopEName.length());
y+=20;
TextOut(hdcprint,10,y,m_VoucherNo.c_str(),m_VoucherNo.length());
RestoreDC(hdcprint,-1); //恢复打印机设备句柄
EndPage(hdcprint); //打印机停纸,停止打印
EndDoc(hdcprint); //结束一个打印作业
}
// 用API函数DeleteDC销毁一个打印机设备句柄
DeleteDC(hdcprint);
}
else
MessageBox(NULL,"没有默认打印机,或者没有安装打印机!",NULL,MB_OK);