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

📄 dodemo.cpp

📁 WinCE PDA打印机测试程序
💻 CPP
📖 第 1 页 / 共 3 页
字号:
	spPrinterCE->get_GetStringWidth(CComBSTR("Hello World"),&y);
	globV_x1.fltVal=x;
	globV_y1.fltVal=y+0.4;
	for (int lp=0;lp<4;lp++) {
		spPrinterCE->put_Rotation(lp);
		spPrinterCE->put_FontName(CComBSTR(fonts[lp]));
		spPrinterCE->put_FontSize(26);
		spPrinterCE->put_FontItalic(TRUE);
		spPrinterCE->put_FontBold(TRUE);
		spPrinterCE->put_ForeColor(RGB(0xC0,0x00,0xC0));
		spPrinterCE->DrawText(CComBSTR("Hello World"),&globV_x1,&globV_y1,&globV_NULL);
		spPrinterCE->put_FontSize(20);
		spPrinterCE->put_FontItalic(FALSE);
		spPrinterCE->put_FontBold(FALSE);
		spPrinterCE->put_ForeColor(RGB(0x00,0xFF,0x00));
		spPrinterCE->DrawText(CComBSTR(wheel[lp]),&globV_NULL,&globV_NULL,&globV_NULL);
	}
}

/*********************************************************
*********************************************************/
void OnImageRotation()
{
	float x,y,siz,wd;

	spPrinterCE->put_ScaleMode(vbInches);
	spPrinterCE->get_PrPgWidth(&wd);
	x=wd/2-0.4;
	y=1.5;
	siz=(float) 2.3;
	spPrinterCE->put_TextX(x);
	spPrinterCE->put_JustifyHoriz(vbLeft);
	for (int lp=0;lp<4;lp++) {
		spPrinterCE->put_Rotation(lp);
		globV_x1.fltVal=siz;
		spPrinterCE->DrawPicture(CComBSTR("\\Images\\owl.bmp"),x,y,&globV_x1,&globV_x1,&globV_NULL);
		siz *= (float) 0.66;
	}
}

/*********************************************************
*********************************************************/
void OnLineFun()
{
	float wd,ht,x1,y1,x2,y2;

	spPrinterCE->get_PrPgWidth(&wd);
	//Center vertically & horizontally
	spPrinterCE->put_JustifyHoriz(vbCenter);
	spPrinterCE->put_JustifyVert(vbCenter);
	//Set font stuff
	spPrinterCE->put_FontName(CComBSTR("Courier New"));
	spPrinterCE->put_FontSize(30);
	spPrinterCE->put_FontItalic(TRUE);

	x1=wd/2;
	y1=720;

	globV_x1.fltVal=x1;
	globV_y1.fltVal=y1;
	spPrinterCE->DrawText(CComBSTR("Demo: Line Fun"),&globV_x1,&globV_y1,&globV_NULL);

	//Rectangle area - width of page by 2 inches
	//  ScaleMode defaults to TWIPS - (1440 twips per inch)
	x1 = 0;
	x2 = wd;
	y1 = 1200;
	ht = 3 * 720;
	y2 = y1 + ht;
	spPrinterCE->put_DrawWidth(72);	// 72 twips = 1/5 of an inch
	spPrinterCE->DrawRect(x1, y1-2, x2, y2,&globV_NULL);

	spPrinterCE->put_DrawWidth(10);
	float deltax, deltay, offsetx, offsety;
	int lp;
	deltax = wd / 25;
	deltay = ht / 25;
	offsetx = 0;
	offsety = y2;
	for (lp=0;lp<25;lp++) {
		offsetx = offsetx + deltax;
		spPrinterCE->DrawLine((float) x1 + offsetx, (float) y1, (float) x1, (float) offsety,&globV_NULL,&globV_NULL);
		spPrinterCE->DrawLine((float) x2 - offsetx, (float) y1, (float) x2, (float) offsety,&globV_NULL,&globV_NULL);
		offsety = offsety - deltay;
	}
	//Put an ellipse filled with a color inside our rectangle
	spPrinterCE->put_DrawWidth(20);
	//calc new y1 & y2
	y1 = y1 + 720;
	y2 = y2 - 120;
	x1 = wd / 2;
	spPrinterCE->DrawEllipse((float) x1 - wd / 3,(float) y1,(float) x1 + wd / 3,(float) y2,&globV_NULL);
	//Put some text in the middle
	spPrinterCE->put_FontSize(32);
	spPrinterCE->put_FontName(CComBSTR("Arial"));
	y1+=(y2-y1)/2;
	globV_x1.fltVal=x1;
	globV_y1.fltVal=y1;
	spPrinterCE->DrawText(CComBSTR("PrinterCE"),&globV_x1,&globV_y1,&globV_NULL);
}

