⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cmndlg32.c

📁 THE DECISION TREE ALGORITHM USED VC
💻 C
📖 第 1 页 / 共 5 页
字号:

/****************************************************************************
*
*    FUNCTION: ChooseFontHookProc(HWND, UINT, UINT, LONG)
*
*    PURPOSE:  Processes messages for ChooseFont common dialog box
*
*    COMMENTS:
*
*        This hook procedure simply prompts the user whether or not they
*        want to change the font.  if they choose YES, the color of the
*        font will be changed and the dialog will be dismissed.  If they
*        choose NO, the font will not be changed and the user will be
*        returned to the dialog
*
*        If the current mode is set to use a customized template, the
*        color drop down combo box is hidden.
*
*    RETURN VALUES:
*        TRUE - Change the font.
*        FALSE - Return to the dialog box.
*
****************************************************************************/

BOOL APIENTRY ChooseFontHookProc(
        HWND hDlg,                /* window handle of the dialog box */
        UINT message,             /* type of message                 */
        UINT wParam,            /* message-specific information    */
        LONG lParam)
{

    switch (message)
    {
        case WM_INITDIALOG:
            if (chf.Flags & CF_ENABLETEMPLATE)
            {
                ShowWindow(GetDlgItem(hDlg, stc4), SW_HIDE);
                ShowWindow(GetDlgItem(hDlg, cmb4), SW_HIDE);
            }
            break;

        case WM_COMMAND:
            if (LOWORD(wParam) == IDOK)
            {
                if (MessageBox( hDlg, "Are you sure you want to change the font?",
                    "Information", MB_YESNO ) == IDYES )
                    break;
                return (TRUE);

            }
            break;
    }
    return (FALSE);

    // avoid compiler warnings at W3
    lParam;

}


/****************************************************************************
*
*    FUNCTION: ChooseNewFont(HWND)
*
*    PURPOSE:  Invokes common dialog function to chose a new font.
*
*    COMMENTS:
*
*        This function initializes the CHOOSEFONT structure for any mode
*        the user chooses: standard, using a hook or using a customized
*        template.  It then calls the ChooseFont() common dialog function.
*
*    RETURN VALUES:
*        TRUE - A new font was chosen.
*        FALSE - No new font was chosen.
*
****************************************************************************/
BOOL ChooseNewFont( HWND hWnd )
{

   HDC hDC;

   hDC = GetDC( hWnd );
   chf.hDC = CreateCompatibleDC( hDC );
   ReleaseDC( hWnd, hDC );
   chf.lStructSize = sizeof(CHOOSEFONT);
   chf.hwndOwner = hWnd;
   chf.lpLogFont = &lf;
   chf.Flags = CF_SCREENFONTS | CF_EFFECTS;
   chf.rgbColors = RGB(0, 255, 255);
   chf.lCustData = 0;
   chf.hInstance = (HANDLE)hInst;
   chf.lpszStyle = (LPTSTR)NULL;
   chf.nFontType = SCREEN_FONTTYPE;
   chf.nSizeMin = 0;
   chf.nSizeMax = 0;

   switch( wMode )
   {
        case IDM_STANDARD:
            chf.Flags = CF_SCREENFONTS | CF_EFFECTS;
            chf.lpfnHook = (LPCFHOOKPROC)(FARPROC)NULL;
            chf.lpTemplateName = (LPTSTR)NULL;
            break;

        case IDM_HOOK:
            chf.Flags = CF_SCREENFONTS | CF_EFFECTS | CF_ENABLEHOOK;
            chf.lpfnHook = (LPCFHOOKPROC)ChooseFontHookProc;
            chf.lpTemplateName = (LPTSTR)NULL;
            break;

        case IDM_CUSTOM:
            chf.Flags = CF_SCREENFONTS | CF_EFFECTS | CF_ENABLEHOOK |
              CF_ENABLETEMPLATE;
            chf.lpfnHook = (LPCFHOOKPROC)ChooseFontHookProc;
           	chf.lpTemplateName = (LPTSTR)MAKEINTRESOURCE(FORMATDLGORD31);
            break;
   }


   if( ChooseFont( &chf ) == FALSE )
   {
        DeleteDC( hDC );
        ProcessCDError(CommDlgExtendedError(), hWnd );
        return FALSE;
   }


   DeleteDC( hDC );

   return (TRUE);
}

