home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgLangD.iso / C++-7 / DISK10 / MFC / INCLUDE / AFXDLGS.H$ / afxdlgs
Encoding:
Text File  |  1992-03-18  |  12.3 KB  |  374 lines

  1. // 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. #ifndef __AFXDLGS_H__
  12. #define __AFXDLGS_H__
  13.  
  14. /////////////////////////////////////////////////////////////////////////////
  15. // Classes declared in this file
  16.  
  17.         // CDialog
  18.             class CFindReplaceDialog; // Find/FindReplace dialogs
  19.             // class CModalDialog
  20.                 class CFileDialog;    // FileOpen/FileSaveAs dialogs
  21.                 class CColorDialog;   // Color picker dialog
  22.                 class CFontDialog;    // Font chooser dialog
  23.                 class CPrintDialog;   // Print/PrintSetup dialogs
  24.  
  25.  
  26. /////////////////////////////////////////////////////////////////////////////
  27. // Make sure 'afxwin.h' is included first
  28.  
  29. #ifndef __AFXWIN_H__
  30. #include "afxwin.h"
  31. #endif
  32.  
  33. #include "commdlg.h"    // common dialog APIs
  34. #include "print.h"      // printer specific APIs (DEVMODE)
  35.  
  36. /////////////////////////////////////////////////////////////////////////////
  37. // Standard dialogs using Windows 3.x dialog (COMMDLG.DLL must be on path)
  38.  
  39. // CFileDialog - used for FileOpen... or FileSaveAs...
  40. class CFileDialog : public CModalDialog
  41. {
  42.     DECLARE_DYNAMIC(CFileDialog)
  43.  
  44. public:
  45. // Attributes
  46.     // open file parameter block
  47.     OPENFILENAME m_ofn;
  48.  
  49. // Constructors
  50.     CFileDialog(BOOL bOpenFileDialog, // TRUE for FileOpen, FALSE for FileSaveAs
  51.         LPCSTR lpszDefExt = NULL,
  52.         LPCSTR lpszFileName = NULL,
  53.         DWORD dwFlags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
  54.         LPCSTR lpszFilter = NULL, 
  55.         CWnd* pParentWnd = NULL);
  56.  
  57. // Operations
  58.     virtual int DoModal();
  59.  
  60.     // Helpers for parsing file name after successful return
  61.     CString GetPathName() const;  // return full path name
  62.     CString GetFileName() const;  // return only filename
  63.     CString GetFileExt() const;   // return only ext
  64.     CString GetFileTitle() const; // return file title
  65.     BOOL GetReadOnlyPref() const; // return TRUE if readonly checked
  66.     
  67. // Overridable callbacks
  68. protected:
  69.     friend UINT FAR PASCAL AFX_EXPORT _AfxCommDlgProc(HWND, UINT, UINT, LONG);
  70.     virtual UINT OnShareViolation(LPCSTR lpszPathName);
  71.     virtual BOOL OnFileNameOK();
  72.     virtual void OnLBSelChangedNotify(UINT nIDBox, UINT iCurSel, UINT nCode);
  73.  
  74. // Implementation
  75. #ifdef _DEBUG
  76. public:
  77.     virtual void Dump(CDumpContext& dc) const;
  78. #endif
  79.  
  80. protected:
  81.     virtual void OnOK();
  82.     virtual void OnCancel();
  83.  
  84.     BOOL m_bOpenFileDialog;       // TRUE for file open, FALSE for file save
  85.     CString m_strFilter;          // filter string
  86.                         // separate fields with '|', terminate with '||\0'
  87.     char m_szFileTitle[64];       // contains file title after return
  88.     char m_szFileName[_MAX_PATH]; // contains full path name after return
  89. };
  90.  
  91. // CFontDialog - used to select a font
  92. class CFontDialog : public CModalDialog
  93. {
  94.     DECLARE_DYNAMIC(CFontDialog)
  95.  
  96. public:
  97. // Attributes
  98.     // font choosing parameter block
  99.     CHOOSEFONT m_cf;
  100.     LOGFONT    m_lf;
  101.  
  102. // Constructors
  103.     CFontDialog(LPLOGFONT lplfInitial = NULL,
  104.         DWORD dwFlags = CF_EFFECTS | CF_SCREENFONTS, 
  105.         CDC* pdcPrinter = NULL,
  106.         CWnd* pParentWnd = NULL);
  107.  
  108. // Operations
  109.     virtual int DoModal();
  110.  
  111.     // Retrieve the currently selected font while dialog is displayed
  112.     void GetCurrentFont(LPLOGFONT lplf);
  113.  
  114.     // Helpers for parsing information after successful return
  115.     CString GetFaceName() const;  // return the face name of the font
  116.     CString GetStyleName() const; // return the style name of the font
  117.     int GetSize() const;          // return the pt size of the font
  118.     COLORREF GetColor() const;    // return the color of the font
  119.     int GetWeight() const;        // return the chosen font weight 
  120.     BOOL IsStrikeOut() const;     // return TRUE if strikeout
  121.     BOOL IsUnderline() const;     // return TRUE if underline
  122.     BOOL IsBold() const;          // return TRUE if bold font
  123.     BOOL IsItalic() const;        // return TRUE if italic font
  124.  
  125. // Implementation
  126.  
  127. #ifdef _DEBUG
  128. public:
  129.     virtual void Dump(CDumpContext& dc) const;
  130. #endif
  131.  
  132. protected:
  133.     virtual void OnOK();
  134.     virtual void OnCancel();
  135.  
  136.     char m_szStyleName[64]; // contains style name after return
  137. };
  138.  
  139.  
  140.  
  141. // CColorDialog - used to select a color
  142. class CColorDialog : public CModalDialog
  143. {
  144.     DECLARE_DYNAMIC(CColorDialog)
  145.  
  146. public:
  147. // Attributes
  148.     // color picker parameter block
  149.     CHOOSECOLOR m_cc;
  150.  
  151. // Constructors
  152.     CColorDialog(COLORREF clrInit = 0, DWORD dwFlags = 0, 
  153.             CWnd* pParentWnd = NULL);
  154.  
  155. // Operations
  156.     virtual int DoModal();
  157.  
  158.     // Set the current color while dialog is displayed
  159.     void SetCurrentColor(COLORREF clr); 
  160.  
  161.     // Helpers for parsing information after successful return
  162.     COLORREF GetColor() const;
  163.  
  164.     // Custom colors are held here and saved between calls
  165.     static COLORREF clrSavedCustom[16];
  166.  
  167. // Overridable callbacks
  168. protected:
  169.     friend UINT FAR PASCAL AFX_EXPORT _AfxCommDlgProc(HWND, UINT, UINT, LONG);
  170.     virtual BOOL OnColorOK();       // validate color
  171.     
  172. // Implementation
  173.  
  174. #ifdef _DEBUG
  175. public:
  176.     virtual void Dump(CDumpContext& dc) const;
  177. #endif
  178.  
  179. protected:
  180.     virtual void OnOK();
  181.     virtual void OnCancel();
  182. };
  183.  
  184.  
  185. // CPrintDialog - used for Print... and PrintSetup...
  186. class CPrintDialog : public CModalDialog
  187. {
  188.     DECLARE_DYNAMIC(CPrintDialog)
  189.  
  190. public:
  191. // Attributes
  192.     // print dialog parameter block (note this is a reference)
  193.     PRINTDLG FAR& m_pd;
  194.  
  195. // Constructors
  196.     CPrintDialog(BOOL bPrintSetupOnly,  // FALSE for print dialog as well
  197.         DWORD dwFlags = PD_ALLPAGES | PD_USEDEVMODECOPIES | PD_NOPAGENUMS
  198.             | PD_HIDEPRINTTOFILE | PD_NOSELECTION,
  199.         CWnd* pParentWnd = NULL); 
  200.  
  201. // Operations
  202.     virtual int DoModal();
  203.  
  204.     // GetDefaults will not display a dialog but will get 
  205.     // device defaults
  206.     BOOL GetDefaults();
  207.  
  208.     // Helpers for parsing information after successful return
  209.     int GetCopies() const;          // num. copies requested
  210.     BOOL PrintCollate() const;      // TRUE if collate checked
  211.     BOOL PrintSelection() const;    // TRUE if printing selection
  212.     BOOL PrintAll() const;          // TRUE if printing all pages
  213.     BOOL PrintRange() const;        // TRUE if printing page range
  214.     int GetFromPage() const;        // starting page if valid
  215.     int GetToPage() const;          // starting page if valid
  216.     LPDEVMODE GetDevMode() const;   // return DEVMODE
  217.     CString GetDriverName() const;  // return driver name
  218.     CString GetDeviceName() const;  // return device name
  219.     CString GetPortName() const;    // return output port name
  220.     HDC GetPrinterDC() const;       // return HDC (caller must delete)
  221.  
  222. // Implementation
  223.  
  224. #ifdef _DEBUG
  225. public:
  226.     virtual void Dump(CDumpContext& dc) const;
  227. #endif
  228.  
  229. protected:
  230.     virtual void OnOK();
  231.     virtual void OnCancel();
  232.  
  233.     // The following handle the case of print setup... from the print dialog
  234.     CPrintDialog(PRINTDLG FAR& pdInit);
  235.     afx_msg void OnPrintSetup();
  236.     virtual CPrintDialog* AttachOnSetup();
  237.  
  238. private:
  239.     PRINTDLG m_pdActual; // the Print/Print Setup need to share this
  240.  
  241.     DECLARE_MESSAGE_MAP()
  242. };
  243.  
  244. // Find/FindReplace modeless dialogs
  245. class CFindReplaceDialog : public CDialog
  246. {
  247.     DECLARE_DYNAMIC(CFindReplaceDialog)
  248.  
  249. public:
  250. // Attributes
  251.     FINDREPLACE m_fr;
  252.  
  253. // Constructors
  254.     CFindReplaceDialog();
  255.     // NOTE: you must allocate these on the heap.  If you do not,
  256.     // you must derive and override PostNcDestroy() and do not delete this.
  257.     
  258.     BOOL Create(BOOL bFindDialogOnly, // TRUE for Find, FALSE for FindReplace
  259.             LPCSTR lpszFindWhat, 
  260.             LPCSTR lpszReplaceWith  = NULL, 
  261.             DWORD dwFlags = FR_DOWN,
  262.             CWnd* pParentWnd = NULL);
  263.  
  264.     // find/replace parameter block
  265.     static CFindReplaceDialog* GetNotifier(LONG lParam);
  266.  
  267. // Operations
  268.     // Helpers for parsing information after successful return
  269.     CString GetReplaceString() const;// get replacement string
  270.     CString GetFindString() const;   // get find string
  271.     BOOL SearchDown() const;         // TRUE if search down, FALSE is up
  272.     BOOL FindNext() const;           // TRUE if command is find next
  273.     BOOL MatchCase() const;          // TRUE if matching case
  274.     BOOL MatchWholeWord() const;     // TRUE if matching whole words only
  275.     BOOL ReplaceCurrent() const;     // TRUE if replacing current string
  276.     BOOL ReplaceAll() const;         // TRUE if replacing all occurrences
  277.     BOOL IsTerminating() const;      // TRUE if terminating dialog
  278.  
  279. // Implementation
  280. protected:
  281.     virtual void PostNcDestroy();
  282.  
  283. #ifdef _DEBUG
  284. public:
  285.     virtual void Dump(CDumpContext& dc) const;
  286. #endif
  287.  
  288. protected:
  289.     char m_szFindWhat[128];
  290.     char m_szReplaceWith[128];
  291. };
  292.  
  293.  
  294. // inline functions for classes in this file
  295.  
  296. inline CString CFileDialog::GetPathName() const
  297.     { return m_ofn.lpstrFile; }
  298. inline CString CFileDialog::GetFileExt() const
  299.     { if (m_ofn.nFileExtension == 0) return (char)'\0';
  300.         else return m_ofn.lpstrFile + m_ofn.nFileExtension; }
  301. inline CString CFileDialog::GetFileTitle() const
  302.     { return m_ofn.lpstrFileTitle; }
  303. inline BOOL CFileDialog::GetReadOnlyPref() const
  304.     { return m_ofn.Flags & OFN_READONLY ? TRUE : FALSE; }
  305. inline void CFontDialog::GetCurrentFont(LPLOGFONT lplf)
  306.     { ASSERT(m_hWnd != NULL); this->SendMessage(WM_CHOOSEFONT_GETLOGFONT, 
  307.         0, (DWORD)(LPSTR)lplf); }
  308. inline CString CFontDialog::GetFaceName() const
  309.     { return m_cf.lpLogFont->lfFaceName; }
  310. inline CString CFontDialog::GetStyleName() const
  311.     { return m_cf.lpszStyle; }
  312. inline int CFontDialog::GetSize() const
  313.     { return m_cf.iPointSize; }
  314. inline int CFontDialog::GetWeight() const
  315.     { return m_cf.lpLogFont->lfWeight; }
  316. inline BOOL CFontDialog::IsItalic() const
  317.     { return m_cf.lpLogFont->lfItalic ? TRUE : FALSE; }
  318. inline BOOL CFontDialog::IsStrikeOut() const
  319.     { return m_cf.lpLogFont->lfStrikeOut ? TRUE : FALSE; }
  320. inline BOOL CFontDialog::IsBold() const
  321.     { return m_cf.lpLogFont->lfWeight == FW_BOLD ? TRUE : FALSE; }
  322. inline BOOL CFontDialog::IsUnderline() const
  323.     { return m_cf.lpLogFont->lfUnderline ? TRUE : FALSE; }
  324. inline COLORREF CFontDialog::GetColor() const
  325.     { return m_cf.rgbColors; }
  326. inline COLORREF CColorDialog::GetColor() const
  327.     { return m_cc.rgbResult; }
  328. inline BOOL CPrintDialog::GetDefaults()
  329.     { m_pd.Flags |= PD_RETURNDEFAULT;
  330.     return ::PrintDlg(&m_pd); }
  331. inline BOOL CPrintDialog::PrintSelection() const
  332.     { return m_pd.Flags & PD_SELECTION ? TRUE : FALSE; }
  333. inline BOOL CPrintDialog::PrintRange() const
  334.     { return m_pd.Flags & PD_PAGENUMS ? TRUE : FALSE; }
  335. inline BOOL CPrintDialog::PrintAll() const
  336.     { return !PrintRange() && !PrintSelection() ? TRUE : FALSE; }
  337. inline BOOL CPrintDialog::PrintCollate() const
  338.     { return m_pd.Flags & PD_COLLATE ? TRUE : FALSE; }
  339. inline int CPrintDialog::GetFromPage() const
  340.     { return (PrintRange() ? m_pd.nFromPage :-1); }
  341. inline int CPrintDialog::GetToPage() const
  342.     { return (PrintRange() ? m_pd.nToPage :-1); }
  343. inline LPDEVMODE CPrintDialog::GetDevMode() const
  344.     { return (LPDEVMODE)::GlobalLock(m_pd.hDevMode); }
  345. inline CString CPrintDialog::GetDriverName() const
  346.     { LPDEVNAMES lpDev = (LPDEVNAMES)GlobalLock(m_pd.hDevNames);
  347.     return (LPSTR)(lpDev) + (UINT)(lpDev->wDriverOffset); }
  348. inline CString CPrintDialog::GetDeviceName() const
  349.     { LPDEVNAMES lpDev = (LPDEVNAMES)GlobalLock(m_pd.hDevNames);
  350.     return (LPSTR)(lpDev) + (UINT)(lpDev->wDeviceOffset); }
  351. inline CString CPrintDialog::GetPortName() const
  352.     { LPDEVNAMES lpDev = (LPDEVNAMES)GlobalLock(m_pd.hDevNames);
  353.     return (LPSTR)(lpDev) + (UINT)(lpDev->wOutputOffset); }
  354. inline BOOL CFindReplaceDialog::IsTerminating() const 
  355.     { return m_fr.Flags & FR_DIALOGTERM ? TRUE : FALSE ; }
  356. inline CString CFindReplaceDialog::GetReplaceString() const 
  357.     { return m_fr.lpstrReplaceWith; }
  358. inline CString CFindReplaceDialog::GetFindString() const 
  359.     { return m_fr.lpstrFindWhat; }
  360. inline BOOL CFindReplaceDialog::SearchDown() const 
  361.     { return m_fr.Flags & FR_DOWN ? TRUE : FALSE; }
  362. inline BOOL CFindReplaceDialog::FindNext() const 
  363.     { return m_fr.Flags & FR_FINDNEXT ? TRUE : FALSE; }
  364. inline BOOL CFindReplaceDialog::MatchCase() const 
  365.     { return m_fr.Flags & FR_MATCHCASE ? TRUE : FALSE; }
  366. inline BOOL CFindReplaceDialog::MatchWholeWord() const 
  367.     { return m_fr.Flags & FR_WHOLEWORD ? TRUE : FALSE; }
  368. inline BOOL CFindReplaceDialog::ReplaceCurrent() const 
  369.     { return m_fr. Flags & FR_REPLACE ? TRUE : FALSE; }
  370. inline BOOL CFindReplaceDialog::ReplaceAll() const 
  371.     { return m_fr.Flags & FR_REPLACEALL ? TRUE : FALSE; }
  372.  
  373. #endif //__AFXDLGS_H__
  374.