c++ - win32: how use the printer?
c++ - win32: how use the printer?
c++ - win32: how use the printer?
c++ - win32: how use the printer?
c++ - win32: how use the printer?
c++ - win32: how use the printer? c++ - win32: how use the printer? c++ - win32: how use the printer? c++ - win32: how use the printer? c++ - win32: how use the printer? c++ - win32: how use the printer? c++ - win32: how use the printer? c++ - win32: how use the printer?
c++ - win32: how use the printer? c++ - win32: how use the printer?
c++ - win32: how use the printer?
Go Back  Xtreme Visual Basic Talk > > > c++ - win32: how use the printer?


Reply
 
Thread Tools Display Modes
  #1  
Old 08-28-2015, 04:54 AM
Cambalinho_83's Avatar
Cambalinho_83 Cambalinho_83 is offline
Senior Contributor
 
Join Date: Feb 2008
Location: somewhere in space
Posts: 1,295
Default c++ - win32: how use the printer?


i have these code for print:
Code:
void print()
        {
            //getting the default printer name
            char szPrinterName[256];
            unsigned long lPrinterNameLength;
            GetDefaultPrinter( szPrinterName, &lPrinterNameLength );
                DebugText(szPrinterName);
            //getting printer DC
            HDC printerDC = CreateDC( "WINSPOOL",szPrinterName, NULL, NULL);
            if(printerDC==NULL)
                DebugText(to_string(GetLastError()));
            //starting doc and pages:
            DOCINFO doc;
            doc.cbSize = sizeof(DOCINFO);
            doc.lpszDocName = "1st doc";
            if(StartDoc(printerDC, &doc)<=0)
                DebugText("start doc errror");
            if(StartPage(printerDC)<=0)
                DebugText("start page errror");

            //draw on printer using GDI functions
            RECT windowRect;
            GetClientRect(hwnd,&windowRect);

            HDC windowDc=GetDC(hwnd);
            if(windowDc==NULL || printerDC==NULL)
                DebugText("HDC error");
            long width= windowRect.right* 1440 / GetDeviceCaps(windowDc, LOGPIXELSX);
            long height=windowRect.bottom* 1440 / GetDeviceCaps(windowDc, LOGPIXELSY);
            DebugText("width: " + to_string(width) + "\r\nheight: " + to_string(height));

            StretchBlt(printerDC,0,0,width,height,windowDc,0,0,windowRect.right,windowRect.bottom,SRCCOPY);

            //end pages and doc
            if(EndPage(printerDC)<=0)
                DebugText("end page error");
            if(EndDoc(printerDC)<=0)
                DebugText("end doc error");
            //delete the printer DC
            DeleteDC(printerDC);
            ReleaseDC(hwnd,windowDc);
        }
i don't ger any errors. only, sometimes, with GetLastError()
i'm totaly confused, because, by some resason, these code is very instable. sometimes can works and other times don't
i can't see the error
the printer name seems correct. can anyone advice me?
Reply With Quote
Reply

Tags
printer, doc;, //getting, print, null, null;, ifprinterdc==null, winspool, szprintername, createdc, hdc, printerdc, &doc, //starting, doc, 1st, doc.cbsize, sizeofdocinfo;, docinfo, pages, ifstartdocprinterdc, doc.lpszdocname, &lprinternamelength, code, void, win32


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
c++ - win32: how use the printer?
c++ - win32: how use the printer?
c++ - win32: how use the printer? c++ - win32: how use the printer?
c++ - win32: how use the printer?
c++ - win32: how use the printer?
c++ - win32: how use the printer? c++ - win32: how use the printer? c++ - win32: how use the printer? c++ - win32: how use the printer? c++ - win32: how use the printer? c++ - win32: how use the printer? c++ - win32: how use the printer?
c++ - win32: how use the printer?
c++ - win32: how use the printer?
 
c++ - win32: how use the printer?
c++ - win32: how use the printer?
 
-->