/****************************************************************************
*
*    FUNCTION: PrintSetupHookProc(HWND, UINT, UINT, LONG)
*
*    PURPOSE:  Processes messages for PrintDlg setup common dialog box
*
*    COMMENTS:
*
*        This function processes the hook and customized template for the
*        print setup common dialog box.  If the customized template has
*        been provided, the 'Options' pushbutton is hidden.  If the hook only mode
*        is chosen, a message box is displayed informing the user that the
*        hook has been installed.
*
*    RETURN VALUES:
*        TRUE - Continue.
*        FALSE - Return to the dialog box.
*
****************************************************************************/

BOOL APIENTRY PrintSetupHookProc(
        HWND hDlg,                /* window handle of the dialog box */
        UINT message,             /* type of message                 */
        UINT wParam,            /* message-specific information    */
        LONG lParam)
{

    switch (message)
    {
        case WM_INITDIALOG:
            if (pd.Flags & PD_ENABLESETUPTEMPLATE )
            {
                ShowWindow( GetDlgItem(hDlg, psh1), SW_HIDE );
                return(TRUE);
            }
            MessageBox( hDlg,
                    "Hook installed.",
                    "Information", MB_OK );
            return (TRUE);
    }
    return (FALSE);

    // avoid compiler warnings at W3
    lParam;
    wParam;
}



/****************************************************************************
*
*    FUNCTION: PrintDlgHookProc(HWND, UINT, UINT, LONG)
*
*    PURPOSE:  Processes messages for PrintDlg common dialog box
*
*    COMMENTS:
*
*        This hook procedure simply prompts the user whether or not they
*        want to print.  if they choose YES, the text buf will be printed
*        and the dialog will be dismissed.  If they choose NO, the text buf
*        will not be printeded and the user will be returned to the dialog.
*
*        If the current mode is 'custom', the 'Print to file' and 'Collate
*        Copies' options are hidden.
*
*    RETURN VALUES:
*        TRUE - Continue.
*        FALSE - Return to the dialog box.
*
****************************************************************************/

BOOL APIENTRY PrintDlgHookProc(
        HWND hDlg,                /* window handle of the dialog box */
        UINT message,             /* type of message                 */
        UINT wParam,            /* message-specific information    */
        LONG lParam)
{

    switch (message)
    {
        case WM_INITDIALOG:
            if (pd.Flags & PD_ENABLEPRINTTEMPLATE )
            {
                ShowWindow( GetDlgItem(hDlg, chx1), SW_HIDE );
                ShowWindow( GetDlgItem(hDlg, chx2), SW_HIDE );
                return(TRUE);
            }
            MessageBox( hDlg,
                    "Hook installed.",
                    "Information", MB_OK );
            return (TRUE);

        case WM_COMMAND:
            if (LOWORD(wParam) == IDOK)
            {
                if (MessageBox( hDlg, "Are you sure you want to print?",
                    "Information", MB_YESNO ) == IDYES )
                    break;
                return (TRUE);

            }
            break;
    }
    return (FALSE);

    // avoid compiler warnings at W3
    lParam;

}


