home *** CD-ROM | disk | FTP | other *** search
/ Mastering Visual Basic 5 / MasteringVisualBasic5.iso / protview / demowinx / data.3 / text / samples / MFC / TEXTDEMO / TEXTDLG.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1996-10-25  |  8.8 KB  |  270 lines

  1. // TextDlg.cpp : implementation file
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "TextDemo.h"
  6. #include "TextDlg.h"
  7. #include "Text3D.h"
  8.  
  9. #ifdef _DEBUG
  10. #define new DEBUG_NEW
  11. #undef THIS_FILE
  12. static char THIS_FILE[] = __FILE__;
  13. #endif
  14.  
  15. #define TIMER_ID 1234
  16.  
  17. /////////////////////////////////////////////////////////////////////////////
  18. // CTextDemoDlg dialog
  19.  
  20. CTextDemoDlg::CTextDemoDlg(CWnd* pParent /*=NULL*/)
  21.     : CDialog(CTextDemoDlg::IDD, pParent)
  22. {
  23.     //{{AFX_DATA_INIT(CTextDemoDlg)
  24.         // NOTE: the ClassWizard will add member initialization here
  25.     //}}AFX_DATA_INIT
  26.     // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
  27.     m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  28. }
  29.  
  30. void CTextDemoDlg::DoDataExchange(CDataExchange* pDX)
  31. {
  32.     CDialog::DoDataExchange(pDX);
  33.     //{{AFX_DATA_MAP(CTextDemoDlg)
  34.         // NOTE: the ClassWizard will add DDX and DDV calls here
  35.     //}}AFX_DATA_MAP
  36. }
  37.  
  38. BEGIN_MESSAGE_MAP(CTextDemoDlg, CDialog)
  39.     //{{AFX_MSG_MAP(CTextDemoDlg)
  40.     ON_WM_PAINT()
  41.     ON_WM_QUERYDRAGICON()
  42.     ON_BN_CLICKED(IDC_TEXTONFRAME, OnTextonframe)
  43.     ON_BN_CLICKED(IDC_SHADOW, OnShadow)
  44.     ON_WM_TIMER()
  45.     ON_CBN_SELCHANGE(IDC_FRAMECOLOR, OnSelchangeFramecolor)
  46.     ON_WM_DESTROY()
  47.     //}}AFX_MSG_MAP
  48. END_MESSAGE_MAP()
  49.  
  50. /////////////////////////////////////////////////////////////////////////////
  51. // CTextDemoDlg message handlers
  52.  
  53. BOOL CTextDemoDlg::OnInitDialog()
  54. {
  55.     CDialog::OnInitDialog();
  56.  
  57.     // Set the icon for this dialog.  The framework does this automatically
  58.     //  when the application's main window is not a dialog
  59.     SetIcon(m_hIcon, TRUE);            // Set big icon
  60.     SetIcon(m_hIcon, FALSE);        // Set small icon
  61.     
  62.     // TODO: Add extra initialization here
  63.     SetTimer(TIMER_ID, 1000, NULL);
  64.     m_uTimer = 0;
  65.     ((CComboBox*)GetDlgItem(IDC_FRAMECOLOR))->SetCurSel(0);
  66.     
  67.     
  68.     return TRUE;  // return TRUE  unless you set the focus to a control
  69. }
  70.  
  71. // If you add a minimize button to your dialog, you will need the code below
  72. //  to draw the icon.  For MFC applications using the document/view model,
  73. //  this is automatically done for you by the framework.
  74.  
  75. void CTextDemoDlg::OnPaint() 
  76. {
  77.     if (IsIconic())
  78.     {
  79.         CPaintDC dc(this); // device context for painting
  80.  
  81.         SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  82.  
  83.         // Center icon in client rectangle
  84.         int cxIcon = GetSystemMetrics(SM_CXICON);
  85.         int cyIcon = GetSystemMetrics(SM_CYICON);
  86.         CRect rect;
  87.         GetClientRect(&rect);
  88.         int x = (rect.Width() - cxIcon + 1) / 2;
  89.         int y = (rect.Height() - cyIcon + 1) / 2;
  90.  
  91.         // Draw the icon
  92.         dc.DrawIcon(x, y, m_hIcon);
  93.     }
  94.     else
  95.     {
  96.         CDialog::OnPaint();
  97.     }
  98. }
  99.  
  100. // The system calls this to obtain the cursor to display while the user drags
  101. //  the minimized window.
  102. HCURSOR CTextDemoDlg::OnQueryDragIcon()
  103. {
  104.     return (HCURSOR) m_hIcon;
  105. }
  106.  
  107. BEGIN_EVENTSINK_MAP(CTextDemoDlg, CDialog)
  108.     //{{AFX_EVENTSINK_MAP(CTextDemoDlg)
  109.     ON_EVENT(CTextDemoDlg, IDC_STOPGO, -605 /* MouseDown */, OnMouseDownStopgo, VTS_I2 VTS_I2 VTS_I4 VTS_I4)
  110.     ON_EVENT(CTextDemoDlg, IDC_STOPGO, -607 /* MouseUp */, OnMouseUpStopgo, VTS_I2 VTS_I2 VTS_I4 VTS_I4)
  111.     //}}AFX_EVENTSINK_MAP
  112. END_EVENTSINK_MAP()
  113.  
  114. void CTextDemoDlg::OnTextonframe() 
  115. {
  116.     //----------------------------------
  117.     // get opposite to a current value of the property 
  118.     // TextOnFrame of any Text3D control
  119.     BOOL fOnFrame = !((CText3D*)GetDlgItem(IDC_PLANE))->GetTextOnFrame();
  120.     //----------------------------------
  121.     // set properties TextOnFrame to opposite
  122.     ((CText3D*)GetDlgItem(IDC_PLANE))->SetTextOnFrame(fOnFrame);
  123.     ((CText3D*)GetDlgItem(IDC_INDENT))->SetTextOnFrame(fOnFrame);
  124.     ((CText3D*)GetDlgItem(IDC_OUTDENT))->SetTextOnFrame(fOnFrame);
  125.     ((CText3D*)GetDlgItem(IDC_SUNKEN))->SetTextOnFrame(fOnFrame);
  126.     ((CText3D*)GetDlgItem(IDC_RAISED))->SetTextOnFrame(fOnFrame);
  127.     ((CText3D*)GetDlgItem(IDC_PICTURE))->SetTextOnFrame(fOnFrame);
  128.     ((CText3D*)GetDlgItem(IDC_FRAME))->SetTextOnFrame(fOnFrame);
  129.     ((CText3D*)GetDlgItem(IDC_SHARP))->SetTextOnFrame(fOnFrame);
  130. }
  131.  
  132. void CTextDemoDlg::OnShadow() 
  133. {
  134.     //----------------------------------
  135.     // get opposite to a current value of the property 
  136.     // FrameShadow of any Text3D control
  137.     BOOL fShadow = !((CText3D*)GetDlgItem(IDC_PLANE))->GetFrameShadow();
  138.     //----------------------------------
  139.     // set properties FrameShadow to opposite
  140.     ((CText3D*)GetDlgItem(IDC_PLANE))->SetFrameShadow(fShadow);
  141.     ((CText3D*)GetDlgItem(IDC_INDENT))->SetFrameShadow(fShadow);
  142.     ((CText3D*)GetDlgItem(IDC_OUTDENT))->SetFrameShadow(fShadow);
  143.     ((CText3D*)GetDlgItem(IDC_SUNKEN))->SetFrameShadow(fShadow);
  144.     ((CText3D*)GetDlgItem(IDC_RAISED))->SetFrameShadow(fShadow);
  145.     ((CText3D*)GetDlgItem(IDC_PICTURE))->SetFrameShadow(fShadow);
  146.     ((CText3D*)GetDlgItem(IDC_FRAME))->SetFrameShadow(fShadow);
  147.     ((CText3D*)GetDlgItem(IDC_SHARP))->SetFrameShadow(fShadow);
  148. }
  149.  
  150. void CTextDemoDlg::OnSelchangeFramecolor() 
  151. {
  152.     //----------------------------------
  153.     // get FrameColor combobox selection
  154.     short sColor = ((CComboBox*)GetDlgItem(IDC_FRAMECOLOR))->GetCurSel();
  155.     //----------------------------------
  156.     // set FrameColor to sColor
  157.     ((CText3D*)GetDlgItem(IDC_PLANE))->SetFrameColor(sColor);
  158.     ((CText3D*)GetDlgItem(IDC_INDENT))->SetFrameColor(sColor);
  159.     ((CText3D*)GetDlgItem(IDC_OUTDENT))->SetFrameColor(sColor);
  160.     ((CText3D*)GetDlgItem(IDC_SUNKEN))->SetFrameColor(sColor);
  161.     ((CText3D*)GetDlgItem(IDC_RAISED))->SetFrameColor(sColor);
  162.     ((CText3D*)GetDlgItem(IDC_PICTURE))->SetFrameColor(sColor);
  163.     ((CText3D*)GetDlgItem(IDC_FRAME))->SetFrameColor(sColor);
  164.     ((CText3D*)GetDlgItem(IDC_SHARP))->SetFrameColor(sColor);
  165. }
  166.  
  167. void CTextDemoDlg::OnMouseDownStopgo(short Button, short Shift, long x, long y) 
  168. {
  169.     CText3D *stopGo = (CText3D*)GetDlgItem(IDC_STOPGO);
  170.     //----------------------------------------
  171.     // create sunking effect on mouse down for frame
  172.     // and for text
  173.     stopGo->SetFrameStyle(39);
  174.     stopGo->SetForeColor(RGB(0xc0, 0xc0, 0xc0));
  175.     stopGo->SetHighlightColor((COLORREF)0);
  176. }
  177.  
  178. void CTextDemoDlg::OnMouseUpStopgo(short Button, short Shift, long x, long y) 
  179. {
  180.     //---------------------------------------
  181.     // start or kill timer
  182.     if(!KillTimer(TIMER_ID))
  183.         SetTimer(TIMER_ID, 1000, NULL);
  184.     //---------------------------------------
  185.     // get pointer to the Stop/Go "button" (Text3D control)
  186.     CText3D *stopGo = (CText3D*)GetDlgItem(IDC_STOPGO);
  187.     //---------------------------------------
  188.     // pop up back the frame style and text appearance
  189.     // after they were sunk onMouseDown()
  190.     stopGo->SetFrameStyle(49);
  191.     stopGo->SetForeColor(RGB(0, 0, 0));
  192.     stopGo->SetHighlightColor(0x00ffffff);
  193.     //---------------------------------------
  194.     // change text from Stop to Go 
  195.     // and change backcolor from red to purple
  196.     // or otherwise
  197.     if(*(LPSTR)(LPCTSTR)stopGo->GetText() == 'S')
  198.     {
  199.         stopGo->SetText("Go");
  200.         stopGo->SetBackColor(RGB(255,0,255));
  201.     }
  202.     else
  203.     {
  204.         stopGo->SetText("Stop");
  205.         stopGo->SetBackColor((COLORREF)0xff);
  206.     }
  207. }
  208.  
  209. void CTextDemoDlg::OnTimer(UINT nIDEvent) 
  210. {
  211.     CDialog::OnTimer(nIDEvent);
  212.     if(nIDEvent != TIMER_ID) return;
  213.     char szStr[12];
  214.     //--------------------------------
  215.     // create loop of m_uTimer ==> 0..9
  216.     if(++m_uTimer > 9) m_uTimer = 0;
  217.  
  218.     //--------------------------------
  219.     // build texts and set frames using m_uTimer
  220.     ((CText3D*)GetDlgItem(IDC_PLANE))->SetFrameStyle(1 + m_uTimer);
  221.     GetDlgItemText(IDC_PLANE, szStr, 10);
  222.     //--------------------------------
  223.     // replace the last character in the text 
  224.     // on the character-digit equal to m_uTimer
  225.     szStr[lstrlen(szStr) - 1] = '0' + m_uTimer;
  226.     SetDlgItemText(IDC_PLANE, szStr);
  227.  
  228.     ((CText3D*)GetDlgItem(IDC_INDENT))->SetFrameStyle(11 + m_uTimer);
  229.     GetDlgItemText(IDC_INDENT, szStr, 10);
  230.     szStr[lstrlen(szStr) - 1] = '0' + m_uTimer;
  231.     SetDlgItemText(IDC_INDENT, szStr);
  232.     
  233.     ((CText3D*)GetDlgItem(IDC_OUTDENT))->SetFrameStyle(21 + m_uTimer);
  234.     GetDlgItemText(IDC_OUTDENT, szStr, 10);
  235.     szStr[lstrlen(szStr) - 1] = '0' + m_uTimer;
  236.     SetDlgItemText(IDC_OUTDENT, szStr);
  237.     
  238.     ((CText3D*)GetDlgItem(IDC_SUNKEN))->SetFrameStyle(31 + m_uTimer);
  239.     GetDlgItemText(IDC_SUNKEN, szStr, 10);
  240.     szStr[lstrlen(szStr) - 1] = '0' + m_uTimer;
  241.     SetDlgItemText(IDC_SUNKEN, szStr);
  242.     
  243.     ((CText3D*)GetDlgItem(IDC_RAISED))->SetFrameStyle(41 + m_uTimer);
  244.     GetDlgItemText(IDC_RAISED, szStr, 10);
  245.     szStr[lstrlen(szStr) - 1] = '0' + m_uTimer;
  246.     SetDlgItemText(IDC_RAISED, szStr);
  247.     
  248.     ((CText3D*)GetDlgItem(IDC_PICTURE))->SetFrameStyle(51 + m_uTimer);
  249.     GetDlgItemText(IDC_PICTURE, szStr, 10);
  250.     szStr[lstrlen(szStr) - 1] = '0' + m_uTimer;
  251.     SetDlgItemText(IDC_PICTURE, szStr);
  252.     
  253.     ((CText3D*)GetDlgItem(IDC_FRAME))->SetFrameStyle(61 + m_uTimer);
  254.     GetDlgItemText(IDC_FRAME, szStr, 10);
  255.     szStr[lstrlen(szStr) - 1] = '0' + m_uTimer;
  256.     SetDlgItemText(IDC_FRAME, szStr);
  257.     
  258.     ((CText3D*)GetDlgItem(IDC_SHARP))->SetFrameStyle(71 + m_uTimer);
  259.     GetDlgItemText(IDC_SHARP, szStr, 10);
  260.     szStr[lstrlen(szStr) - 1] = '0' + m_uTimer;
  261.     SetDlgItemText(IDC_SHARP, szStr);
  262. }
  263.  
  264.  
  265. void CTextDemoDlg::OnDestroy() 
  266. {
  267.     KillTimer(TIMER_ID);
  268.     CDialog::OnDestroy();
  269. }
  270.