📄 printdlg.c
字号:
PRINTDLG_SetUpPaperComboBoxW(hDlg, cmb3,
PrintStructures->lpPrinterInfo->pPrinterName,
PrintStructures->lpPrinterInfo->pPortName,
lpdm);
CheckRadioButton(hDlg, rad1, rad2, bPortrait ? rad1: rad2);
SendDlgItemMessageW(hDlg, ico1, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
(LPARAM)(bPortrait ? PrintStructures->hPortraitIcon :
PrintStructures->hLandscapeIcon));
}
/* help button */
if ((lppd->Flags & PD_SHOWHELP)==0) {
/* hide if PD_SHOWHELP not specified */
ShowWindow(GetDlgItem(hDlg, pshHelp), SW_HIDE);
}
return TRUE;
}
/***********************************************************************
* check_printer_setup [internal]
*/
static LRESULT check_printer_setup(HWND hDlg)
{
DWORD needed,num;
WCHAR resourcestr[256],resultstr[256];
int res;
EnumPrintersW(PRINTER_ENUM_LOCAL, NULL, 2, NULL, 0, &needed, &num);
if(needed == 0)
{
EnumPrintersW(PRINTER_ENUM_CONNECTIONS, NULL, 2, NULL, 0, &needed, &num);
}
if(needed > 0)
return TRUE;
else
{
LoadStringW(COMDLG32_hInstance, PD32_NO_DEVICES,resultstr, 255);
LoadStringW(COMDLG32_hInstance, PD32_PRINT_TITLE,resourcestr, 255);
res = MessageBoxW(hDlg, resultstr, resourcestr,MB_OK | MB_ICONWARNING);
return FALSE;
}
}
/***********************************************************************
* PRINTDLG_WMInitDialog [internal]
*/
static LRESULT PRINTDLG_WMInitDialog(HWND hDlg, WPARAM wParam,
PRINT_PTRA* PrintStructures)
{
LPPRINTDLGA lppd = PrintStructures->lpPrintDlg;
DEVNAMES *pdn;
DEVMODEA *pdm;
char *name = NULL;
UINT comboID = (lppd->Flags & PD_PRINTSETUP) ? cmb1 : cmb4;
/* load Collate ICONs */
/* We load these with LoadImage because they are not a standard
size and we don't want them rescaled */
PrintStructures->hCollateIcon =
LoadImageA(COMDLG32_hInstance, "PD32_COLLATE", IMAGE_ICON, 0, 0, 0);
PrintStructures->hNoCollateIcon =
LoadImageA(COMDLG32_hInstance, "PD32_NOCOLLATE", IMAGE_ICON, 0, 0, 0);
/* These can be done with LoadIcon */
PrintStructures->hPortraitIcon =
LoadIconA(COMDLG32_hInstance, "PD32_PORTRAIT");
PrintStructures->hLandscapeIcon =
LoadIconA(COMDLG32_hInstance, "PD32_LANDSCAPE");
/* display the collate/no_collate icon */
SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
(LPARAM)PrintStructures->hNoCollateIcon);
if(PrintStructures->hCollateIcon == 0 ||
PrintStructures->hNoCollateIcon == 0 ||
PrintStructures->hPortraitIcon == 0 ||
PrintStructures->hLandscapeIcon == 0) {
ERR("no icon in resourcefile\n");
COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
EndDialog(hDlg, FALSE);
}
/*
* if lppd->Flags PD_SHOWHELP is specified, a HELPMESGSTRING message
* must be registered and the Help button must be shown.
*/
if (lppd->Flags & PD_SHOWHELP) {
if((PrintStructures->HelpMessageID =
RegisterWindowMessageA(HELPMSGSTRINGA)) == 0) {
COMDLG32_SetCommDlgExtendedError(CDERR_REGISTERMSGFAIL);
return FALSE;
}
} else
PrintStructures->HelpMessageID = 0;
if(!(lppd->Flags &PD_PRINTSETUP)) {
PrintStructures->hwndUpDown =
CreateUpDownControl(WS_CHILD | WS_VISIBLE | WS_BORDER |
UDS_NOTHOUSANDS | UDS_ARROWKEYS |
UDS_ALIGNRIGHT | UDS_SETBUDDYINT, 0, 0, 0, 0,
hDlg, UPDOWN_ID, COMDLG32_hInstance,
GetDlgItem(hDlg, edt3), MAX_COPIES, 1, 1);
}
/* FIXME: I allow more freedom than either Win95 or WinNT,
* which do not agree to what errors should be thrown or not
* in case nToPage or nFromPage is out-of-range.
*/
if (lppd->nMaxPage < lppd->nMinPage)
lppd->nMaxPage = lppd->nMinPage;
if (lppd->nMinPage == lppd->nMaxPage)
lppd->Flags |= PD_NOPAGENUMS;
if (lppd->nToPage < lppd->nMinPage)
lppd->nToPage = lppd->nMinPage;
if (lppd->nToPage > lppd->nMaxPage)
lppd->nToPage = lppd->nMaxPage;
if (lppd->nFromPage < lppd->nMinPage)
lppd->nFromPage = lppd->nMinPage;
if (lppd->nFromPage > lppd->nMaxPage)
lppd->nFromPage = lppd->nMaxPage;
/* if we have the combo box, fill it */
if (GetDlgItem(hDlg,comboID)) {
/* Fill Combobox
*/
pdn = GlobalLock(lppd->hDevNames);
pdm = GlobalLock(lppd->hDevMode);
if(pdn)
name = (char*)pdn + pdn->wDeviceOffset;
else if(pdm)
name = (char*)pdm->dmDeviceName;
PRINTDLG_SetUpPrinterListComboA(hDlg, comboID, name);
if(pdm) GlobalUnlock(lppd->hDevMode);
if(pdn) GlobalUnlock(lppd->hDevNames);
/* Now find selected printer and update rest of dlg */
name = HeapAlloc(GetProcessHeap(),0,256);
if (GetDlgItemTextA(hDlg, comboID, name, 255))
PRINTDLG_ChangePrinterA(hDlg, name, PrintStructures);
HeapFree(GetProcessHeap(),0,name);
} else {
/* else use default printer */
char name[200];
DWORD dwBufLen = sizeof(name);
BOOL ret = GetDefaultPrinterA(name, &dwBufLen);
if (ret)
PRINTDLG_ChangePrinterA(hDlg, name, PrintStructures);
else
FIXME("No default printer found, expect problems!\n");
}
return TRUE;
}
static LRESULT PRINTDLG_WMInitDialogW(HWND hDlg, WPARAM wParam,
PRINT_PTRW* PrintStructures)
{
static const WCHAR PD32_COLLATE[] = { 'P', 'D', '3', '2', '_', 'C', 'O', 'L', 'L', 'A', 'T', 'E', 0 };
static const WCHAR PD32_NOCOLLATE[] = { 'P', 'D', '3', '2', '_', 'N', 'O', 'C', 'O', 'L', 'L', 'A', 'T', 'E', 0 };
static const WCHAR PD32_PORTRAIT[] = { 'P', 'D', '3', '2', '_', 'P', 'O', 'R', 'T', 'R', 'A', 'I', 'T', 0 };
static const WCHAR PD32_LANDSCAPE[] = { 'P', 'D', '3', '2', '_', 'L', 'A', 'N', 'D', 'S', 'C', 'A', 'P', 'E', 0 };
LPPRINTDLGW lppd = PrintStructures->lpPrintDlg;
DEVNAMES *pdn;
DEVMODEW *pdm;
WCHAR *name = NULL;
UINT comboID = (lppd->Flags & PD_PRINTSETUP) ? cmb1 : cmb4;
/* load Collate ICONs */
/* We load these with LoadImage because they are not a standard
size and we don't want them rescaled */
PrintStructures->hCollateIcon =
LoadImageW(COMDLG32_hInstance, PD32_COLLATE, IMAGE_ICON, 0, 0, 0);
PrintStructures->hNoCollateIcon =
LoadImageW(COMDLG32_hInstance, PD32_NOCOLLATE, IMAGE_ICON, 0, 0, 0);
/* These can be done with LoadIcon */
PrintStructures->hPortraitIcon =
LoadIconW(COMDLG32_hInstance, PD32_PORTRAIT);
PrintStructures->hLandscapeIcon =
LoadIconW(COMDLG32_hInstance, PD32_LANDSCAPE);
/* display the collate/no_collate icon */
SendDlgItemMessageW(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
(LPARAM)PrintStructures->hNoCollateIcon);
if(PrintStructures->hCollateIcon == 0 ||
PrintStructures->hNoCollateIcon == 0 ||
PrintStructures->hPortraitIcon == 0 ||
PrintStructures->hLandscapeIcon == 0) {
ERR("no icon in resourcefile\n");
COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
EndDialog(hDlg, FALSE);
}
/*
* if lppd->Flags PD_SHOWHELP is specified, a HELPMESGSTRING message
* must be registered and the Help button must be shown.
*/
if (lppd->Flags & PD_SHOWHELP) {
if((PrintStructures->HelpMessageID =
RegisterWindowMessageW(HELPMSGSTRINGW)) == 0) {
COMDLG32_SetCommDlgExtendedError(CDERR_REGISTERMSGFAIL);
return FALSE;
}
} else
PrintStructures->HelpMessageID = 0;
if(!(lppd->Flags &PD_PRINTSETUP)) {
PrintStructures->hwndUpDown =
CreateUpDownControl(WS_CHILD | WS_VISIBLE | WS_BORDER |
UDS_NOTHOUSANDS | UDS_ARROWKEYS |
UDS_ALIGNRIGHT | UDS_SETBUDDYINT, 0, 0, 0, 0,
hDlg, UPDOWN_ID, COMDLG32_hInstance,
GetDlgItem(hDlg, edt3), MAX_COPIES, 1, 1);
}
/* FIXME: I allow more freedom than either Win95 or WinNT,
* which do not agree to what errors should be thrown or not
* in case nToPage or nFromPage is out-of-range.
*/
if (lppd->nMaxPage < lppd->nMinPage)
lppd->nMaxPage = lppd->nMinPage;
if (lppd->nMinPage == lppd->nMaxPage)
lppd->Flags |= PD_NOPAGENUMS;
if (lppd->nToPage < lppd->nMinPage)
lppd->nToPage = lppd->nMinPage;
if (lppd->nToPage > lppd->nMaxPage)
lppd->nToPage = lppd->nMaxPage;
if (lppd->nFromPage < lppd->nMinPage)
lppd->nFromPage = lppd->nMinPage;
if (lppd->nFromPage > lppd->nMaxPage)
lppd->nFromPage = lppd->nMaxPage;
/* if we have the combo box, fill it */
if (GetDlgItem(hDlg,comboID)) {
/* Fill Combobox
*/
pdn = GlobalLock(lppd->hDevNames);
pdm = GlobalLock(lppd->hDevMode);
if(pdn)
name = (WCHAR*)pdn + pdn->wDeviceOffset;
else if(pdm)
name = pdm->dmDeviceName;
PRINTDLG_SetUpPrinterListComboW(hDlg, comboID, name);
if(pdm) GlobalUnlock(lppd->hDevMode);
if(pdn) GlobalUnlock(lppd->hDevNames);
/* Now find selected printer and update rest of dlg */
/* ansi is ok here */
name = HeapAlloc(GetProcessHeap(),0,256*sizeof(WCHAR));
if (GetDlgItemTextW(hDlg, comboID, name, 255))
PRINTDLG_ChangePrinterW(hDlg, name, PrintStructures);
HeapFree(GetProcessHeap(),0,name);
} else {
/* else use default printer */
WCHAR name[200];
DWORD dwBufLen = sizeof(name) / sizeof(WCHAR);
BOOL ret = GetDefaultPrinterW(name, &dwBufLen);
if (ret)
PRINTDLG_ChangePrinterW(hDlg, name, PrintStructures);
else
FIXME("No default printer found, expect problems!\n");
}
return TRUE;
}
/***********************************************************************
* PRINTDLG_WMCommand [internal]
*/
LRESULT PRINTDLG_WMCommandA(HWND hDlg, WPARAM wParam,
LPARAM lParam, PRINT_PTRA* PrintStructures)
{
LPPRINTDLGA lppd = PrintStructures->lpPrintDlg;
UINT PrinterComboID = (lppd->Flags & PD_PRINTSETUP) ? cmb1 : cmb4;
LPDEVMODEA lpdm = PrintStructures->lpDevMode;
switch (LOWORD(wParam)) {
case IDOK:
TRACE(" OK button was hit\n");
if (!PRINTDLG_UpdatePrintDlgA(hDlg, PrintStructures)) {
FIXME("Update printdlg was not successful!\n");
return(FALSE);
}
EndDialog(hDlg, TRUE);
return(TRUE);
case IDCANCEL:
TRACE(" CANCEL button was hit\n");
EndDialog(hDlg, FALSE);
return(FALSE);
case pshHelp:
TRACE(" HELP button was hit\n");
SendMessageA(lppd->hwndOwner, PrintStructures->HelpMessageID,
(WPARAM) hDlg, (LPARAM) lppd);
break;
case chx2: /* collate pages checkbox */
if (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED)
SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
(LPARAM)PrintStructures->hCollateIcon);
else
SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
(LPARAM)PrintStructures->hNoCollateIcon);
break;
case edt1: /* from page nr editbox */
case edt2: /* to page nr editbox */
if (HIWORD(wParam)==EN_CHANGE) {
WORD nToPage;
WORD nFromPage;
nFromPage = GetDlgItemInt(hDlg, edt1, NULL, FALSE);
nToPage = GetDlgItemInt(hDlg, edt2, NULL, FALSE);
if (nFromPage != lppd->nFromPage || nToPage != lppd->nToPage)
CheckRadioButton(hDlg, rad1, rad3, rad3);
}
break;
case edt3:
if(HIWORD(wParam) == EN_CHANGE) {
INT copies = GetDlgItemInt(hDlg, edt3, NULL, FALSE);
if(copies <= 1)
EnableWindow(GetDlgItem(hDlg, chx2), FALSE);
else
EnableWindow(GetDlgItem(hDlg, chx2), TRUE);
}
break;
#if 0
case psh1: /* Print Setup */
{
PRINTDLG16 pdlg;
if (!PrintStructures->dlg.lpPrintDlg16) {
FIXME("The 32bit print dialog does not have this button!?\n");
break;
}
memcpy(&pdlg,PrintStructures->dlg.lpPrintDlg16,sizeof(pdlg));
pdlg.Flags |= PD_PRINTSETUP;
pdlg.hwndOwner = HWND_16(hDlg);
if (!PrintDlg16(&pdlg))
break;
}
break;
#endif
case psh2: /* Properties button */
{
HANDLE hPrinter;
char PrinterName[256];
GetDlgItemTextA(hDlg, PrinterComboID, PrinterName, 255);
if (!OpenPrinterA(PrinterName, &hPrinter, NULL)) {
FIXME(" Call to OpenPrinter did not succeed!\n");
break;
}
DocumentPropertiesA(hDlg, hPrinter, PrinterName,
PrintStructures->lpDevMode,
PrintStructures->lpDevMode,
DM_IN_BUFFER | DM_OUT_BUFFER | DM_IN_PROMPT);
ClosePrinter(hPrinter);
break;
}
case rad1: /* Paperorientation */
if (lppd->Flags & PD_PRINTSETUP)
{
lpdm->u.s.dmOrientation = DMORIENT_PORTRAIT;
SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
(LPARAM)(PrintStructures->hPortraitIcon));
}
break;
case rad2: /* Paperorientation */
if (lppd->Flags & PD_PRINTSETUP)
{
lpdm->u.s.dmOrientation = DMORIENT_LANDSCAPE;
SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
(LPARAM)(PrintStructures->hLandscapeIcon));
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -