<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Ein Bitmap mit MFC drucken?]]></title><description><![CDATA[<p>Hallo erstmal!</p>
<p>Auf Codeproject habe ich ein Beispiel gefunden wie man etwas ausdrucken<br />
kann. In diesem Fall ein Bitmap.</p>
<p>Hier verstehe ich aber nicht, wie man das Bild in der original Größe<br />
drucken kann. Es soll nicht auf das ganze Blatt vergrößert werden.</p>
<p>Es muss wohl StretchBlt() auskommentiert werden. Nur dann druckt er gleich<br />
gar nimmer <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f62e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_open_mouth"
      title=":open_mouth:"
      alt="😮"
    /></p>
<pre><code class="language-cpp">CPrintDialog printDlg(FALSE);
 printDlg.GetDefaults(); 
 // Or get from user:
 // if (printDlg.DoModal() == IDCANCEL)   
 //        return; 
 CDC dc;
 if (!dc.Attach(printDlg.GetPrinterDC())) {
  AfxMessageBox(_T(&quot;No printer found!&quot;)); return;
 } 

 dc.m_bPrinting = TRUE; 
 DOCINFO di;    
 // Initialise print document details
 ::ZeroMemory (&amp;di, sizeof (DOCINFO));
 di.cbSize = sizeof (DOCINFO);
 di.lpszDocName = filename; 
 BOOL bPrintingOK = dc.StartDoc(&amp;di); // Begin a new print job 
 // Get the printing extents
 // and store in the m_rectDraw field of a 
 // CPrintInfo object
 CPrintInfo Info;
 Info.SetMaxPage(1); // just one page 
 int maxw = dc.GetDeviceCaps(HORZRES);
 int maxh = dc.GetDeviceCaps(VERTRES); 
 Info.m_rectDraw.SetRect(0, 0, maxw, maxh); 
 for (UINT page = Info.GetMinPage(); page &lt;= 
      Info.GetMaxPage() &amp;&amp; bPrintingOK; page++) {
  dc.StartPage();    // begin new page
  Info.m_nCurPage = page;
  CBitmap bitmap;
  // LoadImage does the trick here, it creates a DIB section
  // You can also use a resource here
  // by using MAKEINTRESOURCE() ... etc. 
  if(!bitmap.Attach(::LoadImage(
   ::GetModuleHandle(NULL), filename, IMAGE_BITMAP, 0, 0, 
   LR_LOADFROMFILE | LR_CREATEDIBSECTION | LR_DEFAULTSIZE))) {
    AfxMessageBox(_T(&quot;Error loading bitmap!&quot;)); return;
   } 
   BITMAP bm;
   bitmap.GetBitmap(&amp;bm);
   int w = bm.bmWidth; 
   int h = bm.bmHeight; 
   // create memory device context
   CDC memDC; 
   memDC.CreateCompatibleDC(&amp;dc);
   CBitmap *pBmp = memDC.SelectObject(&amp;bitmap);
   memDC.SetMapMode(dc.GetMapMode());
   dc.SetStretchBltMode(HALFTONE);
   // now stretchblt to maximum width on page
   dc.StretchBlt(0, 0, maxw, maxh, &amp;memDC, 0, 0, w, h, SRCCOPY); 
   // clean up
   memDC.SelectObject(pBmp);
   bPrintingOK = (dc.EndPage() &gt; 0);   // end page
 } 
 if (bPrintingOK)
   dc.EndDoc(); // end a print job
 else dc.AbortDoc();           // abort job.
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/155392/ein-bitmap-mit-mfc-drucken</link><generator>RSS for Node</generator><lastBuildDate>Sat, 25 Jul 2026 04:09:48 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/155392.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 05 Aug 2006 16:11:04 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Ein Bitmap mit MFC drucken? on Sat, 05 Aug 2006 16:11:04 GMT]]></title><description><![CDATA[<p>Hallo erstmal!</p>
<p>Auf Codeproject habe ich ein Beispiel gefunden wie man etwas ausdrucken<br />
kann. In diesem Fall ein Bitmap.</p>
<p>Hier verstehe ich aber nicht, wie man das Bild in der original Größe<br />
drucken kann. Es soll nicht auf das ganze Blatt vergrößert werden.</p>
<p>Es muss wohl StretchBlt() auskommentiert werden. Nur dann druckt er gleich<br />
gar nimmer <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f62e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_open_mouth"
      title=":open_mouth:"
      alt="😮"
    /></p>
<pre><code class="language-cpp">CPrintDialog printDlg(FALSE);
 printDlg.GetDefaults(); 
 // Or get from user:
 // if (printDlg.DoModal() == IDCANCEL)   
 //        return; 
 CDC dc;
 if (!dc.Attach(printDlg.GetPrinterDC())) {
  AfxMessageBox(_T(&quot;No printer found!&quot;)); return;
 } 

 dc.m_bPrinting = TRUE; 
 DOCINFO di;    
 // Initialise print document details
 ::ZeroMemory (&amp;di, sizeof (DOCINFO));
 di.cbSize = sizeof (DOCINFO);
 di.lpszDocName = filename; 
 BOOL bPrintingOK = dc.StartDoc(&amp;di); // Begin a new print job 
 // Get the printing extents
 // and store in the m_rectDraw field of a 
 // CPrintInfo object
 CPrintInfo Info;
 Info.SetMaxPage(1); // just one page 
 int maxw = dc.GetDeviceCaps(HORZRES);
 int maxh = dc.GetDeviceCaps(VERTRES); 
 Info.m_rectDraw.SetRect(0, 0, maxw, maxh); 
 for (UINT page = Info.GetMinPage(); page &lt;= 
      Info.GetMaxPage() &amp;&amp; bPrintingOK; page++) {
  dc.StartPage();    // begin new page
  Info.m_nCurPage = page;
  CBitmap bitmap;
  // LoadImage does the trick here, it creates a DIB section
  // You can also use a resource here
  // by using MAKEINTRESOURCE() ... etc. 
  if(!bitmap.Attach(::LoadImage(
   ::GetModuleHandle(NULL), filename, IMAGE_BITMAP, 0, 0, 
   LR_LOADFROMFILE | LR_CREATEDIBSECTION | LR_DEFAULTSIZE))) {
    AfxMessageBox(_T(&quot;Error loading bitmap!&quot;)); return;
   } 
   BITMAP bm;
   bitmap.GetBitmap(&amp;bm);
   int w = bm.bmWidth; 
   int h = bm.bmHeight; 
   // create memory device context
   CDC memDC; 
   memDC.CreateCompatibleDC(&amp;dc);
   CBitmap *pBmp = memDC.SelectObject(&amp;bitmap);
   memDC.SetMapMode(dc.GetMapMode());
   dc.SetStretchBltMode(HALFTONE);
   // now stretchblt to maximum width on page
   dc.StretchBlt(0, 0, maxw, maxh, &amp;memDC, 0, 0, w, h, SRCCOPY); 
   // clean up
   memDC.SelectObject(pBmp);
   bPrintingOK = (dc.EndPage() &gt; 0);   // end page
 } 
 if (bPrintingOK)
   dc.EndDoc(); // end a print job
 else dc.AbortDoc();           // abort job.
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1111161</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1111161</guid><dc:creator><![CDATA[Anny]]></dc:creator><pubDate>Sat, 05 Aug 2006 16:11:04 GMT</pubDate></item><item><title><![CDATA[Reply to Ein Bitmap mit MFC drucken? on Sat, 05 Aug 2006 18:37:24 GMT]]></title><description><![CDATA[<p>Wie bekomm ich eigentlich die Größe des Bildes raus?</p>
<p>Ich würde dann ja hier maxw und maxh richtig ersetzen können<br />
um das gewünschte angepasste Druckbild zu bekommen.</p>
<pre><code class="language-cpp">dc.StretchBlt(0, 0, maxw, maxh, &amp;memDC, 0, 0, w, h, SRCCOPY);
</code></pre>
<p>Erster Ansatz führte zu chaotisch großen Zahlen.</p>
<pre><code class="language-cpp">CBitmap bitmap;
 BITMAP bm;
 bitmap.GetBitmap(&amp;bm);
 bitmap.LoadBitmap(filename);

int maxw = bm.bmWidth;  //wird ne zahl jenseits von 60000
int maxh = bm.bmHeight; //wird 114
</code></pre>
<p>Hüülfe <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1111235</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1111235</guid><dc:creator><![CDATA[Anny]]></dc:creator><pubDate>Sat, 05 Aug 2006 18:37:24 GMT</pubDate></item><item><title><![CDATA[Reply to Ein Bitmap mit MFC drucken? on Sat, 05 Aug 2006 20:32:10 GMT]]></title><description><![CDATA[<p>Du bist nen held -.- Holst dir erst die BITMAP struct und dann lädst de die Bitmap... wie um alles in der Welt sollen dann in bm die richtigen Daten stehen?</p>
<p>PS: Man sollte hier mal nen Wtf of the day forum machen <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f921.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--clown_face"
      title=":clown:"
      alt="🤡"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1111297</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1111297</guid><dc:creator><![CDATA[*D*Evil]]></dc:creator><pubDate>Sat, 05 Aug 2006 20:32:10 GMT</pubDate></item><item><title><![CDATA[Reply to Ein Bitmap mit MFC drucken? on Sun, 06 Aug 2006 07:56:08 GMT]]></title><description><![CDATA[<p>Ja gut das war vertauscht. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
<p>Egal, denn daran liegt es nicht!! Die Lösung für diesen Fall<br />
ist und bleibt offenbar BITMAPFILEHEADER. Denn damit habe ich<br />
es mir jetzt zusammengeschustert. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f644.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_rolling_eyes"
      title=":rolling_eyes:"
      alt="🙄"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1111391</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1111391</guid><dc:creator><![CDATA[A(nny)]]></dc:creator><pubDate>Sun, 06 Aug 2006 07:56:08 GMT</pubDate></item></channel></rss>