⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dodemo.cpp

📁 WinCE PDA打印机测试程序
💻 CPP
📖 第 1 页 / 共 3 页
字号:
// DoDemo.cpp : Defines the entry point for the application.
#ifndef _WIN32_WCE
#define _WIN32_WINNT 0x0400
#endif

#include "stdafx.h"
#include "resource.h"
#include <Atlbase.h>

#pragma warning( disable : 4305 4244)  // Disable "truncation from double to float" warning messages

//PrEngineCE.tlb is the COM Type Library created by PrinterCE ATL control
#import "PrEngineCE.tlb" raw_interfaces_only no_namespace
#include "PrCEUser.h" //PrinterCE defs file that defines all user constants

extern HINSTANCE hInst;

#define FIRST_BUTTON	IDCC_BROCHURE
#define LAST_BUTTON		IDCC_LINEFUN
#define TOTAL_BUTTONS (LAST_BUTTON-FIRST_BUTTON+1)
int ButtonVals[TOTAL_BUTTONS];

LPTSTR DemoNames[] = {
	TEXT("Printing Brochure"),
	TEXT("Printing Form Demo"),
	TEXT("Printing Thumbnail Images"),
	TEXT("Printing Barcode Demo"),
	TEXT("Printing Text Wheel"),
	TEXT("Printing Image Rotation"),
	TEXT("Printing Line Fun Demo"),
};

DWORD PrintContinuously=FALSE;


//COM Control Pointers for PrinterCE and BarcodeCE
CComQIPtr<IPrinterCE> spPrinterCE;
CComQIPtr<IBarcodeCE> spBarcodeCE;
CComQIPtr<IAsciiCE2> spAsciiCE;

//Global VARIANT data values used by demo (see comments below)
VARIANT globV_x1,globV_y1,globV_bool,globV_NULL;
//These flags will be set FALSE if the controls cannot be created.
BOOL BarcodeCE_Flag=TRUE;
BOOL AsciiCE_Flag=TRUE;

//DWORD StartTime;
/************************************************************************
************************************************************************/
void DbgPrintf(LPTSTR lpszFmt, ...)
{
	int count;
	va_list ap;
	TCHAR buffer[150];

	va_start(ap, lpszFmt);
	count = wvsprintf(buffer, lpszFmt, ap);
	va_end(ap);
	if (count > 0) {
		MessageBox(NULL,buffer,TEXT("Alert..."), MB_OK | MB_ICONINFORMATION | MB_SETFOREGROUND | MB_TOPMOST | MB_APPLMODAL );
	}
}

/*********************************************************
*********************************************************/
void DonePrinting()
{
	if (spPrinterCE) {
		spPrinterCE.Release();
	}
	if (spBarcodeCE) {
		spBarcodeCE.Release();
	}
	if (spAsciiCE) {
		spAsciiCE.Release();
	}
}

const CLSID CLSID_PrinterCE = {0x417B40A5,0x0EBA,0x11D3,{0x9F,0xA7,0x00,0xA0,0xCC,0x27,0x5E,0x38}};
const CLSID CLSID_BarcodeCE = {0x3ABA8790,0x3940,0x11D3,{0x90,0xFF,0x00,0xA0,0xCC,0x27,0x5E,0x38}};
const CLSID CLSID_AsciiCE   = {0x77821295,0xE7C0,0x4BC9,{0xA4,0x56,0x90,0xAF,0x9E,0x8B,0x80,0x00}};
const CLSID CLSID_AsciiCE2  = {0xC37AEA60,0xA7CA,0x40BE,{0xA2,0xE6,0x93,0x5E,0xB3,0x99,0x3B,0xBE}};