//------------------------------------
//Shared by both OnAsciiCE() and OnAsciiPrCE()
//------------------------------------
LPTSTR AsciiBuff[]= {
	TEXT(" "),
	TEXT(" "),
	TEXT("AsciiCE2 Control"),
	TEXT("---------------"),
	TEXT(" "),
	TEXT("AsciiCE2 allows your application to:"),
	TEXT(" * Send text to ANY Ascii printer"),
	TEXT(" * Offers maximum printing speed"),
	TEXT(" * Offers maximum printer selection"),
	TEXT(" * Suitable for text-only printing."),
	TEXT(" * Print via Infrared or Serial ports"),
	TEXT(" * Send printer control strings"),
	TEXT(" * Read data from Mag Card Readers"),
	TEXT(" * Read data from Smart Card Readers"),
	TEXT(" "),
	TEXT("- Works with Windows Mobile Pocket PC,"),
	TEXT("    CE.Net, WinCE devices"),
	TEXT(" "),
	TEXT("- Supports eVB and eVC (C/C++/MFC)"),
	TEXT(" "),
	TEXT("- AsciiCE2 is included with PrinterCE SDK"),
	TEXT(" "),
	TEXT("For more info:"),
	TEXT(" * http://www.fieldsoftware.com/PrinterCE"),
	TEXT(" * email: techsupport@fieldsoftware.com"),
};

/*********************************************************
*********************************************************/
void OnAsciiCE()
{
	int rval;
	rval=MessageBox(NULL,TEXT("Expecting an ASCII printer connected via Infrared... Continue? (Y/N):"),TEXT("AsciiCE Demo"),MB_YESNO);
	if (rval!=IDYES) return;
	long success;

//spAsciiCE->SelectPort(PORT_COM1,S_38400,SOFTWARE_HANDSHAKE,&success);
	spAsciiCE->SelectPort(PORT_IR, S_DONTCARE, S_DONTCARE,&success);
	if (!success) {
		MessageBox(NULL,TEXT("Unable to establish Infrared connection"),NULL,MB_OK);
		spAsciiCE->ClosePort();
		return;
	}
	for (int lp=0;lp<sizeof(AsciiBuff)/sizeof(LPTSTR);lp++) {
		spAsciiCE->Text(CComBSTR(AsciiBuff[lp]));
		spAsciiCE->CrLf();	//Move to next line
	}
	spAsciiCE->FormFeed();
	spAsciiCE->ClosePort();
}

/*********************************************************
*********************************************************/
void OnAsciiPrCE()
{
	int rval;
	long errVal,success;
	rval=MessageBox(NULL,TEXT("Expecting an ASCII printer connected via Infrared... Continue? (Y/N):"),TEXT("AsciiCE Demo"),MB_YESNO);
	if (rval!=IDYES) return;
	spPrinterCE->SelectPrinter();
	spPrinterCE->get_StatusCheck((long *) &errVal);		//Get status
	if (errVal!=vbNoError) {
		spPrinterCE->EndDoc();
		return;
	}
	spPrinterCE->put_ScaleMode(vbInches);
	spAsciiCE->SelectPortEx(PORT_PRINTERCE, S_DONTCARE, S_DONTCARE,0,&success);
	if (success) {
		spPrinterCE->put_FontSize(15);
		spPrinterCE->put_FontBold(VARIANT_TRUE);
		spPrinterCE->put_FontItalic(VARIANT_TRUE);
		spPrinterCE->DrawText(CComBSTR(_T("PrinterCE+AsciiCE2")),NULL,NULL,NULL);
		globV_x1.fltVal=1.75;
		globV_y1.fltVal=1.75;
		spPrinterCE->DrawPicture(_T("\\Images\\PrinterCE.bmp"),0,0.3,&globV_x1,&globV_y1,&globV_bool);

		for (int lp=0;lp<sizeof(AsciiBuff)/sizeof(LPTSTR);lp++) {
			spAsciiCE->Text(CComBSTR(AsciiBuff[lp]));
			spAsciiCE->CrLf();	//Move to next line
		}
		spPrinterCE->DrawPicture(_T("\\Images\\PrinterCE.bmp"),0,0,&globV_x1,&globV_y1,&globV_bool);
		spAsciiCE->ClosePort();
	}
	spPrinterCE->EndDoc();
}

/*********************************************************
*********************************************************/
// Mesage handler for the Demo box.
LRESULT CALLBACK Demo(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
//	DWORD errVal;
	int lp,ival;
	switch (message)
	{
		case WM_INITDIALOG:
			// trying to center the Demo dialog
#if (_WIN32_WCE >= 300)	//If rapier device, force main dialog to full screen
#ifndef _PRO320
			SHINITDLGINFO shidi;
			// Create a Done button and size it.
			shidi.dwMask = SHIDIM_FLAGS;
			shidi.dwFlags = SHIDIF_SIZEDLG | SHIDIF_SIPDOWN;
			shidi.hDlg = hDlg;
			SHInitDialog(&shidi);
#endif
#endif
			for (lp=FIRST_BUTTON;lp<LAST_BUTTON;lp++) {
				SendMessage(GetDlgItem(hDlg,lp),BM_SETCHECK,ButtonVals[lp-FIRST_BUTTON],0);
			}
			SendMessage(GetDlgItem(hDlg,IDC_LOOP),BM_SETCHECK,PrintContinuously,0);
			{
				//Display PrinterCE's version number on our dialog box
				long ver;
				spPrinterCE->get_GetVersion(&ver);
				TCHAR buffer[] = _T("Version 0.000");

				buffer[12]='0'+(BYTE) (ver%10);
				ver/=10;
				buffer[11]='0'+(BYTE) (ver%10);
				ver/=10;
				buffer[10]='0'+(BYTE) (ver%10);
				ver/=10;
				buffer[8]='0'+(BYTE) (ver%10);
				SendMessage(GetDlgItem(hDlg,IDC_PRINTERCEVERSION),WM_SETTEXT,0,(LPARAM) buffer);
			}
			return TRUE;
		case WM_PAINT:
			//NOTE: Without the SetFocus(), the "Done" OK button goes away if select Today and then back to here
			SetFocus(hDlg);
			HWND hpwnd;
			hpwnd=GetParent(hDlg);
			if (hpwnd) ::UpdateWindow(hpwnd);
			return FALSE;
		case WM_COMMAND:
			ival=LOWORD(wParam);
			switch (ival) {

			case IDCANCEL:
				EndDialog(hDlg, ival);
				return TRUE;
			case IDOK:
				{
				BOOL FirstTime=TRUE;
				DWORD errVal=vbNoError;
				for (;;) {
					for (lp=FIRST_BUTTON;lp<=LAST_BUTTON;lp++) {
						if (errVal!=vbNoError) break;
						if (ButtonVals[lp-FIRST_BUTTON]) {
							if (FirstTime) {
								FirstTime=FALSE;
								spPrinterCE->SelectPrinter();	 //Have PrinterCE pop up Select Printer dialog box
							}
							errVal=CleanUp(lp-FIRST_BUTTON);
							if (errVal!=vbNoError) break;
							switch (lp) {
							case IDCC_LINEFUN:
								OnLineFun();
								break;
							case IDCC_BROCHURE:
								OnBrochure();
								break;
							case IDCC_IMAGEROTATION:
								OnImageRotation();
								break;
							case IDCC_TEXTWHEEL:
								OnTextWheel();
								break;
							case IDCC_THUMBNAIL:
								OnThumbNail();
								break;
							case IDCC_FORMTEST:
								OnFormTest();
								break;
							case IDCC_BARCODES:
								if (!BarcodeCE_Flag) {
									MessageBox(hDlg,TEXT("Barcode demo is unavailable."),TEXT("BarcodeCE not found..."),MB_OK);
								}
								else {
									OnBarcodes();
								}
							}
						} //if
					} //for
					if (!PrintContinuously || errVal!=vbNoError) break;
				} //for
				if (!FirstTime) {
					spPrinterCE->EndDoc();	//Start printing here
					long errval;
					spPrinterCE->get_StatusCheck(&errval);
					if (errval>0) {
						//Do whatever error handling is needed...
					}
				}
				}
				return TRUE;
			//If AsciiCE demo
			case IDC_ASCIICE:
			case IDC_ASCIICE2:
				if (!AsciiCE_Flag) {
					MessageBox(hDlg,TEXT("AsciiCE demo unavailable."),TEXT("AsciiCE2 not found..."),MB_OK);
				}
				else if (ival==IDC_ASCIICE) {
					OnAsciiCE();
				}
				else {
					OnAsciiPrCE();
				}
				return TRUE;
			case IDC_LOOP:
				PrintContinuously=SendMessage(GetDlgItem(hDlg,IDC_LOOP),BM_GETCHECK,0,0);
				return TRUE;
			default:
				if (ival>=FIRST_BUTTON && ival<=LAST_BUTTON) {
					ButtonVals[ival-FIRST_BUTTON]=SendMessage(GetDlgItem(hDlg,ival),BM_GETCHECK,0,0);
					return TRUE;
				}
			}
			break;
	}
	return FALSE;
}

/*********************************************************
*********************************************************/
void DoDemo(HWND hWnd)
{
	if (InitPrinterCE()) {
		DialogBox(hInst, (LPCTSTR)IDD_DEMO, hWnd, (DLGPROC)Demo);
	}
}

⌨️ 快捷键说明

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