Annotation of mstools/mfc/src/windlgs.cpp, revision 1.1.1.1

1.1       root        1: // This is a part of the Microsoft Foundation Classes C++ library. 
                      2: // Copyright (C) 1992 Microsoft Corporation 
                      3: // All rights reserved. 
                      4: //  
                      5: // This source code is only intended as a supplement to the 
                      6: // Microsoft Foundation Classes Reference and Microsoft 
                      7: // QuickHelp documentation provided with the library. 
                      8: // See these sources for detailed information regarding the 
                      9: // Microsoft Foundation Classes product. 
                     10: 
                     11: 
                     12: #include "afxwin.h"
                     13: #pragma hdrstop
                     14: 
                     15: #include "afxdlgs.h"    // standard AFX dialogs
                     16: 
                     17: #include "stddef.h"     // for offsetof macro
                     18: #include "window_.h"    // for hooks and other internals 
                     19: #include "dlgs.h"       // for standard control IDs for commdlg
                     20: 
                     21: #ifdef AFX_CORE_SEG
                     22: #pragma code_seg(AFX_AUX_SEG)
                     23: #endif
                     24: 
                     25: #ifdef _DEBUG
                     26: #undef THIS_FILE
                     27: static char BASED_CODE THIS_FILE[] = __FILE__;
                     28: #define new DEBUG_NEW
                     29: #endif
                     30: 
                     31: static char BASED_CODE szLBSELCH[] = LBSELCHSTRING;
                     32: static char BASED_CODE szSHAREVI[] = SHAREVISTRING;
                     33: static char BASED_CODE szFILEOK[] = FILEOKSTRING;
                     34: static char BASED_CODE szCOLOROK[] = COLOROKSTRING;
                     35: static char BASED_CODE szSETRGB[] = SETRGBSTRING;
                     36: 
                     37: static UINT nMsgLBSELCHANGE = ::RegisterWindowMessage(szLBSELCH);
                     38: static UINT nMsgSHAREVI = ::RegisterWindowMessage(szSHAREVI);
                     39: static UINT nMsgFILEOK = ::RegisterWindowMessage(szFILEOK);
                     40: static UINT nMsgCOLOROK = ::RegisterWindowMessage(szCOLOROK);
                     41: static UINT nMsgSETRGB = ::RegisterWindowMessage(szSETRGB);
                     42: 
                     43: typedef UINT (FAR PASCAL* COMMDLGPROC)(HWND, UINT, UINT, LONG);
                     44: 
                     45: UINT FAR PASCAL AFX_EXPORT
                     46: _AfxCommDlgProc(HWND hWnd, register UINT message, UINT wParam, LONG lParam)
                     47: {
                     48:        if (message == WM_SETFONT || message == WM_INITDIALOG)
                     49:                return (UINT)_AfxDlgProc(hWnd, message, wParam, lParam);
                     50: 
                     51:        if (message < 0xC000)
                     52:                // not a ::RegisterWindowMessage message
                     53:                return 0;
                     54: 
                     55:        // RegisterWindowMessage - does not copy to lastState buffer, so
                     56:        // CWnd::GetCurrentMessage and CWnd::Default will NOT work
                     57:        // while in these handlers
                     58: 
                     59:        // Get our Window
                     60:        // assume it is already wired up to a permanent one
                     61:        CDialog* pDlg = (CDialog*) CWnd::FromHandlePermanent(hWnd);
                     62:        ASSERT(pDlg != NULL);
                     63:        ASSERT(pDlg->m_hWnd == hWnd);
                     64:        ASSERT(pDlg->IsKindOf(RUNTIME_CLASS(CDialog)));
                     65: 
                     66:        // Dispatch special commdlg messages through our virtual callbacks
                     67:        if (message == nMsgSHAREVI)
                     68:        {
                     69:                ASSERT(pDlg->IsKindOf(RUNTIME_CLASS(CFileDialog)));
                     70:                return ((CFileDialog*)pDlg)->OnShareViolation((LPCSTR)lParam);
                     71:        }
                     72:        else if (message == nMsgFILEOK)
                     73:        {
                     74:                ASSERT(pDlg->IsKindOf(RUNTIME_CLASS(CFileDialog)));
                     75:                return ((CFileDialog*)pDlg)->OnFileNameOK();
                     76:        }
                     77:        else if (message == nMsgLBSELCHANGE)
                     78:        {
                     79:                ASSERT(pDlg->IsKindOf(RUNTIME_CLASS(CFileDialog)));
                     80:                ((CFileDialog*)pDlg)->OnLBSelChangedNotify(wParam, LOWORD(lParam), 
                     81:                                HIWORD(lParam));
                     82:                return 0;
                     83:        }
                     84:        else if (message == nMsgCOLOROK)
                     85:        {
                     86:                ASSERT(pDlg->IsKindOf(RUNTIME_CLASS(CColorDialog)));
                     87:                return ((CColorDialog*)pDlg)->OnColorOK();
                     88:        }
                     89:        else if (message == nMsgSETRGB)
                     90:        {
                     91:                // nothing to do here, since this is a SendMessage
                     92:                return 0;
                     93:        }
                     94: 
                     95:        TRACE("_AfxCommDlgProc: received unknown user message, returning 0\n");
                     96:        return 0;
                     97: }
                     98: 
                     99: ////////////////////////////////////////////////////////////////////////////
                    100: // FileOpen/FileSaveAs common dialog helper
                    101: 
                    102: IMPLEMENT_DYNAMIC(CFileDialog, CModalDialog)
                    103: 
                    104: CFileDialog::CFileDialog(BOOL bOpenFileDialog,
                    105:                LPCSTR lpszDefExt /* = NULL */,
                    106:                LPCSTR lpszFileName /* = NULL */,
                    107:                DWORD dwFlags /* = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT */,
                    108:                LPCSTR lpszFilter /* = NULL */, 
                    109:                CWnd* pParentWnd /* = NULL */) : CModalDialog((UINT)0, pParentWnd)
                    110: {
                    111:        memset(&m_ofn, 0, sizeof(m_ofn)); // initialize structure to 0/NULL
                    112:        m_szFileName[0] = '\0';
                    113:        m_szFileTitle[0] = '\0';
                    114: 
                    115:        m_bOpenFileDialog = bOpenFileDialog;
                    116:        
                    117:        m_ofn.lStructSize = sizeof(m_ofn);
                    118: 
                    119:        if (m_pParentWnd != NULL)
                    120:                m_ofn.hwndOwner = m_pParentWnd->m_hWnd;
                    121:        else
                    122:                m_ofn.hwndOwner = AfxGetApp()->m_pMainWnd->GetSafeHwnd();
                    123:        m_ofn.lpstrFile = (LPSTR)&m_szFileName;
                    124:        m_ofn.nMaxFile = sizeof(m_szFileName);
                    125:        m_ofn.lpstrDefExt = lpszDefExt; 
                    126:        m_ofn.lpstrFileTitle = (LPSTR)m_szFileTitle;
                    127:        m_ofn.nMaxFileTitle = sizeof(m_szFileTitle);
                    128: 
                    129:        m_ofn.Flags |= dwFlags | OFN_ENABLEHOOK;
                    130:        m_ofn.lpfnHook = (COMMDLGPROC)_AfxCommDlgProc;
                    131: 
                    132:        // setup initial file name
                    133:        if (lpszFileName)
                    134:        {
                    135:                _fstrncpy(m_szFileName, lpszFileName, sizeof(m_szFileName));
                    136:                m_szFileName[sizeof(m_szFileName)-1] = '\0';
                    137:        }
                    138: 
                    139:        // Translate filter into commdlg format (lots of \0)
                    140:        if (lpszFilter)
                    141:        {
                    142:                int nLen = _fstrlen(lpszFilter);
                    143: 
                    144:                m_strFilter.GetBuffer(_fstrlen(lpszFilter)); // required because of '\0'
                    145:                while (*lpszFilter)
                    146:                {
                    147:                        if (*lpszFilter == '|') // MFC delimits with ':' not '\0'
                    148:                                m_strFilter += (char)'\0';
                    149:                        else
                    150:                                m_strFilter += *lpszFilter;
                    151:                        lpszFilter++;
                    152:                }
                    153:                m_ofn.lpstrFilter = m_strFilter;
                    154:                m_strFilter.ReleaseBuffer(nLen);
                    155:        }
                    156: }
                    157: 
                    158: int
                    159: CFileDialog::DoModal()
                    160: {
                    161:        ASSERT_VALID(this);
                    162:        ASSERT(m_ofn.Flags & OFN_ENABLEHOOK);
                    163:        ASSERT(m_ofn.lpfnHook != NULL); // can still be a user hook
                    164: 
                    165:        BOOL bResult;
                    166: 
                    167:        _AfxHookWindowCreate(this);
                    168: 
                    169:        if (m_bOpenFileDialog)
                    170:                bResult = ::GetOpenFileName(&m_ofn);
                    171:        else
                    172:                bResult = ::GetSaveFileName(&m_ofn);
                    173: 
                    174:        _AfxUnhookWindowCreate();   // just in case
                    175:        Detach();                   // just in case
                    176: 
                    177:        return bResult ? IDOK : IDCANCEL;
                    178: }
                    179: 
                    180: CString CFileDialog::GetFileName() const
                    181: { 
                    182:        ASSERT_VALID(this);
                    183:        char szFile[32];
                    184: 
                    185:        if (m_ofn.nFileExtension == 0 || 
                    186:                        m_ofn.lpstrFile[m_ofn.nFileExtension] == '\0')
                    187:                return m_ofn.lpstrFile + m_ofn.nFileOffset;
                    188:        else
                    189:        {
                    190:                int nFileLen = m_ofn.nFileExtension - m_ofn.nFileOffset - 1;
                    191:                _fstrncpy(szFile, m_ofn.lpstrFile + m_ofn.nFileOffset, nFileLen);
                    192:                szFile[nFileLen] = '\0';
                    193:                return szFile;
                    194:        }
                    195: }
                    196: 
                    197: UINT 
                    198: CFileDialog::OnShareViolation(LPCSTR)
                    199: {
                    200:        ASSERT_VALID(this);
                    201: 
                    202:        // Do not call Default() if you override
                    203:        return OFN_SHAREWARN; // default
                    204: }
                    205: 
                    206: BOOL 
                    207: CFileDialog::OnFileNameOK()
                    208: {
                    209:        ASSERT_VALID(this);
                    210: 
                    211:        // Do not call Default() if you override
                    212:        return FALSE;
                    213: }
                    214: 
                    215: void 
                    216: CFileDialog::OnLBSelChangedNotify(UINT, UINT, UINT)
                    217: {
                    218:        ASSERT_VALID(this);
                    219: 
                    220:        // Do not call Default() if you override
                    221:        // no default processing needed
                    222: }
                    223: 
                    224: void
                    225: CFileDialog::OnOK()
                    226: {
                    227:        // Common dialogs do not require ::EndDialog
                    228:        ASSERT_VALID(this);
                    229:        Default();
                    230: }
                    231: 
                    232: void
                    233: CFileDialog::OnCancel()
                    234: {
                    235:        // Common dialogs do not require ::EndDialog
                    236:        ASSERT_VALID(this);
                    237:        Default();
                    238: }
                    239: 
                    240: #ifdef _DEBUG
                    241: void 
                    242: CFileDialog::Dump(CDumpContext& dc) const
                    243: {
                    244:        ASSERT_VALID(this);
                    245: 
                    246:        CModalDialog::Dump(dc);
                    247: 
                    248:        if (m_bOpenFileDialog)
                    249:                dc << "\nFile open dialog";
                    250:        else
                    251:                dc << "\nFile save dialog";
                    252:        dc << "\nm_ofn.hwndOwner = " << (void NEAR*)m_ofn.hwndOwner;
                    253:        dc << "\nm_ofn.nFilterIndex = " << m_ofn.nFilterIndex;
                    254:        dc << "\nm_ofn.lpstrFile = " << m_ofn.lpstrFile;
                    255:        dc << "\nm_ofn.nMaxFile = " << m_ofn.nMaxFile;
                    256:        dc << "\nm_ofn.lpstrFileTitle = " << m_ofn.lpstrFileTitle;
                    257:        dc << "\nm_ofn.nMaxFileTitle = " << m_ofn.nMaxFileTitle;
                    258:        dc << "\nm_ofn.lpstrTitle = " << m_ofn.lpstrTitle;
                    259:        dc << "\nm_ofn.Flags = " << (LPVOID)m_ofn.Flags;
                    260:        dc << "\nm_ofn.lpstrDefExt = " << m_ofn.lpstrDefExt;
                    261:        dc << "\nm_ofn.nFileOffset = " << m_ofn.nFileOffset;
                    262:        dc << "\nm_ofn.nFileExtension = " << m_ofn.nFileExtension;
                    263: 
                    264:        dc << "\nm_ofn.lpstrFilter = ";
                    265:        LPCSTR lpstrItem = m_ofn.lpstrFilter;
                    266:        char* szBreak = "|";
                    267: 
                    268:        while (lpstrItem != NULL && *lpstrItem != '\0')
                    269:        {
                    270:                dc << lpstrItem << szBreak;
                    271:                lpstrItem += _fstrlen(lpstrItem) + 1;
                    272:        }
                    273:        if (lpstrItem != NULL)
                    274:                dc << szBreak;
                    275: 
                    276:        dc << "\nm_ofn.lpstrCustomFilter = ";
                    277:        lpstrItem = m_ofn.lpstrCustomFilter;
                    278:        while (lpstrItem != NULL && *lpstrItem != '\0')
                    279:        {
                    280:                dc << lpstrItem << szBreak;
                    281:                lpstrItem += _fstrlen(lpstrItem) + 1;
                    282:        }
                    283:        if (lpstrItem != NULL)
                    284:                dc << szBreak;
                    285:        
                    286:        if (m_ofn.lpfnHook == (COMMDLGPROC)_AfxCommDlgProc)
                    287:                dc << "\nhook function set to standard MFC hook function";
                    288:        else
                    289:                dc << "\nhook function set to non-standard hook function";
                    290: }
                    291: #endif
                    292: 
                    293: 
                    294: /////////////////////////////////////////////////////////////////////////////
                    295: // Choose Color dialog
                    296: 
                    297: IMPLEMENT_DYNAMIC(CColorDialog, CModalDialog)
                    298: 
                    299: COLORREF CColorDialog::clrSavedCustom[16] = { RGB(255, 255, 255), 
                    300:        RGB(255, 255, 255), RGB(255, 255, 255), RGB(255, 255, 255),
                    301:        RGB(255, 255, 255), RGB(255, 255, 255), RGB(255, 255, 255),
                    302:        RGB(255, 255, 255), RGB(255, 255, 255), RGB(255, 255, 255),
                    303:        RGB(255, 255, 255), RGB(255, 255, 255), RGB(255, 255, 255),
                    304:        RGB(255, 255, 255), RGB(255, 255, 255), RGB(255, 255, 255) };
                    305: 
                    306: CColorDialog::CColorDialog(COLORREF clrInit /* = 0 */,
                    307:                DWORD dwFlags /* = 0 */, 
                    308:                CWnd* pParentWnd /* = NULL */) : CModalDialog((UINT)0, pParentWnd)
                    309: {
                    310:        memset(&m_cc, 0, sizeof(m_cc));
                    311: 
                    312:        m_cc.lStructSize = sizeof(m_cc);
                    313:        if (m_pParentWnd != NULL)
                    314:                m_cc.hwndOwner = m_pParentWnd->m_hWnd;
                    315:        else
                    316:                m_cc.hwndOwner = AfxGetApp()->m_pMainWnd->GetSafeHwnd();
                    317:        m_cc.lpCustColors = (COLORREF FAR*)&clrSavedCustom;
                    318:        m_cc.Flags = dwFlags | CC_ENABLEHOOK;
                    319:        m_cc.lpfnHook = (COMMDLGPROC)_AfxCommDlgProc;
                    320: 
                    321:        if ((m_cc.rgbResult = clrInit) != 0)
                    322:                m_cc.Flags |= CC_RGBINIT;
                    323: 
                    324:        // There is a "bug" in the Windows 3.1 COMMDLG implementation
                    325:        // of ::ChooseColor that prevents the "new AFX look" from
                    326:        // functioning correctly.  If you wish to disable the default
                    327:        // AFX look, then ::DeleteObject(m_hBrushCtlBk) and set it
                    328:        // to NULL at this point.
                    329: }
                    330: 
                    331: int
                    332: CColorDialog::DoModal()
                    333: {
                    334:        ASSERT_VALID(this);
                    335:        ASSERT(m_cc.Flags & CC_ENABLEHOOK);
                    336:        ASSERT(m_cc.lpfnHook != NULL); // can still be a user hook
                    337: 
                    338:        BOOL bResult;
                    339: 
                    340:        _AfxHookWindowCreate(this);
                    341: 
                    342:        bResult = ::ChooseColor(&m_cc);
                    343: 
                    344:        _AfxUnhookWindowCreate();   // just in case
                    345:        Detach();                   // just in case
                    346: 
                    347:        return bResult ? IDOK : IDCANCEL;
                    348: }
                    349: 
                    350: BOOL 
                    351: CColorDialog::OnColorOK()
                    352: {
                    353:        ASSERT_VALID(this);
                    354:        // Do not call Default() if you override
                    355:        return FALSE;
                    356: }
                    357: 
                    358: void 
                    359: CColorDialog::SetCurrentColor(COLORREF clr)
                    360: {
                    361:        ASSERT_VALID(this);
                    362:        ASSERT(m_hWnd != NULL);
                    363: 
                    364:        SendMessage(nMsgSETRGB, 0, (DWORD)clr);
                    365: }
                    366: 
                    367: void
                    368: CColorDialog::OnOK()
                    369: {
                    370:        // Common dialogs do not require ::EndDialog
                    371:        ASSERT_VALID(this);
                    372: 
                    373:        Default();
                    374: }
                    375: 
                    376: void
                    377: CColorDialog::OnCancel()
                    378: {
                    379:        // Common dialogs do not require ::EndDialog
                    380:        ASSERT_VALID(this);
                    381:        Default();
                    382: }
                    383: 
                    384: #ifdef _DEBUG
                    385: void 
                    386: CColorDialog::Dump(CDumpContext& dc) const
                    387: {
                    388:        ASSERT_VALID(this);
                    389:        CModalDialog::Dump(dc);
                    390:        
                    391:        dc << "\nm_cc.hwndOwner = " << (void NEAR*)m_cc.hwndOwner;
                    392:        dc << "\nm_cc.rgbResult = " << (LPVOID)m_cc.rgbResult;
                    393:        dc << "\nm_cc.Flags = " << (LPVOID)m_cc.Flags;
                    394:        dc << "\nm_cc.lpCustColors ";
                    395:        for (int iClr = 0; iClr < 16; iClr++)
                    396:                dc << "\n\t" << (LPVOID)m_cc.lpCustColors[iClr];
                    397:        if (m_cc.lpfnHook == (COMMDLGPROC)_AfxCommDlgProc)
                    398:                dc << "\nhook function set to standard MFC hook function";
                    399:        else
                    400:                dc << "\nhook function set to non-standard hook function";
                    401: }
                    402: #endif
                    403: 
                    404: /////////////////////////////////////////////////////////////////////////////
                    405: // Choose Font dialog
                    406: 
                    407: IMPLEMENT_DYNAMIC(CFontDialog, CModalDialog)
                    408: 
                    409: CFontDialog::CFontDialog(LPLOGFONT lplfInitial  /* = NULL */,
                    410:                DWORD dwFlags /* = CF_EFFECTS | CF_SCREENFONTS */, 
                    411:                CDC* pdcPrinter /* = NULL */,
                    412:                CWnd* pParentWnd /* = NULL */) : CModalDialog((UINT)0, pParentWnd)
                    413: {
                    414:        memset(&m_cf, 0, sizeof(m_cf));
                    415:        memset(&m_lf, 0, sizeof(m_lf));
                    416:        memset(&m_szStyleName, 0, sizeof(m_szStyleName));
                    417: 
                    418:        m_cf.lStructSize = sizeof(m_cf);
                    419:        if (m_pParentWnd != NULL)
                    420:                m_cf.hwndOwner = m_pParentWnd->m_hWnd;
                    421:        else
                    422:                m_cf.hwndOwner = AfxGetApp()->m_pMainWnd->GetSafeHwnd();
                    423:        m_cf.lpszStyle = (LPSTR)&m_szStyleName;
                    424:        m_cf.Flags = dwFlags | CF_USESTYLE | CF_ENABLEHOOK;
                    425:        m_cf.lpfnHook = (COMMDLGPROC)_AfxCommDlgProc;
                    426: 
                    427:        if (lplfInitial)
                    428:        {
                    429:                m_cf.lpLogFont = lplfInitial;
                    430:                m_cf.Flags |= CF_INITTOLOGFONTSTRUCT;
                    431:                _fmemcpy(&m_lf, m_cf.lpLogFont, sizeof(m_lf));
                    432:        }
                    433:        else
                    434:        {
                    435:                m_cf.lpLogFont = &m_lf;
                    436:        }
                    437: 
                    438:        if (pdcPrinter)
                    439:        {
                    440:                ASSERT(pdcPrinter->m_hDC != NULL);
                    441:                m_cf.hDC = pdcPrinter->m_hDC;
                    442:                m_cf.Flags |= CF_PRINTERFONTS;
                    443:        }
                    444: }
                    445: 
                    446: BOOL 
                    447: CFontDialog::DoModal()
                    448: {
                    449:        ASSERT_VALID(this);
                    450:        ASSERT(m_cf.Flags & CF_ENABLEHOOK);
                    451:        ASSERT(m_cf.lpfnHook != NULL); // can still be a user hook
                    452: 
                    453:        BOOL bResult;
                    454: 
                    455:        _AfxHookWindowCreate(this);
                    456: 
                    457:        bResult = ::ChooseFont(&m_cf);
                    458: 
                    459:        _AfxUnhookWindowCreate();   // just in case
                    460:        Detach();                   // just in case
                    461: 
                    462:        if (bResult)
                    463:                // copy logical font from user's initialization buffer (if needed)
                    464:                _fmemcpy(&m_lf, m_cf.lpLogFont, sizeof(m_lf));
                    465:                
                    466:        return bResult ? IDOK : IDCANCEL;
                    467: }
                    468: 
                    469: 
                    470: void
                    471: CFontDialog::OnOK()
                    472: {
                    473:        // Common dialogs do not require ::EndDialog
                    474:        ASSERT_VALID(this);
                    475:        Default();
                    476: }
                    477: 
                    478: void
                    479: CFontDialog::OnCancel()
                    480: {
                    481:        // Common dialogs do not require ::EndDialog
                    482:        ASSERT_VALID(this);
                    483:        Default();
                    484: }
                    485: 
                    486: #ifdef _DEBUG
                    487: void 
                    488: CFontDialog::Dump(CDumpContext& dc) const
                    489: {
                    490:        ASSERT_VALID(this);
                    491: 
                    492:        CModalDialog::Dump(dc);
                    493:        dc << "\nm_cf.hwndOwner = " << (void NEAR*)m_cf.hwndOwner;
                    494:        if (m_cf.hDC != NULL)
                    495:                dc << "\nm_cf.hDC = " << CDC::FromHandle(m_cf.hDC);
                    496:        dc << "\nm_cf.iPointSize = " << m_cf.iPointSize;
                    497:        dc << "\nm_cf.Flags = " << (LPVOID)m_cf.Flags;
                    498:        dc << "\nm_cf.lpszStyle = " << m_cf.lpszStyle;
                    499:        dc << "\nm_cf.nSizeMin = " << m_cf.nSizeMin;
                    500:        dc << "\nm_cf.nSizeMax = " << m_cf.nSizeMax;
                    501:        dc << "\nm_cf.nFontType = " << (void NEAR*)m_cf.nFontType;
                    502:        dc << "\nm_cf.rgbColors = " << (LPVOID)m_cf.rgbColors;
                    503:        if (m_cf.lpfnHook == (COMMDLGPROC)_AfxCommDlgProc)
                    504:                dc << "\nhook function set to standard MFC hook function";
                    505:        else
                    506:                dc << "\nhook function set to non-standard hook function";
                    507: }
                    508: 
                    509: #endif
                    510: 
                    511: /////////////////////////////////////////////////////////////////////////////
                    512: // Print/Print Setup dialog
                    513: 
                    514: IMPLEMENT_DYNAMIC(CPrintDialog, CModalDialog)
                    515: 
                    516: BEGIN_MESSAGE_MAP(CPrintDialog, CModalDialog)
                    517:        // Handle the print setup button when print is displayed
                    518:        ON_COMMAND(psh1, OnPrintSetup)
                    519: END_MESSAGE_MAP()
                    520: 
                    521: CPrintDialog::CPrintDialog(BOOL bPrintSetupOnly,
                    522:        DWORD dwFlags /* = PD_ALLPAGES | PD_USEDEVMODECOPIES | PD_NOPAGENUMS
                    523:                | PD_HIDEPRINTTOFILE | PD_NOSELECTION */,
                    524:        CWnd* pParentWnd /* = NULL */) 
                    525:                : m_pd(m_pdActual), CModalDialog((UINT)0, pParentWnd)
                    526: {
                    527:        memset(&m_pdActual, 0, sizeof(m_pdActual));
                    528: 
                    529:        m_pd.lStructSize = sizeof(m_pdActual);
                    530:        if (m_pParentWnd != NULL)
                    531:                m_pd.hwndOwner = m_pParentWnd->m_hWnd;
                    532:        else
                    533:                m_pd.hwndOwner = AfxGetApp()->m_pMainWnd->GetSafeHwnd();
                    534:        m_pd.Flags = (dwFlags | PD_ENABLEPRINTHOOK | PD_ENABLESETUPHOOK);
                    535:        m_pd.lpfnPrintHook = (COMMDLGPROC)_AfxCommDlgProc;
                    536:        m_pd.lpfnSetupHook = (COMMDLGPROC)_AfxCommDlgProc;
                    537:                
                    538: 
                    539:        if (bPrintSetupOnly)
                    540:                m_pd.Flags |= PD_PRINTSETUP;
                    541:        else
                    542:                m_pd.Flags |= PD_RETURNDC;
                    543: 
                    544:        m_pd.Flags &= ~PD_RETURNIC; // do not support information context
                    545: }
                    546: 
                    547: // Helper ctor for AttachOnSetup
                    548: CPrintDialog::CPrintDialog(PRINTDLG FAR& pdInit)
                    549:                : m_pd(pdInit), CModalDialog((UINT)0, NULL)
                    550: {   
                    551: }
                    552: 
                    553: // Function to keep m_pd in sync after user invokes Setup from
                    554: // the print dialog (via the Setup button)
                    555: // If you decide to handle any messages/notifications and wish to
                    556: // handle them differently between Print/PrintSetup then override
                    557: // this function and create an object of a derived class
                    558: CPrintDialog* 
                    559: CPrintDialog::AttachOnSetup()
                    560: {
                    561:        ASSERT_VALID(this);
                    562: 
                    563:        CPrintDialog* pDlgSetup;
                    564: 
                    565:        pDlgSetup = new CPrintDialog(m_pd);
                    566:        pDlgSetup->m_hWnd = NULL;
                    567:        pDlgSetup->m_pParentWnd = m_pParentWnd;
                    568:        return pDlgSetup;
                    569: }
                    570: 
                    571: void
                    572: CPrintDialog::OnPrintSetup()
                    573: {
                    574:        ASSERT_VALID(this);
                    575: 
                    576:        CPrintDialog* pDlgSetup;
                    577: 
                    578:        VERIFY((pDlgSetup = this->AttachOnSetup()) != NULL);
                    579: 
                    580:        _AfxHookWindowCreate(pDlgSetup);
                    581:        Default();
                    582:        _AfxUnhookWindowCreate();
                    583: 
                    584:        delete pDlgSetup;
                    585: }
                    586: 
                    587: int
                    588: CPrintDialog::DoModal()
                    589: {
                    590:        ASSERT_VALID(this);
                    591:        ASSERT(m_pd.Flags & PD_ENABLEPRINTHOOK);
                    592:        ASSERT(m_pd.Flags & PD_ENABLESETUPHOOK);
                    593:        ASSERT(m_pd.lpfnPrintHook != NULL); // can still be a user hook
                    594:        ASSERT(m_pd.lpfnSetupHook != NULL); // can still be a user hook
                    595: 
                    596:        BOOL bResult;
                    597: 
                    598:        _AfxHookWindowCreate(this);
                    599: 
                    600:        bResult = ::PrintDlg(&m_pd);
                    601: 
                    602:        _AfxUnhookWindowCreate();   // just in case
                    603:        Detach();                   // just in case
                    604: 
                    605:        return bResult ? IDOK : IDCANCEL;
                    606: }
                    607: 
                    608: // Return an HDC.  We don't return a CDC* so the user can decide
                    609: // where to attach this HDC: either to a newly allocated object
                    610: // (use operator delete to clean up) or to an embedded/frame
                    611: // object (destructor will clean up when leaving scope)
                    612: HDC
                    613: CPrintDialog::GetPrinterDC() const
                    614: {
                    615:        ASSERT_VALID(this);
                    616:        ASSERT(m_pd.Flags & PD_RETURNDC);
                    617:        
                    618:        return m_pd.hDC;
                    619: }
                    620: 
                    621: int 
                    622: CPrintDialog::GetCopies() const
                    623: {   
                    624:        ASSERT_VALID(this);
                    625:        if (m_pd.Flags & PD_USEDEVMODECOPIES)
                    626:                return GetDevMode()->dmCopies;
                    627:        else
                    628:                return m_pd.nCopies; 
                    629: }
                    630: 
                    631: void
                    632: CPrintDialog::OnOK()
                    633: {
                    634:        // Common dialogs do not require ::EndDialog
                    635:        ASSERT_VALID(this);
                    636:        Default();
                    637: }
                    638: 
                    639: void
                    640: CPrintDialog::OnCancel()
                    641: {
                    642:        // Common dialogs do not require ::EndDialog
                    643:        ASSERT_VALID(this);
                    644:        Default();
                    645: }
                    646: 
                    647: #ifdef _DEBUG
                    648: void 
                    649: CPrintDialog::Dump(CDumpContext& dc) const
                    650: {
                    651:        ASSERT_VALID(this);
                    652:        CModalDialog::Dump(dc);
                    653: 
                    654:        dc << "\nm_pd.hwndOwner = " << (void NEAR*)m_pd.hwndOwner;
                    655:        if (m_pd.hDC != NULL)
                    656:                dc << "\nm_pd.hDC = " << CDC::FromHandle(m_pd.hDC);
                    657:        dc << "\nm_pd.Flags = " << (LPVOID)m_pd.Flags;
                    658:        dc << "\nm_pd.nFromPage = " << m_pd.nFromPage;
                    659:        dc << "\nm_pd.nToPage = " << m_pd.nToPage;
                    660:        dc << "\nm_pd.nMinPage = " << m_pd.nMinPage;
                    661:        dc << "\nm_pd.nMaxPage = " << m_pd.nMaxPage;
                    662:        dc << "\nm_pd.nCopies = " << m_pd.nCopies;
                    663:        if (m_pd.lpfnSetupHook == (COMMDLGPROC)_AfxCommDlgProc)
                    664:                dc << "\nsetup hook function set to standard MFC hook function";
                    665:        else
                    666:                dc << "\nsetup hook function set to non-standard hook function";
                    667:        if (m_pd.lpfnPrintHook == (COMMDLGPROC)_AfxCommDlgProc)
                    668:                dc << "\nprint hook function set to standard MFC hook function";
                    669:        else
                    670:                dc << "\nprint hook function set to non-standard hook function";
                    671: 
                    672: }
                    673: #endif
                    674: 
                    675: /////////////////////////////////////////////////////////////////////////////
                    676: // Find/FindReplace dialogs
                    677: 
                    678: IMPLEMENT_DYNAMIC(CFindReplaceDialog, CDialog)
                    679: 
                    680: CFindReplaceDialog::CFindReplaceDialog() 
                    681: {
                    682:        memset(&m_fr, 0, sizeof(m_fr));
                    683:        m_szFindWhat[0] = '\0';
                    684:        m_szReplaceWith[0] = '\0';
                    685: 
                    686:        m_fr.Flags = FR_ENABLEHOOK;
                    687:        m_fr.lpfnHook = (COMMDLGPROC)_AfxCommDlgProc;
                    688:        m_fr.lStructSize = sizeof(m_fr);
                    689:        m_fr.lpstrFindWhat = (LPSTR)m_szFindWhat;
                    690: }
                    691: 
                    692: void
                    693: CFindReplaceDialog::PostNcDestroy()
                    694: {
                    695:        ASSERT(m_hWnd == NULL);
                    696:        delete this;
                    697: }
                    698: 
                    699: 
                    700: BOOL
                    701: CFindReplaceDialog::Create(BOOL bFindDialogOnly,
                    702:                LPCSTR lpszFindWhat,
                    703:                LPCSTR lpszReplaceWith /* = NULL */,
                    704:                DWORD dwFlags /* = FR_DOWN */,
                    705:                CWnd* pParentWnd /* = NULL */)
                    706: {
                    707:        ASSERT_VALID(this);
                    708:        ASSERT(m_fr.Flags & FR_ENABLEHOOK);
                    709:        ASSERT(m_fr.lpfnHook != NULL);
                    710: 
                    711:        HWND hwndResult;
                    712: 
                    713:        m_fr.wFindWhatLen = sizeof(m_szFindWhat);
                    714:        m_fr.lpstrReplaceWith = (LPSTR)m_szReplaceWith;
                    715:        m_fr.wReplaceWithLen = sizeof(m_szReplaceWith);
                    716:        m_fr.Flags |= dwFlags;
                    717: 
                    718:        if (pParentWnd == NULL)
                    719:                m_fr.hwndOwner = AfxGetApp()->m_pMainWnd->GetSafeHwnd();
                    720:        else
                    721:        {
                    722:                ASSERT_VALID(pParentWnd);
                    723:                m_fr.hwndOwner = pParentWnd->m_hWnd;
                    724:        }
                    725:        ASSERT(m_fr.hwndOwner != NULL); // must have a parent for modeless dialog
                    726:        
                    727: 
                    728:        if (lpszFindWhat)
                    729:                _fstrncpy(m_szFindWhat, lpszFindWhat, sizeof(m_szFindWhat));
                    730: 
                    731:        if (lpszReplaceWith)
                    732:                _fstrncpy(m_szReplaceWith, lpszReplaceWith, sizeof(m_szReplaceWith));
                    733: 
                    734: 
                    735:        _AfxHookWindowCreate(this);
                    736:        if (bFindDialogOnly)
                    737:                hwndResult = ::FindText(&m_fr);
                    738:        else
                    739:                hwndResult = ::ReplaceText(&m_fr);
                    740:        _AfxUnhookWindowCreate();   // just in case
                    741: 
                    742:        ASSERT(hwndResult == NULL || m_hWnd != NULL);
                    743: 
                    744:        return hwndResult == NULL ? FALSE : TRUE;
                    745: }
                    746: 
                    747: /* static */ CFindReplaceDialog* 
                    748: CFindReplaceDialog::GetNotifier(LONG lParam)
                    749: {
                    750:        ASSERT(lParam != NULL);
                    751:        CFindReplaceDialog* pDlg;
                    752: 
                    753:        pDlg = (CFindReplaceDialog*)(lParam - offsetof(CFindReplaceDialog, m_fr));
                    754:        ASSERT_VALID(pDlg);
                    755:        ASSERT(pDlg->IsKindOf(RUNTIME_CLASS(CFindReplaceDialog)));
                    756:        
                    757:        return pDlg;
                    758: }
                    759: 
                    760: #ifdef _DEBUG
                    761: void 
                    762: CFindReplaceDialog::Dump(CDumpContext& dc) const
                    763: {
                    764:        ASSERT_VALID(this);
                    765: 
                    766:        CDialog::Dump(dc);
                    767: 
                    768:        dc << "\nm_fr.hwndOwner = " << (void NEAR*)m_fr.hwndOwner;
                    769:        dc << "\nm_fr.Flags = " << (LPVOID)m_fr.Flags;
                    770:        dc << "\nm_fr.lpstrFindWhat = " << m_fr.lpstrFindWhat;
                    771:        dc << "\nm_fr.lpstrReplaceWith = " << m_fr.lpstrReplaceWith;
                    772:        if (m_fr.lpfnHook == (COMMDLGPROC)_AfxCommDlgProc)
                    773:                dc << "\nhook function set to standard MFC hook function";
                    774:        else
                    775:                dc << "\nhook function set to non-standard hook function";
                    776: }
                    777: #endif
                    778: 
                    779: /////////////////////////////////////////////////////////////////////////////

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.