/*********************************************************
	InitPrinterCE() - Create instances of PrinterCE & BarcodeCE
*********************************************************/
BOOL InitPrinterCE()
{
	if (spPrinterCE) return TRUE;
	HRESULT hr;
	CoInitializeEx(NULL, COINIT_MULTITHREADED);
	//Create an instance of PrinterCE ActiveX control
	hr = spPrinterCE.CoCreateInstance(CLSID_PrinterCE);
	if (FAILED(hr)) {
		MessageBox(NULL,TEXT("Failed to init PrinterCE"),TEXT("Init Failed..."),MB_OK);
		return FALSE;
	}
	long bval;
	//Make sure what minimum version of PrinterCE we are working with.
	spPrinterCE->get_GetVersion(&bval);
	if (bval<2711) {
		LPTSTR errstr=TEXT("Early version of PrinterCE found... contact techsupport@fieldsoftware.com for latest version.");
		SetCursor(LoadCursor(NULL,IDC_ARROW));
		MessageBox(NULL,errstr,TEXT("Error - Cannot continue"),MB_OK);
		return FALSE;
	}

	//Create an instance of BarcodeCE (optional extension to PrinterCE)
	hr = spBarcodeCE.CoCreateInstance(CLSID_BarcodeCE);
	if (FAILED(hr)) {
		BarcodeCE_Flag=FALSE;
		MessageBox(NULL,TEXT("Barcode demo will be unavailable."),TEXT("BarcodeCE not found..."),MB_OK);
	}
	//Create an instance of AsciiCE control which is standard part of PrinterCE SDK
	hr = spAsciiCE.CoCreateInstance(CLSID_AsciiCE2);
	if (FAILED(hr)) {
		AsciiCE_Flag=FALSE;
		MessageBox(NULL,TEXT("AsciiCE demo will be unavailable."),TEXT("AsciiCE not found..."),MB_OK);
	}

	//  When you purchase PrinterCE SDK, you will receive a Developer's License Key that is used
	//  to unlock your installations of PrinterCE - use Init() method below and add your license key:
	//
	//  spPrinterCE->Init(CComBSTR("YOURLICENSEKEY"),&bval); 
  
	// Some of the PrinterCE methods need VARIANT data types (blame the VBCE guys)
	// This demo can get by with three global VARIANT variables, so lets init them
	// here... need two 4-byte floats and one BOOL.
	VariantInit(&globV_x1); //You have to init variants before you use them
	VariantInit(&globV_y1);
	VariantInit(&globV_bool);
	VariantInit(&globV_NULL);

	globV_x1.vt=VT_R4;
	globV_y1.vt=VT_R4;
	globV_bool.vt=VT_BOOL;
	globV_bool.boolVal=VARIANT_TRUE;

	globV_NULL.vt=VT_NULL;

	memset(ButtonVals,0,sizeof(ButtonVals));
	ButtonVals[0]=TRUE;
	return TRUE;
}

/*********************************************************
*********************************************************/
DWORD CleanUp(int WhichDemo)
{
	DWORD errVal;
	spPrinterCE->get_StatusCheck((long *) &errVal);		//Get status
	if (errVal==vbNoError) {
		spPrinterCE->NewPage();
		spPrinterCE->put_FontName(CComBSTR("Tahoma"));
		spPrinterCE->put_FontSize(12);
		spPrinterCE->put_FontItalic(FALSE);
		spPrinterCE->put_FontBold(FALSE);
		spPrinterCE->put_JustifyHoriz(vbLeft);
		spPrinterCE->put_JustifyVert(vbTop);
		spPrinterCE->put_ScaleMode(vbTwips);
		spPrinterCE->put_Rotation(vbNorth);

		CComBSTR tstr=(WhichDemo>=0 && WhichDemo<TOTAL_BUTTONS) ? DemoNames[WhichDemo] : NULL;
		spPrinterCE->PrDialogBoxText(tstr,CComBSTR("PrinterCE Demo"),NULL);
		spPrinterCE->get_StatusCheck((long *) &errVal);		//Get status
	}
	return errVal;
}