/****************************************************************************
*
*    FUNCTION: PrintFile(HWND)
*
*    PURPOSE:  Invokes common dialog function to print.
*
*    COMMENTS:
*
*        This function initializes the PRINTDLG structure for all modes
*        possible: standard, using a hook or using a customized template.
*        When hook mode is chosen, a hook is installed for both the
*        Print dialog and the Print Setup dialog.  When custom mode is
*        chosen, the templates are enabled for both the print dialog and
*        the Print Setup dialog boxes.
*
*        If the PrintDlg() common dialog returns TRUE, the current
*        text buffer is printed out.
*
*
*    RETURN VALUES:
*        void.
*
****************************************************************************/
void PrintFile( HWND hWnd )
{


    // initialize PRINTDLG structure
    pd.lStructSize = sizeof(PRINTDLG);
    pd.hwndOwner = hWnd;
    pd.hDevMode = (HANDLE)NULL;
    pd.hDevNames = (HANDLE)NULL;
    pd.nFromPage = 0;
    pd.nToPage = 0;
    pd.nMinPage = 0;
    pd.nMaxPage = 0;
    pd.nCopies = 0;
    pd.hInstance = (HANDLE)hInst;


    switch( wMode )
    {
        case IDM_STANDARD:
            pd.Flags = PD_RETURNDC | PD_NOPAGENUMS | PD_NOSELECTION | PD_PRINTSETUP;
            pd.lpfnSetupHook = (LPSETUPHOOKPROC)(FARPROC)NULL;
            pd.lpSetupTemplateName = (LPTSTR)NULL;
            pd.lpfnPrintHook = (LPPRINTHOOKPROC)(FARPROC)NULL;
            pd.lpPrintTemplateName = (LPTSTR)NULL;
            break;

        case IDM_HOOK:
            pd.Flags = PD_RETURNDC | PD_NOPAGENUMS | PD_NOSELECTION |
                PD_ENABLEPRINTHOOK | PD_ENABLESETUPHOOK | PD_PRINTSETUP;
            pd.lpfnSetupHook = (LPSETUPHOOKPROC)PrintSetupHookProc;
            pd.lpSetupTemplateName = (LPTSTR)NULL;
            pd.lpfnPrintHook = (LPPRINTHOOKPROC)PrintDlgHookProc;
            pd.lpPrintTemplateName = (LPTSTR)NULL;
            break;

        case IDM_CUSTOM:
            pd.Flags = PD_RETURNDC | PD_NOPAGENUMS | PD_NOSELECTION |
                PD_ENABLEPRINTHOOK | PD_ENABLEPRINTTEMPLATE |
                PD_ENABLESETUPHOOK | PD_ENABLESETUPTEMPLATE | PD_PRINTSETUP;
            pd.lpfnSetupHook = (LPSETUPHOOKPROC)PrintSetupHookProc;
            pd.lpfnPrintHook = (LPPRINTHOOKPROC)PrintDlgHookProc;
           	pd.lpPrintTemplateName = (LPTSTR)MAKEINTRESOURCE(PRINTDLGORD);
           	pd.lpSetupTemplateName = (LPTSTR)MAKEINTRESOURCE(PRNSETUPDLGORD);
           break;

    }

    //print a test page if successful
    if (PrintDlg(&pd) == TRUE)
    {
        Escape(pd.hDC, STARTDOC, 8, "Test-Doc", NULL);

        //Print text
        TextOut(pd.hDC, 5, 5, FileBuf, strlen(FileBuf));

        Escape(pd.hDC, NEWFRAME, 0, NULL, NULL);
        Escape(pd.hDC, ENDDOC, 0, NULL, NULL );
        DeleteDC(pd.hDC);
        if (pd.hDevMode)
            GlobalFree(pd.hDevMode);
        if (pd.hDevNames)
            GlobalFree(pd.hDevNames);
    }
   else
        ProcessCDError(CommDlgExtendedError(), hWnd );
}

/****************************************************************************
*
*    FUNCTION: PageSetupHook(HWND, UINT, UINT, LONG)
*
*    PURPOSE:  Processes messages for PageSetupDlg common dialog box
*
*    COMMENTS:
*
*        This hook procedure simply informs the user that the hook is in place.
*
*    RETURN VALUES:
*        TRUE - Continue.
*        FALSE - Return to the dialog box.
*
****************************************************************************/

BOOL APIENTRY PageSetupHook(
        HWND hDlg,                /* window handle of the dialog box */
        UINT message,             /* type of message                 */
        UINT wParam,            /* message-specific information    */
        LONG lParam)
{

    switch (message)
    {
        case WM_INITDIALOG:
            if (psDlg.Flags & PSD_ENABLEPAGESETUPTEMPLATE )
            {
				// Hide the Options button
                ShowWindow( GetDlgItem(hDlg, psh1), SW_HIDE );
                return(TRUE);
            }
            MessageBox( hDlg,
                    "Hook installed.",
                    "Information", MB_OK );
            return (TRUE);

        case WM_COMMAND:
            if (LOWORD(wParam) == IDOK)
            {
                if (MessageBox( hDlg, "Are you done?",
                    "Information", MB_YESNO ) == IDYES )
                    break;
                return (TRUE);

            }
            break;
    }
    return (FALSE);

}
/****************************************************************************
*
*    FUNCTION: PageSetup(HWND)
*
*    PURPOSE:  Invokes Page Setup common dialog function.
*
*    COMMENTS:

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -