Print this window

void TfrmPrintSearch::setPrinterOrientation(bool lay)
 
{
if (printDC)
{
HANDLE hPrinter;
LPDEVMODE pDevMode; // Printer capabilities
DWORD dwTemp; // Temp variable of printer capabilities
DWORD dwRet; // Variable so that we can change the printer capabilities
if (!OpenPrinter(pPrintName, &hPrinter, NULL))
Application->MessageBox("Could not open printer", "Printer failure", MB_OK);
else
{
dwTemp = DocumentProperties(Handle, // Handle to the form that owns the print job
hPrinter, // Handle to the printer
pPrintName, // Name of the printer
NULL, // Not needed for this one
NULL, // Not needed for this one
0); // Zero returns the buffer size
pDevMode = (LPDEVMODE)malloc(dwTemp);

dwRet = DocumentProperties(Handle, // Handle to the form that owns the print job
hPrinter, // Printer handle
pPrintName, // Printer name
pDevMode, // Address of the structur to fill
NULL, // Not using the input buffer
DM_OUT_BUFFER); // Have the output buffer filled
if (dwRet != IDOK) // Failure of the call, get out
{
free(pDevMode); // Free up the malloc call
Application->MessageBox("Orientation change failed", "Printer failure", MB_OK);
} // End the if
else
{
if (!lay) // Going for portrait
{
if (pDevMode->dmFields & DM_ORIENTATION)// Make changes to the orientation if it is available
pDevMode->dmOrientation = DMORIENT_LANDSCAPE;
} // End the if
else
{
if (pDevMode->dmFields & DM_ORIENTATION) // Make changes to the orientation if it is available
pDevMode->dmOrientation = DMORIENT_PORTRAIT;
} // End the else
// Could be assigned to dwRet = to check for return value
DocumentProperties(Handle, hPrinter, pPrintName,
pDevMode, // Reuse our buffer for output
pDevMode, // Pass the driver our changes
DM_IN_BUFFER |
DM_OUT_BUFFER); // Write the result

ResetDC(printDC, pDevMode); // Update the printer to the new printing orientation
free(pDevMode);
} // End the dwRet else
} // End the OpenPrinter else
} // End the if printDC
} // End the setPrinterLandscape method