Orientierung bei Drucker setzen
-
Hallo zusammen,
ich habe da ein kleines Problem:
Ich versuche auf einen Drucker zu Drucken. Das funktioniert alles wunderbar, aber das Setzen einiger Eigenschaften will nicht so recht.Hier ist mein Code:
bool _stdcall DC_Feed ( char DocTitle[], DWORD DC_Cmd ) { DOCINFO dokument_info; memset(&dokument_info, 0, sizeof(DOCINFO)); dokument_info.cbSize = sizeof(DOCINFO); dokument_info.lpszDocName = DocTitle; int result = 0; // DC_Hnd & DC_Printername werden bei der Initialisierung gefüllt mit // Druckerhandle und Druckername if ( Mode ( DC_Hnd, TRUE ) ) { // hier wird die Variable Line gefüllt mit "Portrait" oder "Landscape" GetMyOrientation(); result = strcmp(Line, "Portrait"); if (result = 0) { SetOrientation(DC_Hnd, DC_PrinterName, 1); } else { result = strcmp(Line, "Landscape"); if (result = 0) { SetOrientation(DC_Hnd, DC_PrinterName, 2); } } StartDoc(DC_Hnd, &dokument_info); StartPage(DC_Hnd); if ( Feed ( DC_Hnd, DC_Cmd ) ) { return 1; } else { return 0; } } else } return 0; } } void SetOrientation(HDC hCardDC, LPTSTR pPrinterName, short iOrientation) { HANDLE hPrinter; DWORD dwNeeded, dwResult; LPDEVMODE lpDevMode = NULL; /* Retrieve a handle for the specified printer */ if (!OpenPrinter(pPrinterName, &hPrinter, NULL)) { return; // error } /* Determine the size of the printer's DEVMODE structure */ dwNeeded = DocumentProperties(NULL, hPrinter, pPrinterName, NULL, NULL, 0); /* Allocate memory to hold the printer's DEVMODE structure */ lpDevMode = (DEVMODE*)malloc(dwNeeded); if (lpDevMode != NULL) { /* Get the printer's DEVMODE structure */ dwResult = DocumentProperties(NULL, hPrinter, pPrinterName, lpDevMode, NULL, DM_OUT_BUFFER); if (dwResult == IDOK) { /* Set the orientation in the printer's DEVMODE structure */ lpDevMode->dmOrientation = iOrientation; lpDevMode->dmFields = DM_ORIENTATION; dwResult = DocumentProperties(NULL, hPrinter, pPrinterName, lpDevMode, lpDevMode, DM_IN_BUFFER | DM_OUT_BUFFER); /* Reset the printer device context with the new orientation */ if (dwResult == IDOK) { ResetDC(hCardDC, lpDevMode); } } /* Free the memory used to hold the printer's DEVMODE structure */ free(lpDevMode); } /* Close the specified printer */ ClosePrinter(hPrinter); }
Des weiteren muss ich vorher bei der Variable Line die Leerzeichen vorn und hinten abschneiden, da ich diesen aus einer Datei lese.
Danke im Voraus & Gruß,
Moony
-
Dieser Thread wurde von Moderator/in evilissimo aus dem Forum C++ in das Forum WinAPI verschoben.
Im Zweifelsfall bitte auch folgende Hinweise beachten:
C/C++ Forum :: FAQ - Sonstiges :: Wohin mit meiner Frage?Dieses Posting wurde automatisch erzeugt.
-
So, wenn ich die Funktion
SetOrientation(DC_Hnd, DC_PrinterName, 2);
direkt aufrufe, dann funktioniert das. Aber wenn ich die Stringvergleiche und anschließend die Abfragen habe, dann funktioniert das nicht.