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.

Empfohlene Antworten

Veröffentlicht

Hallo zusammen!

Ich habe mir eine Druckfunktion von einem Buch heraus abgeschrieben, die eingentlich für eine TextBox gedacht ist.

Ich habe sie jetzt ein bißchen modifiziert und es funtkioniert leider nicht ganz.

Ich will von einer ListView die ersten 3 Spalten ausgegeben. Dieses funktioniert auch jedoch wird dann noch etwas ausgegeben von einer MySQL-Anfrage.

z.B.: 1 112 aus der mitte entspringt ein Fuss b.hauptdarstellerid, b.hauptdarsteller....

2 120 Die Mumie tte entspringt ein Fuss b.hauptdarstellerid, b.hauptdarsteller....

Bis die Zeile voll ist. Es sollte aber nach dem "Die Mumie" nichts mehr dortstehen.

Hier die Funktionen:

BOOL LVPrntPrintFile(HINSTANCE hInst, HWND hwnd, HWND hwnd_ListView, PTSTR szTitleName)

{

   static DOCINFO    di = {sizeof(DOCINFO)};

   static PRINTDLG   pd;

   BOOL              bSuccess;

   int               yChar, iCharsPerLine, iLinesPerPage, iTotalLines,

                     iTotalPages, iPage, iLine, iLineNum;

   PTSTR             pstrBuffer;

   TCHAR             szJobName[64 + MAX_PATH];

   TEXTMETRIC        tm;

   WORD              iColCopy, iNoiColCopy;


   //Aufruf des Druck-Dialogs(COMMDLG)

   pd.lStructSize    = sizeof(PRINTDLG);

   pd.hwndOwner      = hwnd;

   pd.hDevMode       = NULL;

   pd.hDevNames      = NULL;

   pd.hDC            = NULL;

   pd.Flags          = PD_ALLPAGES | PD_COLLATE | PD_RETURNDC | PD_NOSELECTION;

   pd.nFromPage      = 0;

   pd.nToPage        = 0;

   pd.nMinPage       = 0;

   pd.nMaxPage       = 0;

   pd.nCopies        = 1;

   pd.hInstance      = NULL;

   pd.lCustData      = 0L;

   pd.lpfnPrintHook  = NULL;

   pd.lpfnSetupHook  = NULL;

   pd.lpPrintTemplateName  = NULL;

   pd.lpSetupTemplateName  = NULL;

   pd.hPrintTemplate       = NULL;

   pd.hSetupTemplate       = NULL;


   if (!PrintDlg(&pd))

      return TRUE;


   if (0 == (iTotalLines = SendMessage(hwnd_ListView, LVM_GETITEMCOUNT, 0, 0)))

      return TRUE;


   //Schriftgröße ermitteln, darüber Zeilenzahl und Seitenzahl berechnen

   GetTextMetrics(pd.hDC, &tm);

   yChar = tm.tmHeight + tm.tmExternalLeading;


   iCharsPerLine = GetDeviceCaps(pd.hDC, HORZRES) / tm.tmAveCharWidth;

   iLinesPerPage = GetDeviceCaps(pd.hDC, VERTRES) / yChar;

   iTotalPages   = (iTotalLines + iLinesPerPage - 1) / iLinesPerPage;

   printf("iCharsPerLine: %d\n", iCharsPerLine);

   printf("iLinesPerPage: %d\n", iLinesPerPage);

   printf("iTotalPages: %d\n", iTotalPages);


   //Puffer für eine Textzeile

   pstrBuffer = (PTSTR) malloc(sizeof(TCHAR) * (iCharsPerLine + 1));


   //Hauptfenster deaktivieren, Abbruchdialog anzeigen

   EnableWindow(hwnd, FALSE);


   bSuccess   = TRUE;

   bUserAbort = FALSE;


   hDlgPrint = CreateDialog(hInst, TEXT("PrintDlgBox"), hwnd, PrintDlgProc);


   SetDlgItemText(hDlgPrint, IDC_FILENAME, szTitleName);

   SetAbortProc(pd.hDC, AbortProc);


   //Start des Ausdruckens

   GetWindowText(hwnd, szJobName, sizeof(szJobName));

   di.lpszDocName = szJobName;


   if (StartDoc(pd.hDC, &di) > 0)

   {

      //Sortierreihenfolge und Anzahl der Kopien

      for (iColCopy = 0; iColCopy < ((WORD) pd.Flags & PD_COLLATE ? pd.nCopies : 1); iColCopy++)

      {

         for (iPage = 0; iPage < iTotalPages; iPage++)

         {

            for (iNoiColCopy = 0; iNoiColCopy < (pd.Flags & PD_COLLATE ? 1: pd.nCopies); iNoiColCopy++)

            {

               //Start einer Seite

               if (StartPage(pd.hDC) < 0)

               {

                  bSuccess = FALSE;

                  break;

               }


               //zeilenweise Ausgabe

               for (iLine = 0; iLine < iLinesPerPage; iLine++)

               {

                  iLineNum = iLinesPerPage * iPage + iLine;


                  if (iLineNum > iTotalLines)

                     break;


                  //Ausgabe von Text zum Drucker

                  //pstrBuffer = LVString_func(hwnd_ListView, iCharsPerLine, iLine);

                  LVString_func(hwnd_ListView, pstrBuffer, iCharsPerLine, iLine);

                  TextOut(pd.hDC, 0, yChar * iLine, pstrBuffer, iCharsPerLine);

               }


               if (EndPage(pd.hDC) < 0)

               {

                  bSuccess = FALSE;

                  break;

               }


               if (bUserAbort)

                  break;

            }

            if (!bSuccess || bUserAbort)

               break;


         }

         if (!bSuccess || bUserAbort)

            break;

      }

   }

   else

      bSuccess = FALSE;


   if (bSuccess)

      EndDoc(pd.hDC);


   if (!bUserAbort)

   {

      EnableWindow(hwnd, TRUE);

      DestroyWindow(hDlgPrint);

   }


   free(pstrBuffer);

   DeleteDC(pd.hDC);


   return bSuccess && !bUserAbort;

}