/*********************************************************
*********************************************************/
void OnBrochure()
{
	float wd, ht, x1, y1, x2, y2;
	long base;

	spPrinterCE->put_ScaleMode(vbInches);

	spPrinterCE->get_PrPgWidth(&wd);
	spPrinterCE->put_FontName(CComBSTR("Frutiger Linotype"));
	if (wd>5) {
		wd=5;
		base=12;
	}
	else {
		if (wd > 4) wd = 4;
		base=10;
	}
	// Center vertically & horizontally
	spPrinterCE->put_JustifyVert(vbTop);
	spPrinterCE->put_JustifyHoriz(vbCenter);
	// Rectangle area - width of page by 1.25 inches
	// 	ScaleMode defaults to TWIPS - (1440 twips per inch)
	x1 = 0;
	x2 = wd;
	y1 = 0;
	ht = 1.25;
	y2 = y1 + ht;
	spPrinterCE->put_DrawWidth((float) 0.035); //  72 twips = 1/5 of an inch
	spPrinterCE->DrawRect(x1, y1, x2, y2,&globV_NULL);
	spPrinterCE->put_DrawWidth((float) 0.007);
	float deltax, deltay, offsetx, offsety;
	int lp;
	deltax = wd / 20;
	deltay = ht / 20;
	offsetx = 0;
	offsety = y2;
	for (lp=0;lp<20;lp++) {
		offsetx = offsetx + deltax;
		spPrinterCE->DrawLine(x1 + offsetx, y1, x1, offsety,&globV_NULL,&globV_NULL);
		spPrinterCE->DrawLine(x2 - offsetx, y1, x2, offsety,&globV_NULL,&globV_NULL);
		offsety = offsety - deltay;
	}
	// Put an ellipse filled with a color inside our rectangle
	spPrinterCE->put_DrawWidth((float) 0.014);
	// calc new y1 & y2
	y1 = y1 + 0.3;
	y2 = y2 - 0.05;
	x1 = wd / 2;

//	spPrinterCE->put_FillColor(vbLightGray);
//	spPrinterCE->put_FillStyle(PicFSSolid); //PicFSSolid

	spPrinterCE->DrawEllipse(x1 - wd / 3, y1, x1 + wd / 3, y2,&globV_NULL);
//	spPrinterCE->put_FillColor(vbWhite);
//	spPrinterCE->put_FillStyle(PicFSTransparent); //PicFSSolid

	// Put some text in the middle
	spPrinterCE->put_FontSize(base+12);
	spPrinterCE->put_FontName(CComBSTR("Arial"));
	spPrinterCE->put_FontItalic(TRUE);
	spPrinterCE->put_FontBold(TRUE);
	y1+=(float) 0.03;
	globV_x1.fltVal=x1;
	globV_y1.fltVal=y1;
	spPrinterCE->DrawText(CComBSTR("PrinterCE"),&globV_x1,&globV_y1,&globV_NULL);
	spPrinterCE->put_FontSize(base+1);
	spPrinterCE->put_FontItalic(FALSE);
	spPrinterCE->put_FontBold(FALSE);
	spPrinterCE->DrawText(CComBSTR("Simple, sophisticated printing for your"),&globV_NULL,&globV_NULL,&globV_NULL);
	spPrinterCE->DrawText(CComBSTR("Pocket PC/Windows CE applications!"),&globV_NULL,&globV_NULL,&globV_NULL);
	// ---------------------------
	spPrinterCE->put_JustifyHoriz(vbLeft);
	spPrinterCE->put_FontName(CComBSTR("Arial"));
	
	spPrinterCE->put_FontSize(base+5);
	spPrinterCE->put_FontItalic(TRUE);
	spPrinterCE->put_FontUnderline(TRUE);
	spPrinterCE->put_TextX(0);
	spPrinterCE->put_TextY((float) 1.35);
	spPrinterCE->DrawText(CComBSTR("PrinterCE for Pocket PC/Windows CE"),&globV_NULL,&globV_NULL,&globV_NULL);
	float gettexty;
	spPrinterCE->get_TextY(&gettexty);
	spPrinterCE->put_TextY(gettexty + 0.035);
	spPrinterCE->put_FontSize(base);
	spPrinterCE->put_FontItalic(FALSE);
	spPrinterCE->put_FontUnderline(FALSE);

	LPTSTR PrBuff[]= {
		TEXT(" - eVB and eVC (C/C++/MFC) development environments"),
		TEXT(" - Versions for Windows Mobile Pocket PC, CE.Net and WinCE platforms"),
		TEXT(" - Easy to use - no device contexts, bitblits or other complexities"),
		TEXT(" - Powerful..."),
		TEXT("   * Text - Select font, size, style, rotation, page position..."),
		TEXT("   * Images - BMP, JPG - Select size, aspect ratio, rotation..."),
		TEXT("      + Plus GIF & PNG image support for the Pocket PC"),
		TEXT("   * Objects - Lines, ellipses, rectangles, rounded rectangles..."),
		TEXT("   * Much More!!!"),
		TEXT(" - AsciiCE control - fast Ascii-text printing for ANY Ascii printer"),
		TEXT(" - Optional BarcodeCE control supports over a dozen barcode types"),
		TEXT(" "),
		TEXT(" Printers Supported:"),
		TEXT("   * HP PCL3 - Most HP DeskJet, LaserJet & compatible printers"),
		TEXT("   * Canon BubbleJet and compatible printers"),
		TEXT("   * Epson - ESC/P2, Stylus, 24-pin and LQ compatible printers"),
		TEXT("   * Zebra Cameo, Encore, QL-320/420 thermal"),
		TEXT("   * Seiko DPU-3445"),
		TEXT("   * Citizen CMP-10, PD-22, PD-04 & PN60i"),
		TEXT("   * O'Neil MicroFlash thermal"),
		TEXT("   * Extech thermal"),
		TEXT("   * Brother MW-100, MW120, MW-140BT"),
		TEXT("   * Pentax PocketJet Portable printers"),
		TEXT("   * OMNIPrint 6240/6400"),
		TEXT("   * IPC PP-50"),
		TEXT("   * More..."),
		TEXT(" "),
	};

	for (lp=0;lp<sizeof(PrBuff)/sizeof(LPTSTR);lp++) {
		spPrinterCE->DrawText(CComBSTR(PrBuff[lp]),&globV_NULL,&globV_NULL,&globV_NULL);
	}
	
	// ---------------------------
	spPrinterCE->put_FontSize(base+2);
	spPrinterCE->put_FontItalic(TRUE);
	spPrinterCE->DrawText(CComBSTR("Visit at http://www.fieldsoftware.com/PrinterCE.htm"),&globV_NULL,&globV_NULL,&globV_NULL);
	
	spPrinterCE->put_FontSize(base);
	spPrinterCE->put_FontItalic(FALSE);
	spPrinterCE->put_FontUnderline(FALSE);
	LPTSTR PrBuff3[] = {
		TEXT(" - Free 60-day full-function evaluation"),
		TEXT(" - Documentation & sample source code"),
		TEXT(" - Pricing and purchasing info"),
		TEXT(" "),
		TEXT("For more info contact: techsupport@fieldsoftware.com"),
	};
	for (lp=0;lp<sizeof(PrBuff3)/sizeof(LPTSTR);lp++) {
		spPrinterCE->DrawText(CComBSTR(PrBuff3[lp]),&globV_NULL,&globV_NULL,&globV_NULL);
	}
}

