home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c480 / 19.ddi / MFC / SAMPLES / CTRLTEST / FEATPEN.CP_ / FEATPEN.CP
Encoding:
Text File  |  1993-02-08  |  5.0 KB  |  205 lines

  1. // featpen.cpp : pen HEdit features
  2. //
  3. // This is a part of the Microsoft Foundation Classes C++ library.
  4. // Copyright (C) 1992 Microsoft Corporation
  5. // All rights reserved.
  6. //
  7. // This source code is only intended as a supplement to the
  8. // Microsoft Foundation Classes Reference and Microsoft
  9. // WinHelp documentation provided with the library.
  10. // See these sources for detailed information regarding the
  11. // Microsoft Foundation Classes product.
  12.  
  13. #include "stdafx.h"
  14. #include "ctrltest.h"
  15.  
  16.  
  17. // we need the MFC extensions for PenWindows
  18. #include <afxpen.h>
  19. // we also use the MFC common dialogs for color picker
  20. #include <afxdlgs.h>
  21.  
  22. /////////////////////////////////////////////////////////////////////////////
  23.  
  24. class CPenFeatureDlg : public CDialog
  25. {
  26. public:
  27.     //{{AFX_DATA(CPenFeatureDlg)
  28.         enum { IDD = IDD_PENEDIT_FEATURES };
  29.     //}}AFX_DATA
  30.     CPenFeatureDlg()
  31.         : CDialog(CPenFeatureDlg::IDD)
  32.         { }
  33.  
  34.     // just 1 HEdit to play with
  35.     CHEdit& Edit1()
  36.                 { return *(CHEdit*)GetDlgItem(IDC_EDIT1); }
  37.  
  38. // Implementation
  39. protected:
  40.     BOOL OnInitDialog();
  41.     //{{AFX_MSG(CPenFeatureDlg)
  42.     virtual void OnOK();
  43.     afx_msg void OnConfigure();
  44.     //}}AFX_MSG
  45.     DECLARE_MESSAGE_MAP();
  46. };
  47.  
  48. BEGIN_MESSAGE_MAP(CPenFeatureDlg, CDialog)
  49.     //{{AFX_MSG_MAP(CPenFeatureDlg)
  50.     ON_COMMAND(IDC_CONFIGURE, OnConfigure)
  51.     //}}AFX_MSG_MAP
  52. END_MESSAGE_MAP()
  53.  
  54. /////////////////////////////////////////////////////////////////////////////
  55.  
  56. BOOL CPenFeatureDlg::OnInitDialog()
  57. {
  58.     // nothing special to do
  59.     return TRUE;
  60. }
  61.  
  62. void CPenFeatureDlg::OnOK()
  63. {
  64. #ifdef _DEBUG
  65.     // dump results, normally you would do something with these
  66.     CString s;
  67.     Edit1().GetWindowText(s);
  68.     TRACE("edit1 = '%s'\n", (const char*) s);
  69. #endif
  70.  
  71.     EndDialog(IDOK);
  72. }
  73.  
  74. /////////////////////////////////////////////////////////////////////////////
  75. // Run the test
  76.  
  77. void CTestWindow::OnTestPenEditFeatures()
  78. {
  79.     TRACE("running HEdit feature test dialog\n");
  80.     CPenFeatureDlg dlg;
  81.     dlg.DoModal();
  82. }
  83.  
  84.  
  85. /////////////////////////////////////////////////////////////////////////////
  86. // Configure the HEdit edit item
  87.     // (note: local changes only)
  88.  
  89. // Dialog used for the configure option
  90. class CConfigureHEditDlg : public CDialog
  91. {
  92. protected:
  93.     CHEdit&     m_rHEdit;       // reference to Edit item to configure
  94.     COLORREF    m_inkColor;     // for color picker
  95.  
  96. public:
  97.     //{{AFX_DATA(CConfigureHEditDlg)
  98.         enum { IDD = IDD_PENEDIT_CONFIGURE };
  99.     //}}AFX_DATA
  100.  
  101.     CConfigureHEditDlg(CHEdit& rHEdit, CWnd* pParent = NULL)
  102.         : CDialog(CConfigureHEditDlg::IDD, pParent),
  103.             m_rHEdit(rHEdit)
  104.         { }
  105.  
  106. // Implementation
  107. protected:
  108.     BOOL OnInitDialog();
  109.     //{{AFX_MSG(CConfigureHEditDlg)
  110.     virtual void OnOK();
  111.     afx_msg void OnChooseInkColor();
  112.     //}}AFX_MSG
  113.     DECLARE_MESSAGE_MAP();
  114. };
  115.  
  116. BEGIN_MESSAGE_MAP(CConfigureHEditDlg, CDialog)
  117.     //{{AFX_MSG_MAP(CConfigureHEditDlg)
  118.     ON_COMMAND(IDC_BUTTON2, OnChooseInkColor)
  119.     //}}AFX_MSG_MAP
  120. END_MESSAGE_MAP()
  121.  
  122. BOOL CConfigureHEditDlg::OnInitDialog()
  123. {
  124.     // fill in initial values
  125.     RC rcInfo;
  126.     VERIFY(m_rHEdit.GetRC(&rcInfo));            // get current settings
  127.  
  128.     // set the ALC bits (max of 32 of them, 1 checkbox each)
  129.     TRACE("initial ALC = 0x%lx\n", rcInfo.alc);
  130.     for (int i = 0; i < 32; i++)
  131.     {
  132.         if (rcInfo.alc & (1L<<i))
  133.             CheckDlgButton(IDC_ALC_FIRST+i, TRUE);
  134.                 // check control if there is one
  135.     }
  136.  
  137.     // set LeftHanded
  138.     if (rcInfo.wRcPreferences & RCP_LEFTHAND)
  139.         CheckDlgButton(IDC_BUTTON1, TRUE);
  140.  
  141.     // set ink info
  142.     SetDlgItemInt(IDC_EDIT1, rcInfo.nInkWidth);
  143.     m_inkColor = rcInfo.rgbInk;
  144.     return TRUE;
  145. }
  146.  
  147. void CConfigureHEditDlg::OnOK()
  148. {
  149.     // get info from dialog, update fields of RC as appropriate
  150.     RC rcInfo;
  151.     VERIFY(m_rHEdit.GetRC(&rcInfo));            // get current settings
  152.  
  153.     for (int i = 0; i < 32; i++)
  154.     {
  155.         CButton* pButton = (CButton*)GetDlgItem(IDC_ALC_FIRST + i);
  156.         if (pButton != NULL)
  157.         {
  158.             // set bit depending on checkbox content
  159.             if (pButton->GetCheck())
  160.                 rcInfo.alc |= (1L << i);
  161.             else
  162.                 rcInfo.alc &= ~(1L << i);
  163.         }
  164.     }
  165.  
  166.     if (IsDlgButtonChecked(IDC_BUTTON1))
  167.         rcInfo.wRcPreferences |= RCP_LEFTHAND;
  168.     else
  169.         rcInfo.wRcPreferences &= ~RCP_LEFTHAND;
  170.  
  171.     BOOL bOk;
  172.     rcInfo.nInkWidth = GetDlgItemInt(IDC_EDIT1, &bOk);
  173.     if (!bOk || rcInfo.nInkWidth < -1 || rcInfo.nInkWidth > 15)
  174.     {
  175.         MessageBox("Illegal Ink Width (-1 .. 15 permitted)");
  176.         CEdit* pEdit = (CEdit*)GetDlgItem(IDC_EDIT1);
  177.         pEdit->SetSel(0, -1);
  178.         pEdit->SetFocus();
  179.         return;
  180.     }
  181.     rcInfo.rgbInk = m_inkColor;
  182.  
  183.     // set the final values
  184.     VERIFY(m_rHEdit.SetRC(&rcInfo));
  185.     EndDialog(IDOK);
  186. }
  187.  
  188. void CConfigureHEditDlg::OnChooseInkColor()
  189. {
  190.     COLORREF crPrompt = ((m_inkColor != RC_LDEFAULT) ? m_inkColor : 0);
  191.         // default to 0 (black) for default color
  192.  
  193.     CColorDialog dlg(crPrompt, CC_PREVENTFULLOPEN, this);
  194.     if (dlg.DoModal() == IDOK)
  195.         m_inkColor = dlg.GetColor();
  196. }
  197.  
  198. void CPenFeatureDlg::OnConfigure()
  199. {
  200.     CConfigureHEditDlg dlg(Edit1(), this);
  201.     dlg.DoModal();
  202. }
  203.  
  204. /////////////////////////////////////////////////////////////////////////////
  205.