void LVString_func(HWND hwnd_ListView, PTSTR &pstrBuffer, int iCharsPerLine, int iItem)

{

   int      cchTextMax;

   TCHAR    *szpTemp;

   TCHAR    szfNr[6] = "", szID[6] = "", szFilmbezeichnung[85] = "",

            szFilmLenght[20] = "", szVideoformat[15] = "", szGenre[25] = "";


   ListView_GetItemText(hwnd_ListView, iItem, 0, szfNr, 3);

   ListView_GetItemText(hwnd_ListView, iItem, 1, szID, 3);

   ListView_GetItemText(hwnd_ListView, iItem, 2, szFilmbezeichnung, 80);


   szpTemp = (TCHAR *) malloc(sizeof(TCHAR) * (iCharsPerLine + 1));

   strcpy(pstrBuffer, " ");

   wsprintf(szpTemp, "%5s %5s %s", szfNr, szID, szFilmbezeichnung);

   strcpy(pstrBuffer, szpTemp);

   free(szpTemp);

}

PS.: Die Ausgabe erfolgt nicht direkt am Drucker sondern in ein PDF-File mittels PDFCreator (ist ein Druckertreiber);

Hat da jemand eine Idee was falsch sein könnte.

Vielen Dank im voraus.

Danke für deine Antwort.

Werde das dann ausprobieren.

Also deswegen wurde der Inhalt einer meiner SELECT-Anweisungen mitausgegeben.

Ich habe mich schon gefragt und geärgert warum das alles ausgegeben wurde.

Gibt es eine andere Möglichkeit Text auszugeben, oder ist die beste Möglichkeit eben das "TextOut" ??

Danke schon mal.

Ok.

Danke für deine Hilfe.

Ich denke "TextOut" wird zur Zeit ausreichend sein für mich.

Danke noch mal.

Erstelle ein Konto oder melde dich an, um einen Kommentar zu schreiben.

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.