char szprinter[80];
char *szDevice,*szDriver,*szOutput;
HDC hdcprint; // 定义唯一设备环境句柄
OrginPoint point;
//定义唯一打印功课
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); //保存打印机设备句柄
TextOut(hdcprint,150,100,"这是第二个例子",17);
// 输出一条直线
RestoreDC(hdcprint,-1); //恢复打印机设备句柄
EndPage(hdcprint); //打印机停纸,停止打印
EndDoc(hdcprint); //结束唯一打印功课
MessageBox("打印完毕!","提示",MB_ICONINFORMATION);
}
// 用API参数DeleteDC销毁唯一打印机设备句柄
DeleteDC(hdcprint);
}
else
{
MessageBox("没有默认打印机,或者没有安装打印机!");
return;
}