我无法为文档设置“默认”页面大小。我在Windows上使用Visual C ++,使用GDI调用(向后兼容所需)。
到目前为止,我的基本方法是获取默认值DEVMODE
,在其上设置我想要的属性,然后提示用户是否要更改它。但它似乎对页面大小没有影响。它适用于Orientation。
我做错了什么?
HDC GetPrinterDC () {
// Initialize device
PRINTDLG pd = {0};
pd.lStructSize = sizeof( pd );
pd.Flags = PD_RETURNDEFAULT;
PrintDlg(&pd);
// If device initialization failed, abort
if (pd.hDevMode == NULL) return NULL;
// Get the actual memory pointer
PDEVMODE dm = (PDEVMODE)GlobalLock(pd.hDevMode);
if (dm) {
// Set any properties that are specific for our document
if (dm->dmFields & DM_ORIENTATION)
dm->dmOrientation = DMORIENT_LANDSCAPE;
if (dm->dmFields & DM_PAPERSIZE)
dm->dmPaperSize = 0;
if (dm->dmFields & DM_PAPERLENGTH)
dm->dmPaperLength = 3302; // 13in
if (dm->dmFields & DM_PAPERWIDTH)
dm->dmPaperWidth = 4572; // 18in
GlobalUnlock(pd.hDevMode);
}
// Initialize a PRINTDLG structure.
pd.hwndOwner = GetForegroundWindow();
pd.Flags = PD_RETURNDC | PD_HIDEPRINTTOFILE | PD_DISABLEPRINTTOFILE | PD_NOPAGENUMS | PD_NOSELECTION | PD_USEDEVMODECOPIESANDCOLLATE ;
// Retrieve the printer DC
HDC hdc = NULL;
if (PrintDlg(&pd)) hdc = pd.hDC;
// Free the resources allocated
if (pd.hDevMode != NULL) GlobalFree(pd.hDevMode);
if (pd.hDevNames != NULL) GlobalFree(pd.hDevNames);
return hdc;
}
答案 0 :(得分:1)
显然,您可以在dmFields
结构中指定DEVMODE
为您想要的任何内容。
代码应如下所示:
PDEVMODE dm = (PDEVMODE)GlobalLock(pd.hDevMode);
if (dm) {
// Set any properties that are specific for our document
dm->dmFields = dm->dmFields | DM_ORIENTATION | DM_PAPERSIZE
| DM_PAPERLENGTH | DM_PAPERWIDTH;
dm->dmOrientation = DMORIENT_LANDSCAPE;
dm->dmPaperSize = 0;
dm->dmPaperLength = 3302; // 13in
dm->dmPaperWidth = 4572; // 18in
GlobalUnlock(pd.hDevMode);
}