Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Get the HDC for the printer

Posted on 2002-04-11
3
433 Views
Last Modified: 2008-02-01
Hi

How do you get the HDC for the default printer in windows ?
0
Comment
Question by:win32
  • 2
3 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 6934067
You'd usually use 'PrintDlg()' to do this, e.g.

PRINTDLG pdlg;

ZeroMemory ( &pdlg, sizeof ( PRINTDLG));

pdlg.Flags = PD_RETURNDC | PD_RETURNDEFAULT;

PrintDlg ( &pdlg);

HDC hDC = pdlg.hDC;
0
 
LVL 32

Accepted Solution

by:
jhance earned 75 total points
ID: 6934199
To do it without need for the printer dialog...

HDC GetPrinterDC(void)
{
     DWORD dwNeeded, dwReturned;
     HDC hdc;
     PRINTER_INFO_5 *pinfo5;
     TCHAR *lpszPrinter;

     if(GetVersion() & 0x800000000){
          // Win9x
          EnumPrinters(PRINTER_ATTRIBUTE_DEFAULT, NULL, 5, NULL, 0, &dwNeeded, &dwReturned);
          pinfo5 = (PRINTER_INFO_5 *)malloc(dwNeeded);

          EnumPrinters(PRINTER_ATTRIBUTE_DEFAULT, NULL, 5, (PBYTE)pinfo5, dwNeeded, &dwNeeded, &dwReturned);

          hdc = CreateDC(NULL, pinfo5->pPrinterName, NULL, NULL);

          free(pinfo5);
     }
     else{
          // WinNT/2000/XP

          GetDefaultPrinter(NULL, &dwNeeded);
          lpszPrinter = new TCHAR[dwNeeded];
          GetDefaultPrinter(lpszPrinter, &dwNeeded);
          hdc = CreateDC(NULL, lpszPrinter, NULL, NULL);
          delete [] lpszPrinter;
     }

     return hdc;
}
0
 
LVL 86

Expert Comment

by:jkr
ID: 6934231
>>To do it without need for the printer dialog...

The dialog doesn't even show up using this method...
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
convert char array to number in c 5 86
I could not build boost code, 10 94
Why isn't object file created? 6 68
FMX TEdit KeyUp handler detecting  "enter" key 4 13
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question