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!

change printer setting within program

Status
Not open for further replies.

fkkchung

Programmer
Oct 12, 2006
4
0
0
HK
Hi,

I was sent the following codes when I bump into some problem within FP and asking for help. This is suppose to be some API source code for changing the window printers settings without going thru Window's interactive dialog . Someone said its C++? If it is, what do I have to do to make it 'Window API' and workable? I had no idea how to deal with this kind of programming. Are they complete? I don't know why no one ask for the help that I was asking for (which I thought is a very common situation you will run into)


--------------------------------------------------------

BOOL SetPrinterDeviceOrientation(LPTSTR pszPrinterName, int Orientation)
{
// if NULL is passed, then assume we are setting app object's devmode and devnames

// Open printer
HANDLE hPrinter;
if( OpenPrinter( pszPrinterName, &hPrinter, NULL ) == FALSE )
return FALSE;

// obtain PRINTER_INFO_2 structure and close printer
DWORD dwBytesReturned, dwBytesNeeded;
GetPrinter( hPrinter, 2, NULL, 0, &dwBytesNeeded );
PRINTER_INFO_2* p2 = (PRINTER_INFO_2*)GlobalAlloc( GPTR, dwBytesNeeded);
if( GetPrinter( hPrinter, 2, (LPBYTE)p2, dwBytesNeeded, &dwBytesReturned) == 0 )
{
GlobalFree( p2 );
ClosePrinter( hPrinter );
return FALSE;
}

p2->pDevMode->dmFields |= DM_ORIENTATION;

p2->pDevMode->dmOrientation = Orientation;

if( SetPrinter(
hPrinter, // handle to printer object
2, // information level
(LPBYTE) p2, // printer data buffer
0 // printer-state command
) == 0 )
{
GlobalFree( p2 );
ClosePrinter( hPrinter );
return FALSE;
}


ClosePrinter( hPrinter );




// Allocate a global handle for DEVMODE

return TRUE;
}

------------------------------------------------------

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top