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

📄 cmndlg32.c

📁 THE DECISION TREE ALGORITHM USED VC
💻 C
📖 第 1 页 / 共 5 页
字号:
*
*        This function initializes the PAGESETUPDLG structure for all modes
*        possible: standard, using a hook or using a customized template.
*
*    RETURN VALUES:
*        void.
*
****************************************************************************/
void PageSetup( HWND hWnd )
{

    // initialize PAGESETUPDLG structure
    psDlg.lStructSize = sizeof(PAGESETUPDLG);
    psDlg.hwndOwner = hWnd;
    psDlg.hDevMode = (HANDLE)NULL;
    psDlg.hDevNames = (HANDLE)NULL;
    psDlg.hInstance = (HANDLE)hInst;
    psDlg.lCustData = (LPARAM)NULL;
	psDlg.hPageSetupTemplate = (HGLOBAL)NULL;

    switch( wMode )
    {
        case IDM_STANDARD:
            psDlg.Flags = PSD_DEFAULTMINMARGINS | PSD_DISABLEPAGEPAINTING |
              PSD_DISABLEPRINTER | PSD_INHUNDREDTHSOFMILLIMETERS;
            psDlg.lpfnPageSetupHook = (LPPAGESETUPHOOK)(FARPROC)NULL;
            psDlg.lpPageSetupTemplateName = (LPTSTR)NULL;
            psDlg.lpfnPagePaintHook = (LPPAGEPAINTHOOK)(FARPROC)NULL;
            break;

        case IDM_HOOK:
            psDlg.Flags = PSD_DEFAULTMINMARGINS | PSD_ENABLEPAGESETUPHOOK;
            psDlg.lpfnPageSetupHook = (LPPAGESETUPHOOK)(FARPROC)PageSetupHook;
            psDlg.lpPageSetupTemplateName = (LPTSTR)NULL;
            psDlg.lpfnPagePaintHook = (LPPAGEPAINTHOOK)(FARPROC)NULL;
            break;

        case IDM_CUSTOM:
            psDlg.Flags = PSD_DEFAULTMINMARGINS | PSD_ENABLEPAGESETUPHOOK |
            	PSD_ENABLEPAGESETUPTEMPLATE;
            psDlg.lpfnPageSetupHook = (LPPAGESETUPHOOK)(FARPROC)PageSetupHook;
            psDlg.lpPageSetupTemplateName = (LPTSTR)PRNSETUPDLGORD95;
            psDlg.lpfnPagePaintHook = (LPPAGEPAINTHOOK)(FARPROC)NULL;
           break;

    }

    // Call the Page Setup common dialog
    if (PageSetupDlg(&psDlg) == FALSE)
        ProcessCDError(CommDlgExtendedError(), hWnd );
}

/****************************************************************************
*
*    FUNCTION: ReplaceTextHookProc(HWND, UINT, UINT, LONG)
*
*    PURPOSE:  Processes messages for ReplaceText common dialog box
*
*    COMMENTS:
*
*        Puts up a message stating that the hook is active if hook
*        only active.  Otherwise, if template enabled, hides the
*        Replace All pushbutton, plus the 'Match case' and
*        'Match whole word' check box options.
*
*    RETURN VALUES:
*        TRUE - Continue.
*        FALSE - Return to the dialog box.
*
****************************************************************************/

BOOL APIENTRY ReplaceTextHookProc(
        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 (frText.Flags & FR_ENABLETEMPLATE )
                {
                    ShowWindow( GetDlgItem(hDlg, psh2), SW_HIDE );
                    ShowWindow( GetDlgItem(hDlg, chx1), SW_HIDE );
                    ShowWindow( GetDlgItem(hDlg, chx2), SW_HIDE );
                }
            MessageBox( hDlg,
                    "Hook installed.",
                    "Information", MB_OK );
            return (TRUE);


        default:
            break;
    }
    return (FALSE);

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

/****************************************************************************
*
*    FUNCTION: FindTextHookProc(HWND, UINT, UINT, LONG)
*
*    PURPOSE:  Processes messages for FindText common dialog box
*
*    COMMENTS:
*
*        Puts up a message stating that the hook is active if hook
*        only enabled.  If custom template, hides the 'Match case'
*        and 'Match whole word' options, hides the group box 'Direction'
*        with the radio buttons 'Up' and 'Down'.
*
*    RETURN VALUES:
*        TRUE - Continue.
*        FALSE - Return to the dialog box.
*
****************************************************************************/

