Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get PRINTDLG struct by printer name

Status
Not open for further replies.

sgk17

Technical User
Nov 8, 2002
68
0
0
US
Hi, I'm writing code to print. What I've managed so far is to use the PrintDlg function to allow a user to select a printer and print. Now what I want is to programmatically select the printer. I have the printer name. Can I get a PRINTDLG struct that corresponds to that name? If so, how? If not, what's another way to do it?
 
Well, you can research the EnumPrinters function, it takes either a PRINTER_INFO_4 or a PRINTER_INFO_5 structure, but you can get local or default printer names with this function.

Call it once to obtain the size of the structure it needs, and again to actually fill it.

here's a snippet.

EnumPrinters( PRINTER_ENUM_LOCAL,, NULL, 4, NULL, 0, &dwNeeded, &dwReturned );

Get the size of the things you need for the structure.

dwNeeded, and dwRetured are both defined as DWORD values.

PRINTER_INFO_4 * pinfo4; //used for windows NT.

pinfo4 = malloc( dwNeeded );

EnumPrinters( PRINTER_ENUM_LOCAL, NULL, 4, (PBYTE) pinfo4,
dwNeeded, &dwNeeded, &dwRetured );

Fill the actual structure.

then, put it in an hdc..

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

free( pinfo4 );



now if you were to wrap this up into a function, you can
call it from a part of another window's program, say...

HDC hdcPrn;


if( NULL == (hdcPrn = GetPrinterDC( ) ) )
return FALSE;

this will populate your hdcPrn with the values you obtained by using that function to get your printer name/values, etc.


then you can

if( StartDoc( hdcPrn .....

hope this is what you were asking

The weevil of doooooooooom
-The eagle may soar, but the weasel never gets sucked up by a jet engine (Anonymous)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top