home *** CD-ROM | disk | FTP | other *** search
- // TextDlg.cpp : implementation file
- //
-
- #include "stdafx.h"
- #include "TextDemo.h"
- #include "TextDlg.h"
- #include "Text3D.h"
-
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
-
- #define TIMER_ID 1234
-
- /////////////////////////////////////////////////////////////////////////////
- // CTextDemoDlg dialog
-
- CTextDemoDlg::CTextDemoDlg(CWnd* pParent /*=NULL*/)
- : CDialog(CTextDemoDlg::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CTextDemoDlg)
- // NOTE: the ClassWizard will add member initialization here
- //}}AFX_DATA_INIT
- // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
- m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
- }
-
- void CTextDemoDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CTextDemoDlg)
- // NOTE: the ClassWizard will add DDX and DDV calls here
- //}}AFX_DATA_MAP
- }
-
- BEGIN_MESSAGE_MAP(CTextDemoDlg, CDialog)
- //{{AFX_MSG_MAP(CTextDemoDlg)
- ON_WM_PAINT()
- ON_WM_QUERYDRAGICON()
- ON_BN_CLICKED(IDC_TEXTONFRAME, OnTextonframe)
- ON_BN_CLICKED(IDC_SHADOW, OnShadow)
- ON_WM_TIMER()
- ON_CBN_SELCHANGE(IDC_FRAMECOLOR, OnSelchangeFramecolor)
- ON_WM_DESTROY()
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
-
- /////////////////////////////////////////////////////////////////////////////
- // CTextDemoDlg message handlers
-
- BOOL CTextDemoDlg::OnInitDialog()
- {
- CDialog::OnInitDialog();
-
- // Set the icon for this dialog. The framework does this automatically
- // when the application's main window is not a dialog
- SetIcon(m_hIcon, TRUE); // Set big icon
- SetIcon(m_hIcon, FALSE); // Set small icon
-
- // TODO: Add extra initialization here
- SetTimer(TIMER_ID, 1000, NULL);
- m_uTimer = 0;
- ((CComboBox*)GetDlgItem(IDC_FRAMECOLOR))->SetCurSel(0);
-
-
- return TRUE; // return TRUE unless you set the focus to a control
- }
-
- // If you add a minimize button to your dialog, you will need the code below
- // to draw the icon. For MFC applications using the document/view model,
- // this is automatically done for you by the framework.
-
- void CTextDemoDlg::OnPaint()
- {
- if (IsIconic())
- {
- CPaintDC dc(this); // device context for painting
-
- SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
-
- // Center icon in client rectangle
- int cxIcon = GetSystemMetrics(SM_CXICON);
- int cyIcon = GetSystemMetrics(SM_CYICON);
- CRect rect;
- GetClientRect(&rect);
- int x = (rect.Width() - cxIcon + 1) / 2;
- int y = (rect.Height() - cyIcon + 1) / 2;
-
- // Draw the icon
- dc.DrawIcon(x, y, m_hIcon);
- }
- else
- {
- CDialog::OnPaint();
- }
- }
-
- // The system calls this to obtain the cursor to display while the user drags
- // the minimized window.
- HCURSOR CTextDemoDlg::OnQueryDragIcon()
- {
- return (HCURSOR) m_hIcon;
- }
-
- BEGIN_EVENTSINK_MAP(CTextDemoDlg, CDialog)
- //{{AFX_EVENTSINK_MAP(CTextDemoDlg)
- ON_EVENT(CTextDemoDlg, IDC_STOPGO, -605 /* MouseDown */, OnMouseDownStopgo, VTS_I2 VTS_I2 VTS_I4 VTS_I4)
- ON_EVENT(CTextDemoDlg, IDC_STOPGO, -607 /* MouseUp */, OnMouseUpStopgo, VTS_I2 VTS_I2 VTS_I4 VTS_I4)
- //}}AFX_EVENTSINK_MAP
- END_EVENTSINK_MAP()
-
- void CTextDemoDlg::OnTextonframe()
- {
- //----------------------------------
- // get opposite to a current value of the property
- // TextOnFrame of any Text3D control
- BOOL fOnFrame = !((CText3D*)GetDlgItem(IDC_PLANE))->GetTextOnFrame();
- //----------------------------------
- // set properties TextOnFrame to opposite
- ((CText3D*)GetDlgItem(IDC_PLANE))->SetTextOnFrame(fOnFrame);
- ((CText3D*)GetDlgItem(IDC_INDENT))->SetTextOnFrame(fOnFrame);
- ((CText3D*)GetDlgItem(IDC_OUTDENT))->SetTextOnFrame(fOnFrame);
- ((CText3D*)GetDlgItem(IDC_SUNKEN))->SetTextOnFrame(fOnFrame);
- ((CText3D*)GetDlgItem(IDC_RAISED))->SetTextOnFrame(fOnFrame);
- ((CText3D*)GetDlgItem(IDC_PICTURE))->SetTextOnFrame(fOnFrame);
- ((CText3D*)GetDlgItem(IDC_FRAME))->SetTextOnFrame(fOnFrame);
- ((CText3D*)GetDlgItem(IDC_SHARP))->SetTextOnFrame(fOnFrame);
- }
-
- void CTextDemoDlg::OnShadow()
- {
- //----------------------------------
- // get opposite to a current value of the property
- // FrameShadow of any Text3D control
- BOOL fShadow = !((CText3D*)GetDlgItem(IDC_PLANE))->GetFrameShadow();
- //----------------------------------
- // set properties FrameShadow to opposite
- ((CText3D*)GetDlgItem(IDC_PLANE))->SetFrameShadow(fShadow);
- ((CText3D*)GetDlgItem(IDC_INDENT))->SetFrameShadow(fShadow);
- ((CText3D*)GetDlgItem(IDC_OUTDENT))->SetFrameShadow(fShadow);
- ((CText3D*)GetDlgItem(IDC_SUNKEN))->SetFrameShadow(fShadow);
- ((CText3D*)GetDlgItem(IDC_RAISED))->SetFrameShadow(fShadow);
- ((CText3D*)GetDlgItem(IDC_PICTURE))->SetFrameShadow(fShadow);
- ((CText3D*)GetDlgItem(IDC_FRAME))->SetFrameShadow(fShadow);
- ((CText3D*)GetDlgItem(IDC_SHARP))->SetFrameShadow(fShadow);
- }
-
- void CTextDemoDlg::OnSelchangeFramecolor()
- {
- //----------------------------------
- // get FrameColor combobox selection
- short sColor = ((CComboBox*)GetDlgItem(IDC_FRAMECOLOR))->GetCurSel();
- //----------------------------------
- // set FrameColor to sColor
- ((CText3D*)GetDlgItem(IDC_PLANE))->SetFrameColor(sColor);
- ((CText3D*)GetDlgItem(IDC_INDENT))->SetFrameColor(sColor);
- ((CText3D*)GetDlgItem(IDC_OUTDENT))->SetFrameColor(sColor);
- ((CText3D*)GetDlgItem(IDC_SUNKEN))->SetFrameColor(sColor);
- ((CText3D*)GetDlgItem(IDC_RAISED))->SetFrameColor(sColor);
- ((CText3D*)GetDlgItem(IDC_PICTURE))->SetFrameColor(sColor);
- ((CText3D*)GetDlgItem(IDC_FRAME))->SetFrameColor(sColor);
- ((CText3D*)GetDlgItem(IDC_SHARP))->SetFrameColor(sColor);
- }
-
- void CTextDemoDlg::OnMouseDownStopgo(short Button, short Shift, long x, long y)
- {
- CText3D *stopGo = (CText3D*)GetDlgItem(IDC_STOPGO);
- //----------------------------------------
- // create sunking effect on mouse down for frame
- // and for text
- stopGo->SetFrameStyle(39);
- stopGo->SetForeColor(RGB(0xc0, 0xc0, 0xc0));
- stopGo->SetHighlightColor((COLORREF)0);
- }
-
- void CTextDemoDlg::OnMouseUpStopgo(short Button, short Shift, long x, long y)
- {
- //---------------------------------------
- // start or kill timer
- if(!KillTimer(TIMER_ID))
- SetTimer(TIMER_ID, 1000, NULL);
- //---------------------------------------
- // get pointer to the Stop/Go "button" (Text3D control)
- CText3D *stopGo = (CText3D*)GetDlgItem(IDC_STOPGO);
- //---------------------------------------
- // pop up back the frame style and text appearance
- // after they were sunk onMouseDown()
- stopGo->SetFrameStyle(49);
- stopGo->SetForeColor(RGB(0, 0, 0));
- stopGo->SetHighlightColor(0x00ffffff);
- //---------------------------------------
- // change text from Stop to Go
- // and change backcolor from red to purple
- // or otherwise
- if(*(LPSTR)(LPCTSTR)stopGo->GetText() == 'S')
- {
- stopGo->SetText("Go");
- stopGo->SetBackColor(RGB(255,0,255));
- }
- else
- {
- stopGo->SetText("Stop");
- stopGo->SetBackColor((COLORREF)0xff);
- }
- }
-
- void CTextDemoDlg::OnTimer(UINT nIDEvent)
- {
- CDialog::OnTimer(nIDEvent);
- if(nIDEvent != TIMER_ID) return;
- char szStr[12];
- //--------------------------------
- // create loop of m_uTimer ==> 0..9
- if(++m_uTimer > 9) m_uTimer = 0;
-
- //--------------------------------
- // build texts and set frames using m_uTimer
- ((CText3D*)GetDlgItem(IDC_PLANE))->SetFrameStyle(1 + m_uTimer);
- GetDlgItemText(IDC_PLANE, szStr, 10);
- //--------------------------------
- // replace the last character in the text
- // on the character-digit equal to m_uTimer
- szStr[lstrlen(szStr) - 1] = '0' + m_uTimer;
- SetDlgItemText(IDC_PLANE, szStr);
-
- ((CText3D*)GetDlgItem(IDC_INDENT))->SetFrameStyle(11 + m_uTimer);
- GetDlgItemText(IDC_INDENT, szStr, 10);
- szStr[lstrlen(szStr) - 1] = '0' + m_uTimer;
- SetDlgItemText(IDC_INDENT, szStr);
-
- ((CText3D*)GetDlgItem(IDC_OUTDENT))->SetFrameStyle(21 + m_uTimer);
- GetDlgItemText(IDC_OUTDENT, szStr, 10);
- szStr[lstrlen(szStr) - 1] = '0' + m_uTimer;
- SetDlgItemText(IDC_OUTDENT, szStr);
-
- ((CText3D*)GetDlgItem(IDC_SUNKEN))->SetFrameStyle(31 + m_uTimer);
- GetDlgItemText(IDC_SUNKEN, szStr, 10);
- szStr[lstrlen(szStr) - 1] = '0' + m_uTimer;
- SetDlgItemText(IDC_SUNKEN, szStr);
-
- ((CText3D*)GetDlgItem(IDC_RAISED))->SetFrameStyle(41 + m_uTimer);
- GetDlgItemText(IDC_RAISED, szStr, 10);
- szStr[lstrlen(szStr) - 1] = '0' + m_uTimer;
- SetDlgItemText(IDC_RAISED, szStr);
-
- ((CText3D*)GetDlgItem(IDC_PICTURE))->SetFrameStyle(51 + m_uTimer);
- GetDlgItemText(IDC_PICTURE, szStr, 10);
- szStr[lstrlen(szStr) - 1] = '0' + m_uTimer;
- SetDlgItemText(IDC_PICTURE, szStr);
-
- ((CText3D*)GetDlgItem(IDC_FRAME))->SetFrameStyle(61 + m_uTimer);
- GetDlgItemText(IDC_FRAME, szStr, 10);
- szStr[lstrlen(szStr) - 1] = '0' + m_uTimer;
- SetDlgItemText(IDC_FRAME, szStr);
-
- ((CText3D*)GetDlgItem(IDC_SHARP))->SetFrameStyle(71 + m_uTimer);
- GetDlgItemText(IDC_SHARP, szStr, 10);
- szStr[lstrlen(szStr) - 1] = '0' + m_uTimer;
- SetDlgItemText(IDC_SHARP, szStr);
- }
-
-
- void CTextDemoDlg::OnDestroy()
- {
- KillTimer(TIMER_ID);
- CDialog::OnDestroy();
- }
-