BOOL APIENTRY FindTextHookProc(
        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 (frText.Flags & FR_ENABLETEMPLATE )
            {
                ShowWindow(GetDlgItem(hDlg, chx1), SW_HIDE);
                ShowWindow(GetDlgItem(hDlg, grp1), SW_HIDE);
                ShowWindow(GetDlgItem(hDlg, chx2), SW_HIDE);
                ShowWindow(GetDlgItem(hDlg, rad1), SW_HIDE);
                ShowWindow(GetDlgItem(hDlg, rad2), SW_HIDE);
            }
            MessageBox( hDlg,
                    "Hook installed.",
                    "Information", MB_OK );
            return (TRUE);


        default:
            break;
    }
    return (FALSE);

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


/****************************************************************************
*
*    FUNCTION: CallFindText( HWND )
*
*    PURPOSE:  Initializes and calls the FindText()
*        common dialog.
*
*    COMMENTS:
*
*        This function initialzes the FINDREPLACE structure for any mode:
*        standard, using a hook or using a customized template.  It then
*        calls the FindText() common dialog function.
*
*    RETURN VALUES:
*        void.
*
****************************************************************************/
void CallFindText( HWND hWnd )
{

    frText.lStructSize = sizeof( frText );
    frText.hwndOwner = hWnd;
    frText.hInstance = (HANDLE)hInst;
    frText.lpstrFindWhat = szFindString;
    frText.lpstrReplaceWith = (LPTSTR)NULL;
    frText.wFindWhatLen = sizeof(szFindString);
    frText.wReplaceWithLen = 0;
    frText.lCustData = 0;
    lpBufPtr = FileBuf;

    switch( wMode )
    {
        case IDM_STANDARD:
            frText.Flags =  FR_NOMATCHCASE | FR_NOUPDOWN | FR_NOWHOLEWORD;
            frText.lpfnHook = (LPFRHOOKPROC)(FARPROC)NULL;
            frText.lpTemplateName = (LPTSTR)NULL;
            break;

        case IDM_HOOK:
            frText.Flags = FR_NOMATCHCASE | FR_NOUPDOWN | FR_NOWHOLEWORD |
                FR_ENABLEHOOK;
            frText.lpfnHook = (LPFRHOOKPROC)FindTextHookProc;
            frText.lpTemplateName = (LPTSTR)NULL;
            break;

        case IDM_CUSTOM:
            frText.Flags = FR_NOMATCHCASE | FR_NOUPDOWN | FR_NOWHOLEWORD |
                 FR_ENABLEHOOK | FR_ENABLETEMPLATE;
            frText.lpfnHook = (LPFRHOOKPROC)FindTextHookProc;
           	frText.lpTemplateName = (LPTSTR)MAKEINTRESOURCE(FINDDLGORD);
            break;
    }

    if ((hDlgFR = FindText(&frText)) == NULL)
        ProcessCDError(CommDlgExtendedError(), hWnd );

}


/****************************************************************************
*
*    FUNCTION: CallReplaceText( HWND )
*
*    PURPOSE:  Initializes and calls the ReplaceText()
*        common dialog.
*
*    COMMENTS:
*
*        This function initialzes the FINDREPLACE structure for any mode:
*        standard, using a hook or using a customized template.  It then
*        calls the ReplaceText() common dialog function.
*
*    RETURN VALUES:
*        void.
*
****************************************************************************/
void CallReplaceText( HWND hWnd )
{
    frText.lStructSize = sizeof( frText );
    frText.hwndOwner = hWnd;
    frText.hInstance = (HANDLE)hInst;
    frText.lpstrFindWhat = szFindString;
    frText.lpstrReplaceWith = szReplaceString;
    frText.wFindWhatLen = sizeof(szFindString);
    frText.wReplaceWithLen = sizeof( szReplaceString );
    frText.lCustData = 0;
    lpBufPtr = FileBuf;

    switch( wMode )
    {
        case IDM_STANDARD:
            frText.Flags = FR_NOMATCHCASE | FR_NOUPDOWN | FR_NOWHOLEWORD;
            frText.lpfnHook = (LPFRHOOKPROC)(FARPROC)NULL;
            frText.lpTemplateName = (LPTSTR)NULL;
            break;

        case IDM_HOOK:
            frText.Flags = FR_NOMATCHCASE | FR_NOUPDOWN | FR_NOWHOLEWORD |
                FR_ENABLEHOOK;
            frText.lpfnHook = (LPFRHOOKPROC)ReplaceTextHookProc;
            frText.lpTemplateName = (LPTSTR)NULL;
            break;

        case IDM_CUSTOM:
            frText.Flags = FR_NOMATCHCASE | FR_NOUPDOWN | FR_NOWHOLEWORD |
                FR_ENABLEHOOK | FR_ENABLETEMPLATE;
            frText.lpfnHook = (LPFRHOOKPROC)ReplaceTextHookProc;
           	frText.lpTemplateName = (LPTSTR)MAKEINTRESOURCE(REPLACEDLGORD);
            break;
    }

    if ( (hDlgFR = ReplaceText( &frText )) == NULL )
            ProcessCDError(CommDlgExtendedError(), hWnd );

}

