![]() |
| | #1 |
| Registered User Join Date: May 2005
Posts: 39
| changing property (layout) of a printer I got this piece of code from somewhere which seems to run as expected. It sets the DEVMODE structure and exits without error. But when I check the property of the printer, it hasn't changed could somebody please verify if this code runs properly on their machines. If you notice any flaws or errors do let me know Code: #include "stdafx.h"
#include <windows.h>
LPDEVMODE GetLandscapeDevMode(HWND hWnd, char *pDevice)
{
HANDLE hPrinter;
LPDEVMODE pDevMode;
DWORD dwNeeded, dwRet;
/* Start by opening the printer */
if (!OpenPrinter(pDevice, &hPrinter, NULL))
return NULL;
/*
* Step 1:
* Allocate a buffer of the correct size.
*/
dwNeeded = DocumentProperties(hWnd,
hPrinter, /* Handle to our printer. */
pDevice, /* Name of the printer. */
NULL, /* Asking for size, so */
NULL, /* these are not used. */
0); /* Zero returns buffer size. */
pDevMode = (LPDEVMODE)malloc(dwNeeded);
/*
* Step 2:
* Get the default DevMode for the printer and
* modify it for your needs.
*/
dwRet = DocumentProperties(hWnd,
hPrinter,
pDevice,
pDevMode, /* The address of the buffer to fill. */
NULL, /* Not using the input buffer. */
DM_OUT_BUFFER); /* Have the output buffer filled. */
if (dwRet != IDOK)
{
/* If failure, cleanup and return failure. */
free(pDevMode);
ClosePrinter(hPrinter);
return NULL;
}
/*
* Make changes to the DevMode which are supported.
*/
if (pDevMode->dmFields & DM_ORIENTATION)
{
/* If the printer supports paper orientation, set it.*/
pDevMode->dmOrientation = DMORIENT_LANDSCAPE;
}
/*
* Step 3:
* Merge the new settings with the old.
* This gives the driver an opportunity to update any private
* portions of the DevMode structure.
*/
dwRet = DocumentProperties(hWnd,
hPrinter,
pDevice,
pDevMode, /* Reuse our buffer for output. */
pDevMode, /* Pass the driver our changes. */
DM_IN_BUFFER | /* Commands to Merge our changes and */
DM_OUT_BUFFER); /* write the result. */
/* Finished with the printer */
ClosePrinter(hPrinter);
if (dwRet != IDOK)
{
/* If failure, cleanup and return failure. */
free(pDevMode);
return NULL;
}
/* Return the modified DevMode structure. */
return pDevMode;
}
int main(void)
{
GetLandscapeDevMode(NULL,"Ghostscript PDF");
return 0;
}
|
| leojose is offline | |
| | #2 |
| carry on Join Date: Feb 2003 Location: Seattle, WA
Posts: 1,971
| I haven't done anything with the printing functions but it sounds likie the DocumentProperties function makes changes that are local to the application (link). Edit: Actually, I don't think it makes any changes, it just gives you a valid DEVMODE structure to use with CreateDC
__________________ "Think not but that I know these things; or think I know them not: not therefore am I short Of knowing what I ought." -John Milton, Paradise Regained (1671) "Work hard and it might happen." -XSquared Last edited by JaWiB; 12-03-2005 at 12:50 PM. |
| JaWiB is offline | |
| | #3 |
| Yes, my avatar is stolen Join Date: Dec 2002
Posts: 2,544
| It sounds like you are trying to change the default settings for the printer. I think this printer orientation sample may be useful. |
| anonytmouse is offline | |
| | #4 | ||
| Registered User Join Date: May 2005
Posts: 39
| Quote:
Quote:
But there is a particular limitation I observed (and it is important for my design). the changes don't seem to affect 'open' applications. For e.g. If I run IE first and then run this application to change the layout of printer, IE still doesn't recognize the change and keeps printing in the previous format. Restarting the application does help, but my requirement prevents me from doing so. On the contrary, applications like MS-Word updates its database automatically. Is there any method by which I can force applications like IE to make such changes on the fly? Thanks for your responses so far... | ||
| leojose is offline | |
| | #5 |
| Yes, my avatar is stolen Join Date: Dec 2002
Posts: 2,544
| This appears to be an issue with IE. Assumably, it loads the printer settings at startup and doesn't repspond to the WM_DEVMODECHANGE message. |
| anonytmouse is offline | |
| | #6 |
| Registered User Join Date: May 2005
Posts: 39
| Thanks for verifying the source of the problem anonytmouse Luckily for me, I am using a flash application, and unlike IE it does update on a WM_DEVMODECHANGE. Hence it solve my problem |
| leojose is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Set Printer Prior To Loading Print Dialog Box | Beaner | Windows Programming | 3 | 10-10-2008 01:02 PM |
| Problem with a file parser. | Hulag | C++ Programming | 7 | 03-17-2005 09:54 AM |
| Success - Output to Printer | noraa | C Programming | 5 | 08-04-2002 09:12 AM |
| Property Sheets :: MFC | kuphryn | Windows Programming | 0 | 05-09-2002 03:04 PM |
| Changing printer | goodz13 | C++ Programming | 0 | 01-16-2002 09:46 PM |