home *** CD-ROM | disk | FTP | other *** search
/ Mastering Visual Basic 5 / MasteringVisualBasic5.iso / protview / demowinx / data.2 / marquee / samples / MFC / TICKER / TICKER~1.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1996-10-17  |  5.0 KB  |  220 lines

  1. // tickerDlg.cpp : implementation file
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "ticker.h"
  6. #include "tickerDlg.h"
  7. #include "colors.h"
  8. #include "tkfont.h"
  9. #include "image.h"
  10. #include "tknext.h"
  11. #include "ttkm.h"
  12.  
  13. #ifdef _DEBUG
  14. #define new DEBUG_NEW
  15. #undef THIS_FILE
  16. static char THIS_FILE[] = __FILE__;
  17. #endif
  18.  
  19. /////////////////////////////////////////////////////////////////////////////
  20. // CAboutDlg dialog used for App About
  21.  
  22. class CAboutDlg : public CDialog
  23. {
  24. public:
  25.     CAboutDlg();
  26.  
  27. // Dialog Data
  28.     //{{AFX_DATA(CAboutDlg)
  29.     enum { IDD = IDD_ABOUTBOX };
  30.     //}}AFX_DATA
  31.  
  32.     // ClassWizard generated virtual function overrides
  33.     //{{AFX_VIRTUAL(CAboutDlg)
  34.     protected:
  35.     virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
  36.     //}}AFX_VIRTUAL
  37.  
  38. // Implementation
  39. protected:
  40.     //{{AFX_MSG(CAboutDlg)
  41.     //}}AFX_MSG
  42.     DECLARE_MESSAGE_MAP()
  43. };
  44.  
  45. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  46. {
  47.     //{{AFX_DATA_INIT(CAboutDlg)
  48.     //}}AFX_DATA_INIT
  49. }
  50.  
  51. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  52. {
  53.     CDialog::DoDataExchange(pDX);
  54.     //{{AFX_DATA_MAP(CAboutDlg)
  55.     //}}AFX_DATA_MAP
  56. }
  57.  
  58. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  59.     //{{AFX_MSG_MAP(CAboutDlg)
  60.         // No message handlers
  61.     //}}AFX_MSG_MAP
  62. END_MESSAGE_MAP()
  63.  
  64. /////////////////////////////////////////////////////////////////////////////
  65. // CTickerDlg dialog
  66.  
  67. CTickerDlg::CTickerDlg(CWnd* pParent /*=NULL*/)
  68.     : CDialog(CTickerDlg::IDD, pParent)
  69. {
  70.     //{{AFX_DATA_INIT(CTickerDlg)
  71.         // NOTE: the ClassWizard will add member initialization here
  72.     //}}AFX_DATA_INIT
  73.     // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
  74.     m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  75. }
  76.  
  77. void CTickerDlg::DoDataExchange(CDataExchange* pDX)
  78. {
  79.     CDialog::DoDataExchange(pDX);
  80.     //{{AFX_DATA_MAP(CTickerDlg)
  81.     DDX_Control(pDX, IDC_TICKERCTRL1, m_tk1);
  82.     DDX_Control(pDX, IDC_TICKERCTRL2, m_tk2);
  83.     DDX_Control(pDX, IDC_TICKERCTRL3, m_tk3);
  84.     DDX_Control(pDX, IDC_TICKERCTRL4, m_tk4);
  85.     //}}AFX_DATA_MAP
  86. }
  87.  
  88. BEGIN_MESSAGE_MAP(CTickerDlg, CDialog)
  89.     //{{AFX_MSG_MAP(CTickerDlg)
  90.     ON_WM_SYSCOMMAND()
  91.     ON_WM_PAINT()
  92.     ON_WM_QUERYDRAGICON()
  93.     ON_BN_CLICKED(IDC_FREEZE, OnFreeze)
  94.     ON_BN_CLICKED(IDC_MARQUEE, OnMarquee)
  95.     ON_BN_CLICKED(IDC_FONT, OnFont)
  96.     ON_BN_CLICKED(IDC_COLOR, OnColor)
  97.     ON_BN_CLICKED(IDC_PICTURE, OnPicture)
  98.     ON_BN_CLICKED(ID_NEXT, OnNext)
  99.     //}}AFX_MSG_MAP
  100. END_MESSAGE_MAP()
  101.  
  102. /////////////////////////////////////////////////////////////////////////////
  103. // CTickerDlg message handlers
  104.  
  105. BOOL CTickerDlg::OnInitDialog()
  106. {
  107.     CDialog::OnInitDialog();
  108.  
  109.     // Add "About..." menu item to system menu.
  110.  
  111.     // IDM_ABOUTBOX must be in the system command range.
  112.     ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
  113.     ASSERT(IDM_ABOUTBOX < 0xF000);
  114.  
  115.     CMenu* pSysMenu = GetSystemMenu(FALSE);
  116.     CString strAboutMenu;
  117.     strAboutMenu.LoadString(IDS_ABOUTBOX);
  118.     if (!strAboutMenu.IsEmpty())
  119.     {
  120.         pSysMenu->AppendMenu(MF_SEPARATOR);
  121.         pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
  122.     }
  123.  
  124.     // Set the icon for this dialog.  The framework does this automatically
  125.     //  when the application's main window is not a dialog
  126.     SetIcon(m_hIcon, TRUE);            // Set big icon
  127.     SetIcon(m_hIcon, FALSE);        // Set small icon
  128.     
  129.     // TODO: Add extra initialization here
  130.     
  131.     return TRUE;  // return TRUE  unless you set the focus to a control
  132. }
  133.  
  134. void CTickerDlg::OnSysCommand(UINT nID, LPARAM lParam)
  135. {
  136.     if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  137.     {
  138.         CAboutDlg dlgAbout;
  139.         dlgAbout.DoModal();
  140.     }
  141.     else
  142.     {
  143.         CDialog::OnSysCommand(nID, lParam);
  144.     }
  145. }
  146.  
  147. // If you add a minimize button to your dialog, you will need the code below
  148. //  to draw the icon.  For MFC applications using the document/view model,
  149. //  this is automatically done for you by the framework.
  150.  
  151. void CTickerDlg::OnPaint() 
  152. {
  153.     if (IsIconic())
  154.     {
  155.         CPaintDC dc(this); // device context for painting
  156.  
  157.         SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  158.  
  159.         // Center icon in client rectangle
  160.         int cxIcon = GetSystemMetrics(SM_CXICON);
  161.         int cyIcon = GetSystemMetrics(SM_CYICON);
  162.         CRect rect;
  163.         GetClientRect(&rect);
  164.         int x = (rect.Width() - cxIcon + 1) / 2;
  165.         int y = (rect.Height() - cyIcon + 1) / 2;
  166.  
  167.         // Draw the icon
  168.         dc.DrawIcon(x, y, m_hIcon);
  169.     }
  170.     else
  171.     {
  172.         CDialog::OnPaint();
  173.     }
  174. }
  175.  
  176. // The system calls this to obtain the cursor to display while the user drags
  177. //  the minimized window.
  178. HCURSOR CTickerDlg::OnQueryDragIcon()
  179. {
  180.     return (HCURSOR) m_hIcon;
  181. }
  182.  
  183. void CTickerDlg::OnFreeze() 
  184. {
  185.    m_tk1.SetFreezeMarquee(TRUE);
  186.    m_tk2.SetFreezeMarquee(TRUE);
  187.    m_tk3.SetFreezeMarquee(TRUE);
  188.    m_tk4.SetFreezeMarquee(TRUE);
  189. }
  190.  
  191. void CTickerDlg::OnMarquee() 
  192. {
  193.    TtkM Dlg(this);
  194.    Dlg.DoModal();    
  195. }
  196.  
  197. void CTickerDlg::OnFont() 
  198. {
  199.    TkFont Dlg(this);
  200.    Dlg.DoModal();    
  201. }
  202.  
  203. void CTickerDlg::OnColor() 
  204. {
  205.    Colors Dlg(this);
  206.    Dlg.DoModal();    
  207. }
  208.  
  209. void CTickerDlg::OnPicture() 
  210. {
  211.    Image Dlg(this);
  212.    Dlg.DoModal();    
  213. }
  214.  
  215. void CTickerDlg::OnNext() 
  216. {
  217.    TkNext Dlg(this);
  218.    Dlg.DoModal();    
  219. }
  220.