/****************************************************************************
*
*    FUNCTION: SearchFile(LPFINDREPLACE)
*
*    PURPOSE:  Does the find/replace specified by the Find/ReplaceText
*        common dialog.
*
*    COMMENTS:
*
*        This function does the least necessary to implement find and
*        replace by calling existing c-runtime functions.  It is in
*        no way intended to demonstrate either correct or efficient
*        methods for doing textual search or replacement.
*
*    RETURN VALUES:
*        void.
*
****************************************************************************/
void SearchFile( LPFINDREPLACE lpFR )
{

    TCHAR Buf[FILE_LEN];
    TCHAR *pStr;
    int count, newcount;
    static BOOL bFoundLast = FALSE;
    
   if ( lpFR->Flags & ( FR_FINDNEXT | FR_REPLACE | FR_REPLACEALL ) )
   {
      if ( bFoundLast )
      {
         if ( (lpBufPtr != FileBuf) && (lpFR->Flags & FR_FINDNEXT) )
            lpBufPtr++;
         bFoundLast = FALSE;
      }

      if (!*lpBufPtr || !(pStr = strstr( lpBufPtr, lpFR->lpstrFindWhat ) ) )
      {
         lpBufPtr = FileBuf;
         MessageBox( lpFR->hwndOwner, lpFR->lpstrFindWhat, TEXT("String not found"), MB_OK );
      }
      else
      {
         if ( lpFR->Flags & FR_FINDNEXT )
         {
            lpBufPtr = pStr;
            bFoundLast = TRUE;
            MessageBox( lpFR->hwndOwner, lpFR->lpstrFindWhat, TEXT("String found!"), MB_OK );
         }
         else if ( lpFR->Flags & FR_REPLACE )
         {
            // replace string specified in the replace with found string
            // copy up to found string into new buffer
            for( count=0; 
               *pStr && lpBufPtr[count] && *pStr != lpBufPtr[count]; 
               count++);
            strncpy( Buf, lpBufPtr, count );
            // concatenate new string
            strcat( Buf, lpFR->lpstrReplaceWith );
            // copy rest of string (less the found string)
            newcount = count + strlen(lpFR->lpstrFindWhat);
            strcat( Buf, lpBufPtr+newcount);
            strcpy( lpBufPtr, Buf );
            lpBufPtr += count + strlen(lpFR->lpstrReplaceWith);
            dwFileSize = strlen(FileBuf);
            MessageBox( lpFR->hwndOwner, FileBuf, "Success!", MB_OK );
         }
         else if ( lpFR->Flags & FR_REPLACEALL)
         {
            do
            {
                // replace string specified in the replace with found string
                // copy up to found string into new buffer
                for( count=0; 
                     *pStr && lpBufPtr[count] && *pStr != lpBufPtr[count]; 
                     count++);
                strncpy( Buf, lpBufPtr, count);
                // concatenate new string
                strcat( Buf, lpFR->lpstrReplaceWith );
                // copy rest of string (less the found string)
                newcount = count + strlen(lpFR->lpstrFindWhat);
                strcat( Buf, lpBufPtr + newcount);
                strcpy( lpBufPtr, Buf );
                lpBufPtr += count + strlen(lpFR->lpstrReplaceWith);
            }
            while ( *lpBufPtr && 
                    (pStr = strstr( lpBufPtr, lpFR->lpstrFindWhat ) ) );
            dwFileSize = strlen(FileBuf);
            lpBufPtr = FileBuf;
            MessageBox( lpFR->hwndOwner, FileBuf, 
                        "Success!", MB_OK );
         }
      }
   }
}


/****************************************************************************
*
*    FUNCTION: ProcessCDError(DWORD)
*
*    PURPOSE:  Processes errors from the common dialog functions.
*
*    COMMENTS:
*
*        This function is called whenever a common dialog function
*        fails.  The CommonDialogExtendedError() value is passed to
*        the function which maps the error value to a string table.
*        The string is loaded and displayed for the user.
*
*    RETURN VALUES:
*        void.
*
****************************************************************************/
void ProcessCDError(DWORD dwErrorCode, HWND hWnd)
{
   WORD  wStringID;
   TCHAR  buf[256];

   switch(dwErrorCode)
      {
         case CDERR_DIALOGFAILURE:   wStringID=IDS_DIALOGFAI

⌨️ 快捷键说明

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