Article ID: 140271
Article Last Modified on 7/11/2005
/***********************************************************************
DoPrintDialog()
***********************************************************************/
BOOL DoPrintDialog(HWND hwndParent, BOOL bSetup)
{
PRINTDLG pd;
BOOL bReturn;
/*
initialize PRINTDLG structure
*/
ZeroMemory(&pd, sizeof(pd));
pd.lStructSize = sizeof(PRINTDLG);
pd.hwndOwner = hwndParent;
pd.hDevMode = NULL;
pd.hDevNames = NULL;
pd.nFromPage = 0;
pd.nToPage = 0;
pd.nMinPage = 0;
pd.nMaxPage = 0;
pd.nCopies = 0;
pd.hInstance = g_hInst;
if(bSetup)
{
/*
display the print setup dialog box
*/
pd.Flags = PD_RETURNDC |
PD_SHOWHELP |
PD_PRINTSETUP |
PD_ENABLESETUPHOOK;
pd.lpfnSetupHook = PrintDlgHookProc;
pd.lpSetupTemplateName = NULL;
}
else
{
/*
display the regular print dialog box
*/
pd.Flags = PD_RETURNDC |
PD_SHOWHELP |
PD_ENABLEPRINTHOOK;
pd.lpfnPrintHook = PrintDlgHookProc;
pd.lpPrintTemplateName = NULL;
}
bReturn = PrintDlg(&pd);
if(bReturn)
{
}
return bReturn;
}
/***********************************************************************
PrintDlgHookProc()
***********************************************************************/
BOOL CALLBACK PrintDlgHookProc( HWND hWnd,
UINT uMessage,
WPARAM wParam,
LPARAM lParam)
{
switch (uMessage)
{
case WM_INITDIALOG:
{
/*
lParam is a pointer to the PRINTDLG structure
*/
LPPRINTDLG lppd = (LPPRINTDLG)lParam;
/*
Only create the help button if it has been specified and it
doesn't already exist - pshHelp is defined in Dlgs.h.
*/
if( (lppd->Flags & PD_SHOWHELP) &&
(NULL == GetDlgItem(hWnd, pshHelp)))
{
RECT rc,
rcGroup;
HWND hwndHelp;
HFONT hFont;
/*
Get the rectangle of the OK button as a template
*/
GetWindowRect(GetDlgItem(hWnd, IDOK), &rc);
MapWindowPoints(HWND_DESKTOP, hWnd, (LPPOINT)&rc, 2);
/*
Get the rectangle of the group box
*/
GetWindowRect(GetDlgItem(hWnd, grp4), &rcGroup);
MapWindowPoints(HWND_DESKTOP, hWnd, (LPPOINT)&rcGroup, 2);
/*
Put the width in right and the height in left
*/
rc.right = rc.right - rc.left;
rc.bottom = rc.bottom - rc.top;
/*
Align the button - this is reliable for the print and setup
dialogs
*/
rc.left = rcGroup.left;
/*
Create the help button
*/
hwndHelp = CreateWindow(
"button",
"&Help Button",
WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_PUSHBUTTON,
rc.left,
rc.top,
rc.right,
rc.bottom,
hWnd,
(HMENU)pshHelp,
(HINSTANCE)GetWindowLong(hWnd, GWL_HINSTANCE),
NULL);
/*
Get the font from the OK button and set the font of the help
button
*/
hFont = (HFONT)SendDlgItemMessage(hWnd, IDOK, WM_GETFONT,
0, 0);
SendMessage(hwndHelp, WM_SETFONT, (WPARAM)hFont, 0);
}
}
return TRUE;
}
return FALSE;
}
Keywords: kbbug kboswin98fix kbcmndlgprint kbcmndlg kbprb kbcode KB140271