/*********************************************************
*********************************************************/
void OnFormTest()
{
	spPrinterCE->put_ScaleMode(vbInches);
	spPrinterCE->put_DrawWidth((float) 0.02);
    
	//Draw major rectangles and lines
	spPrinterCE->DrawRect((float) 0,(float) 0,(float) 4.5,(float) 0.5,&globV_NULL);
	//Draw a shaded rectangle
	spPrinterCE->put_FillColor(vbLightGray);
	spPrinterCE->put_FillStyle(0); //picFSSolid
	spPrinterCE->DrawRect((float) 0,(float) 0,(float) 4.5,(float) 0.25,&globV_NULL);
	spPrinterCE->DrawLine((float) 1.5,(float) 0,(float) 1.5,(float) 0.5,&globV_NULL,&globV_NULL);
	spPrinterCE->DrawLine((float) 3.0, (float) 0,(float) 3.0,(float)  0.5,&globV_NULL,&globV_NULL);

	//Draw dark box with clear inner box
	spPrinterCE->put_FillColor(vbDarkGray);
	spPrinterCE->put_FillStyle(0); //picFSSolid
	spPrinterCE->DrawRect(4.5, 0, 6.5, 0.7,&globV_NULL);
	spPrinterCE->put_FillColor(vbWhite);
	spPrinterCE->DrawRoundedRect(4.6, 0.2, 6.4, 0.6, 0.15, 0.15,&globV_NULL);

	//Draw text strings
	spPrinterCE->put_FontSize(12);
	spPrinterCE->put_FontBold(VARIANT_TRUE);
	spPrinterCE->put_ForeColor(vbBlack);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -