Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

[WINAPI] Schriftarten vom Drucker verwenden

Empfohlene Antworten

Veröffentlicht

Hallo.

Wie man in .NET Druckt, weiss ich ja:


	    static String^ text;

		void pd_PrintPage( Object^ /*sender*/, PrintPageEventArgs^ ev )

		{

			System::Drawing::Font^ printFontB = gcnew System::Drawing::Font("Arial",30);

			System::Drawing::Font^ printFont = gcnew System::Drawing::Font( "Arial",12 );

			//Image^ newImage = Image::FromFile( "print.jpg" );

			Point ulCorner = Point(30,0);

			//ev->Graphics->DrawImage( newImage, ulCorner );

			ev->Graphics->DrawString("•••S•••K•••S•••",printFontB,Brushes::Black,0,0);

			ev->Graphics->DrawString("17.04.2009\t22:00\n\nCola\nPreis:2,00\n\n",printFont,Brushes::Black,0,20);

			ev->Graphics->DrawString("•••S•••K•••S•••",printFontB,Brushes::Black,0,90);


		}


	private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) 

			 {

				 PrintDocument^ pd = gcnew PrintDocument;

				 //text = "Cola Bieeer 1,2\nHeute voll Billig brudeeeer xDDD\n Hallooo";

				 pd->PrintPage += gcnew PrintPageEventHandler( this, &Form1::pd_PrintPage );

				 pd->Print();


				 //pd->PrintPage += gcnew PrintPageEventHandler( this, &Form1::pd_PrintPage );

				 //pd->Print();

			 }

Der Code ist zwar nicht der schönste, aber er tut seinen Zweck.

Mein Problem ist jetzt, dass ich mit einem Bondrucker arbeite. Er hat intigrierte Fonds, mit denen er Schneller drucken kann ( z.B. FontA11 ).

Es handelt sich um einen Epson TM-88II Bondrucker.

Hier sind alle Font's aufgelistet:

fonth.png

Mit Exel kann ich die Schriftart auswählen und ich erreiche die Gewünschte geschwindigkeit. Wie wähle ich aber die Schriftart in .NET aus, da sie ja nicht wie die anderen im Systemordner/Schriftarten zu finden ist?

Liebe Grüße

errox

  • Autor

Irgentwie konnt ich mir denken, dass niemand darauf ne antwort findet, aber ich hab eine Alternatividee:

In exel wird die Schriftart angezeigt und in der gewünschten geschwindigkeit gedruckt ( FontA11 )

schriftarteninexel.png

Weiss jemand, wie ich genau das Selbe Drop-Down menü erzeugen kann und dann vielleicht mit FontA11 drucken kann?

Danke

  • 2 Wochen später...
  • Autor

Also wie ich drucke, weiss ich jetzt ( Windows API )


void draw_img(HDC hDC)

{

	Graphics graphics(hDC);

	Image image(L"print.jpg");

	graphics.DrawImage(ℑ, Point(80, 0));

}

int main()

{


	GdiplusStartupInput gdiplusStartupInput;

	ULONG_PTR gdiplusToken;

	GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);

	PRINTDLG p = {0};

	p.lStructSize = sizeof p;

	p.Flags = PD_NOPAGENUMS | PD_RETURNDC | PD_RETURNDEFAULT;

	HRESULT hr = PrintDlg(&p);

	DOCINFO di;

	di.lpszDocName = TEXT("BON");

	di.cbSize = sizeof(di);

	di.lpszOutput =  NULL;

	di.lpszDatatype =  NULL;

	di.fwType = 0;

	StartDoc(p.hDC,&di);

	//draw_img(p.hDC);

	TextOutA(p.hDC,0,0,"&H1B",1);

	EndDoc(p.hDC);


	GdiplusShutdown(gdiplusToken);



}

Der Drucker druckt auch in der gewünschten geschwindigkeit. Jetzt hab ich aber das Problem, dass ich aktionen wie &H1B schicken muss mit der Schriftart control.

Ich DACHTE, dass ich das nicht brauche ( Fonts auswählen die gedruckt werden sollen ), weil er sowieso in der Geschwindigkeit druckt, die ich wollte.

Jetzt wo ich diese Controls wie "kassenschublade öffnen" und "barcode schreiben" brauche, hab ich meine Meinung geändert :D

Meine idee ist eine Kombination aus meinem Code und How To Use Printer Device Fonts

Natürlich ist es auch ohne möglich. Aber es ist umständlich die Kasse immer selbst zu öffnen. Wenn es schon möglich ist, will ich diese Funktion auch nutzen

P.S. Mit Excel funktioniert es :)

Danke für antworten

Liebe Grüße

errox

  • Autor

Bin ich mit dem Soure ein schritt näher? ( Es wird ein leerer Text gedruckt )


void draw_img(HDC hDC)

{

	Graphics graphics(hDC);

	Image image(L"print.jpg");

	graphics.DrawImage(ℑ, Point(80, 0));

}

int main()

{


	GdiplusStartupInput gdiplusStartupInput;

	ULONG_PTR gdiplusToken;

	CHOOSEFONT cf; 

    LOGFONT lf;

	cf.lStructSize = sizeof(CHOOSEFONT); 

    cf.hwndOwner = (HWND)NULL; 

    cf.hDC = (HDC)NULL; 

    cf.lpLogFont = &lf; 

    cf.iPointSize = 0; 

    cf.Flags = CF_SCREENFONTS; 

    cf.rgbColors = RGB(0,0,0); 

    cf.lCustData = 0L; 

    cf.lpfnHook = (LPCFHOOKPROC)NULL; 

    cf.lpTemplateName = NULL; 

    cf.hInstance = (HINSTANCE) NULL; 

    cf.lpszStyle = NULL; 

    cf.nFontType = SCREEN_FONTTYPE; 

    cf.nSizeMin = 0; 

    cf.nSizeMax = 0; 

	GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);

	PRINTDLG p = {0};

	p.lStructSize = sizeof p;

	p.Flags = PD_NOPAGENUMS | PD_RETURNDC | PD_RETURNDEFAULT;

	HRESULT hr = PrintDlg(&p);

	DOCINFO di;

	di.lpszDocName = TEXT("BON");

	di.cbSize = sizeof(di);

	di.lpszOutput =  NULL;

	di.lpszDatatype =  NULL;

	di.fwType = 0;

	SelectObject(p.hDC, CreateFontIndirect(cf.lpLogFont));

	StartDoc(p.hDC,&di);	

	//draw_img(p.hDC);

	TextOutA(p.hDC,0,0,"&H1B",4);

	EndDoc(p.hDC);


	GdiplusShutdown(gdiplusToken);



}

  • Autor

Ich glaub du verstehst meine frage nicht. Tut mir leid, dass ich sie falsch erkläre.

Also ich brauche ja die Callback funktionen


int CALLBACK PrinterDeviceFontEnum(

  ENUMLOGFONTEX *lpelfe,    // logical-font data

  NEWTEXTMETRICEX *lpntme,  // physical-font data

  DWORD FontType,           // type of font

  LPARAM lParam             // application-defined data

)

und

int CALLBACK PrinterDeviceFontFamiliesEnum(

  ENUMLOGFONTEX *lpelfe,    // logical-font data

  NEWTEXTMETRICEX *lpntme,  // physical-font data

  DWORD FontType,           // type of font

  LPARAM lParam             // application-defined data

)

um die Druckerfonts zu Enumerieren, oder?

Hoffentlich bin ich soweit richtig :D Jedenfalls, wenn ich mit einer TTF Drucken will, muss ich sie ja auch nicht aussuchen, sondern kann sie einfach auswählen wie "Arial" oder "Times New Roman".

Muss ich die DruckerFonts Enumerieren, weil es nicht anders geht? Mir wäre es lieber, wenn ich sie wie bei den TT Fonts einfach nur auswählen kann wie "control" oder "FontA11"

Liebe Grüße

errox

Ich glaub du verstehst meine frage nicht.
Ich glaube eher, du verstehst meine Antwort nicht. ;)

Muss ich die DruckerFonts Enumerieren, weil es nicht anders geht?
Wie bereits gesagt: Nein. Du kannst auch direkt eine LOGFONT-Struktur mit den richtigen Daten füllen.

Das Enumerieren dient nur dazu, dir richtig befüllte LOGFONT-Strukturen zu liefern.

  • Autor

Also entweder tu ich mich schwer, oder ich versteh es nicht.

Also der Code um etwas zu drucken, sieht so aus:


	PRINTDLG p = {0};

	p.lStructSize = sizeof p;

	p.Flags = PD_NOPAGENUMS | PD_RETURNDC | PD_RETURNDEFAULT;

	HRESULT hr = PrintDlg(&p);

	DOCINFO di;

	di.lpszDocName = TEXT("BON");

	di.cbSize = sizeof(di);

	di.lpszOutput =  NULL;

	di.lpszDatatype =  NULL;

	di.fwType = 0;

	StartDoc(p.hDC,&di);	

	TextOutA(p.hDC,0,0,"&H1B",4);

	EndDoc(p.hDC);

Jetzt will ich aber meine Persönliche Schriftart. Mit SelectObject() kann ich diese Schriftart control in meinen hDC intigrieren.

