home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 27 / IOPROG_27.ISO / SOFT / DTEDIT.ZIP / dteditDlg.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-12-24  |  6.2 KB  |  263 lines

  1. // dteditDlg.cpp : implementation file
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "dtedit.h"
  6. #include "dteditDlg.h"
  7.  
  8. #include <afxtempl.h> // for CArray
  9.  
  10. #ifdef _DEBUG
  11. #define new DEBUG_NEW
  12. #undef THIS_FILE
  13. static char THIS_FILE[] = __FILE__;
  14. #endif
  15.  
  16. /////////////////////////////////////////////////////////////////////////////
  17. // CAboutDlg dialog used for App About
  18.  
  19. class CAboutDlg : public CDialog
  20. {
  21. public:
  22.     CAboutDlg();
  23.  
  24. // Dialog Data
  25.     //{{AFX_DATA(CAboutDlg)
  26.     enum { IDD = IDD_ABOUTBOX };
  27.     //}}AFX_DATA
  28.  
  29.     // ClassWizard generated virtual function overrides
  30.     //{{AFX_VIRTUAL(CAboutDlg)
  31.     protected:
  32.     virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
  33.     //}}AFX_VIRTUAL
  34.  
  35. // Implementation
  36. protected:
  37.     //{{AFX_MSG(CAboutDlg)
  38.     //}}AFX_MSG
  39.     DECLARE_MESSAGE_MAP()
  40. };
  41.  
  42. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  43. {
  44.     //{{AFX_DATA_INIT(CAboutDlg)
  45.     //}}AFX_DATA_INIT
  46. }
  47.  
  48. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  49. {
  50.     CDialog::DoDataExchange(pDX);
  51.     //{{AFX_DATA_MAP(CAboutDlg)
  52.     //}}AFX_DATA_MAP
  53. }
  54.  
  55. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  56.     //{{AFX_MSG_MAP(CAboutDlg)
  57.         // No message handlers
  58.     //}}AFX_MSG_MAP
  59. END_MESSAGE_MAP()
  60.  
  61. /////////////////////////////////////////////////////////////////////////////
  62. // CDteditDlg dialog
  63.  
  64. CDteditDlg::CDteditDlg(CWnd* pParent /*=NULL*/)
  65.     : CDialog(CDteditDlg::IDD, pParent)
  66. {
  67.     //{{AFX_DATA_INIT(CDteditDlg)
  68.     m_strDocName = _T("");
  69.     m_strFileNewName = _T("");
  70.     m_strFilterExt = _T("");
  71.     m_strFilterName = _T("");
  72.     m_strRegId = _T("");
  73.     m_strRegName = _T("");
  74.     m_strWindowTitle = _T("");
  75.     m_strTemplate = _T("");
  76.     //}}AFX_DATA_INIT
  77.     // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
  78.     m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  79. }
  80.  
  81. void CDteditDlg::DoDataExchange(CDataExchange* pDX)
  82. {
  83.     CDialog::DoDataExchange(pDX);
  84.     //{{AFX_DATA_MAP(CDteditDlg)
  85.     DDX_Text(pDX, IDC_EDIT_DOCUMENT_NAME, m_strDocName);
  86.     DDX_Text(pDX, IDC_EDIT_FILE_NEW_NAME, m_strFileNewName);
  87.     DDX_Text(pDX, IDC_EDIT_FILTER_EXTENSION, m_strFilterExt);
  88.     DDX_Text(pDX, IDC_EDIT_FILTER_NAME, m_strFilterName);
  89.     DDX_Text(pDX, IDC_EDIT_REGISTRATION_ID, m_strRegId);
  90.     DDX_Text(pDX, IDC_EDIT_REGISTRATION_NAME, m_strRegName);
  91.     DDX_Text(pDX, IDC_EDIT_WINDOW_TITLE, m_strWindowTitle);
  92.     DDX_Text(pDX, IDC_EDIT_TEMPLATE, m_strTemplate);
  93.     //}}AFX_DATA_MAP
  94. }
  95.  
  96. BEGIN_MESSAGE_MAP(CDteditDlg, CDialog)
  97.     //{{AFX_MSG_MAP(CDteditDlg)
  98.     ON_WM_SYSCOMMAND()
  99.     ON_WM_PAINT()
  100.     ON_WM_QUERYDRAGICON()
  101.     ON_BN_CLICKED(IDC_BTN_EXAMPLE, OnBtnExample)
  102.     ON_BN_CLICKED(IDC_BTN_BUILD, OnBtnBuild)
  103.     ON_BN_CLICKED(IDC_BTN_PARSE, OnBtnParse)
  104.     ON_WM_CLOSE()
  105.     //}}AFX_MSG_MAP
  106. END_MESSAGE_MAP()
  107.  
  108. /////////////////////////////////////////////////////////////////////////////
  109. // CDteditDlg message handlers
  110.  
  111. BOOL CDteditDlg::OnInitDialog()
  112. {
  113.     CDialog::OnInitDialog();
  114.  
  115.     // Add "About..." menu item to system menu.
  116.  
  117.     // IDM_ABOUTBOX must be in the system command range.
  118.     ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
  119.     ASSERT(IDM_ABOUTBOX < 0xF000);
  120.  
  121.     CMenu* pSysMenu = GetSystemMenu(FALSE);
  122.     if (pSysMenu != NULL)
  123.     {
  124.         CString strAboutMenu;
  125.         strAboutMenu.LoadString(IDS_ABOUTBOX);
  126.         if (!strAboutMenu.IsEmpty())
  127.         {
  128.             pSysMenu->AppendMenu(MF_SEPARATOR);
  129.             pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
  130.         }
  131.     }
  132.  
  133.     // Set the icon for this dialog.  The framework does this automatically
  134.     //  when the application's main window is not a dialog
  135.     SetIcon(m_hIcon, TRUE);            // Set big icon
  136.     SetIcon(m_hIcon, FALSE);        // Set small icon
  137.     
  138.     // TODO: Add extra initialization here
  139.     
  140.     return TRUE;  // return TRUE  unless you set the focus to a control
  141. }
  142.  
  143. void CDteditDlg::OnSysCommand(UINT nID, LPARAM lParam)
  144. {
  145.     if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  146.     {
  147.         CAboutDlg dlgAbout;
  148.         dlgAbout.DoModal();
  149.     }
  150.     else
  151.     {
  152.         CDialog::OnSysCommand(nID, lParam);
  153.     }
  154. }
  155.  
  156. // If you add a minimize button to your dialog, you will need the code below
  157. //  to draw the icon.  For MFC applications using the document/view model,
  158. //  this is automatically done for you by the framework.
  159.  
  160. void CDteditDlg::OnPaint() 
  161. {
  162.     if (IsIconic())
  163.     {
  164.         CPaintDC dc(this); // device context for painting
  165.  
  166.         SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  167.  
  168.         // Center icon in client rectangle
  169.         int cxIcon = GetSystemMetrics(SM_CXICON);
  170.         int cyIcon = GetSystemMetrics(SM_CYICON);
  171.         CRect rect;
  172.         GetClientRect(&rect);
  173.         int x = (rect.Width() - cxIcon + 1) / 2;
  174.         int y = (rect.Height() - cyIcon + 1) / 2;
  175.  
  176.         // Draw the icon
  177.         dc.DrawIcon(x, y, m_hIcon);
  178.     }
  179.     else
  180.     {
  181.         CDialog::OnPaint();
  182.     }
  183. }
  184.  
  185. // The system calls this to obtain the cursor to display while the user drags
  186. //  the minimized window.
  187. HCURSOR CDteditDlg::OnQueryDragIcon()
  188. {
  189.     return (HCURSOR) m_hIcon;
  190. }
  191.  
  192. void CDteditDlg::OnBtnExample() 
  193. {
  194.     m_strDocName = "Sheet1";
  195.     m_strFileNewName = "Worksheet";
  196.     m_strFilterExt = ".xls";
  197.     m_strFilterName = "Worksheets (*.xls)";
  198.     m_strRegId = "ExcelWorksheet";
  199.     m_strRegName = "Microsoft Excel Worksheet";
  200.     m_strWindowTitle = "Microsoft Excel";
  201.  
  202.     UpdateData(false);
  203.  
  204.     OnBtnBuild();
  205. }
  206.  
  207. void CDteditDlg::OnBtnBuild() 
  208. {
  209.     UpdateData();
  210.  
  211.     m_strTemplate.Format("%s\\n%s\\n%s\\n%s\\n%s\\n%s\\n%s", 
  212.         m_strWindowTitle,
  213.         m_strDocName,
  214.         m_strFileNewName,
  215.         m_strFilterName,
  216.         m_strFilterExt,
  217.         m_strRegId,
  218.         m_strRegName);
  219.  
  220.     UpdateData(false);
  221. }
  222.  
  223. void CDteditDlg::OnBtnParse() 
  224. {
  225.     UpdateData();
  226.  
  227.     CArray<CString*, CString*> oFields;
  228.  
  229.     oFields.Add(&m_strWindowTitle);
  230.     oFields.Add(&m_strDocName);
  231.     oFields.Add(&m_strFileNewName);
  232.     oFields.Add(&m_strFilterName);
  233.     oFields.Add(&m_strFilterExt);
  234.     oFields.Add(&m_strRegId);
  235.     oFields.Add(&m_strRegName);
  236.  
  237.     CString strTemp(m_strTemplate);
  238.     strTemp += "\\n";
  239.     int nLoc;
  240.     for(int i=0, j=oFields.GetSize(); i<j; i++)
  241.     {
  242.         nLoc = strTemp.Find("\\n");
  243.         *oFields[i] = strTemp.Left(nLoc);
  244.         CString strT = strTemp.Right(strTemp.GetLength() - nLoc - 2);
  245.         strTemp = strT;
  246.     }
  247.     UpdateData(false);    
  248. }
  249.  
  250. void CDteditDlg::OnCancel() 
  251. {
  252. // Don't let ESC key close dialog    
  253. //    CDialog::OnCancel();
  254. }
  255.  
  256. void CDteditDlg::OnClose() 
  257. {
  258. // Since CDteditDlg::OnCancel was subverted, call it here for cleanup!
  259.     CDialog::OnCancel();
  260.     
  261.     CDialog::OnClose();
  262. }
  263.