Für SelectObject() brauch ich CreateFontIndirect()

Und CreateFontIndirect() braucht nen Zeiger auf eine LOGFONT Struktur

Die LOGFONT Struktur ist das entscheidende. Ich muss sie mit den richtigen Daten füttern, damit ich etwas in control drucke.

Bin ich soweit richtig?

Wenn ja, ist es schonmal gut und ich werde was Probieren. Wenn nicht, bitte ich um Fehlerreports.

  • Autor

Also soweit bin ich schonmal.

	PRINTDLG p = {0};

	LOGFONT lf;

	p.lStructSize = sizeof p;

	p.Flags = PD_NOPAGENUMS | PD_RETURNDC | PD_RETURNDEFAULT;

	PrintDlg(&p);

	DOCINFO di;

	di.lpszDocName = TEXT("BON");

	di.cbSize = sizeof(di);

	di.lpszOutput =  NULL;

	di.lpszDatatype =  NULL;

	di.fwType = 0;


	lf.lfCharSet = ANSI_CHARSET;



	StartDoc(p.hDC,&di);

	SelectObject(p.hDC,CreateFontIndirect(&lf));

	TextOutA(p.hDC,0,0,"&H1B",4);

	EndDoc(p.hDC);

Welcher Parameter der Struktur ist für mich am Wichtigsten, damit ich mit control drucken kann?

Und noch eine kurze frage: Muss das SelectObject() Nach, oder vor StartDoc() stehen?

  • Autor

Also ich glaub ich bin kurz vor meinem Ziel. Vorher gehe ich auch nicht schlafen :D


	PRINTDLG p = {0};

	LOGFONTA lf;

	p.lStructSize = sizeof p;

	p.Flags = PD_NOPAGENUMS | PD_RETURNDC | PD_RETURNDEFAULT;

	PrintDlg(&p);

	DOCINFO di;

	di.lpszDocName = TEXT("BON");

	di.cbSize = sizeof(di);

	di.lpszOutput =  NULL;

	di.lpszDatatype =  NULL;

	di.fwType = 0;

	StartDoc(p.hDC,&di); 

	ZeroMemory(&lf, sizeof(lf));

    lf.lfCharSet = DEFAULT_CHARSET;

	[B]lf.lfFaceName = "control";[/B]

	SelectObject(p.hDC,CreateFontIndirectA(&lf));

	TextOutA(p.hDC,0,0,"&H1B",4);

	EndDoc(p.hDC);

Das ich die Fehlermeldung

error C2440: '=' : cannot convert from 'const char [8]' to 'CHAR [32]'

wundert mich wenig. Da steht aber etwas interessantes, dass ich etwas mit NULL hinzufügen soll

...

The length of this string must not exceed 32 TCHARS, including the terminating NULL.

...

Ich glaub wenn ich das hab, bin ich fertig. Wie kann ich dieses NULL hinzufügen?

Das ich die Fehlermeldung ... wundert mich wenig.
Sollte es eigentlich nicht. lfFaceName ist ein Array, Arrays kann man nichts zuweisen.

Da steht aber etwas interessantes, dass ich etwas mit NULL hinzufügen soll

Ich glaub wenn ich das hab, bin ich fertig. Wie kann ich dieses NULL hinzufügen?

Bist du nicht mit der Art und Weise vertraut, wie Strings in C eingesetzt werden? Strings in C sind Zeiger auf char-Arrays. Das Ende des Strings wird durch ein Nullzeichen markiert. Fast alle Stringverarbeitungsfunktionen in C setzen diese Nullterminierung automatisch.

Die Funktion, die du suchst, heißt strcpy (bzw. in diesem Fall die TCHAR-Variante, _tcscpy).

  • Autor

Ich habs :)


PRINTDLG p = {0};

LOGFONTA lf;

p.lStructSize = sizeof p;

p.Flags = PD_NOPAGENUMS | PD_RETURNDC | PD_RETURNDEFAULT;

PrintDlg(&p);

DOCINFO di;

di.lpszDocName = TEXT("BON");

di.cbSize = sizeof(di);

di.lpszOutput =  NULL;

di.lpszDatatype =  NULL;

di.fwType = 0;

StartDoc(p.hDC,&di); 

ZeroMemory(&lf, sizeof(lf));

lf.lfCharSet = DEFAULT_CHARSET;

strcpy(lf.lfFaceName,"control");

SelectObject(p.hDC,CreateFontIndirectA(&lf));

TextOutA(p.hDC,0,0,"&H1B",4);

EndDoc(p.hDC);

Nun kann ich gut schlafen :D

Vielen dank für alles!

gute nacht :D

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.