CEZSnakeDlgDemoDlg.cpp
上传用户:cqzhuye
上传日期:2007-01-01
资源大小:72k
文件大小:6k
- // CEZSnakeDlgDemoDlg.cpp : implementation file
- //
- #include "stdafx.h"
- #include "CEZSnakeDlgDemo.h"
- #include "CEZSnakeDlgDemoDlg.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CAboutDlg dialog used for App About
- class CAboutDlg : public CDialog
- {
- public:
- CAboutDlg();
- // Dialog Data
- //{{AFX_DATA(CAboutDlg)
- enum { IDD = IDD_ABOUTBOX };
- //}}AFX_DATA
- // ClassWizard generated virtual function overrides
- //{{AFX_VIRTUAL(CAboutDlg)
- protected:
- virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
- //}}AFX_VIRTUAL
- // Implementation
- protected:
- //{{AFX_MSG(CAboutDlg)
- //}}AFX_MSG
- DECLARE_MESSAGE_MAP()
- };
- CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
- {
- //{{AFX_DATA_INIT(CAboutDlg)
- //}}AFX_DATA_INIT
- }
- void CAboutDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CAboutDlg)
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
- //{{AFX_MSG_MAP(CAboutDlg)
- // No message handlers
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CCEZSnakeDlgDemoDlg dialog
- CCEZSnakeDlgDemoDlg::CCEZSnakeDlgDemoDlg(CWnd* pParent /*=NULL*/)
- : CDialog(CCEZSnakeDlgDemoDlg::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CCEZSnakeDlgDemoDlg)
- m_nMax = 0;
- m_nSize = 0;
- m_nStep = 0;
- //}}AFX_DATA_INIT
- // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
- m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
- }
- void CCEZSnakeDlgDemoDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CCEZSnakeDlgDemoDlg)
- DDX_Control(pDX, IDC_RESET, m_wndReset);
- DDX_Control(pDX, IDC_START, m_wndStart);
- DDX_Control(pDX, IDOK, m_wndOk);
- DDX_Control(pDX, IDC_SNAKE, m_wndSnake);
- DDX_Control(pDX, IDC_COLOR_START, m_wndClrStart);
- DDX_Control(pDX, IDC_COLOR_BACK, m_wndClrBk);
- DDX_Control(pDX, IDC_COLOR_END, m_wndClrEnd);
- DDX_Text(pDX, IDC_MAX, m_nMax);
- DDX_Text(pDX, IDC_SNAKESIZE, m_nSize);
- DDX_Text(pDX, IDC_STEP, m_nStep);
- //}}AFX_DATA_MAP
- DDX_ColourPicker(pDX, IDC_COLOR_START, m_clrStart);
- DDX_ColourPicker(pDX, IDC_COLOR_END, m_clrEnd);
- DDX_ColourPicker(pDX, IDC_COLOR_BACK, m_clrBk);
- }
- BEGIN_MESSAGE_MAP(CCEZSnakeDlgDemoDlg, CDialog)
- //{{AFX_MSG_MAP(CCEZSnakeDlgDemoDlg)
- ON_WM_SYSCOMMAND()
- ON_WM_PAINT()
- ON_WM_QUERYDRAGICON()
- ON_BN_CLICKED(IDC_START, OnStart)
- ON_BN_CLICKED(IDC_STOP, OnStop)
- ON_BN_CLICKED(IDC_RESET, OnReset)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CCEZSnakeDlgDemoDlg message handlers
- BOOL CCEZSnakeDlgDemoDlg::OnInitDialog()
- {
- CDialog::OnInitDialog();
- // Add "About..." menu item to system menu.
- // IDM_ABOUTBOX must be in the system command range.
- ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
- ASSERT(IDM_ABOUTBOX < 0xF000);
- CMenu* pSysMenu = GetSystemMenu(FALSE);
- if (pSysMenu != NULL)
- {
- CString strAboutMenu;
- strAboutMenu.LoadString(IDS_ABOUTBOX);
- if (!strAboutMenu.IsEmpty())
- {
- pSysMenu->AppendMenu(MF_SEPARATOR);
- pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
- }
- }
- // 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
- m_bStop=TRUE;
- m_clrBk=m_wndSnake.GetBkColor();
- m_clrStart=m_wndSnake.GetGradientStartColor();
- m_clrEnd=m_wndSnake.GetGradientEndColor();
- m_nMax=m_wndSnake.GetMax();
- m_nSize=m_wndSnake.GetSize();
- m_nStep=m_wndSnake.GetStep();
- UpdateData(FALSE);
-
- return TRUE; // return TRUE unless you set the focus to a control
- }
- void CCEZSnakeDlgDemoDlg::OnSysCommand(UINT nID, LPARAM lParam)
- {
- if ((nID & 0xFFF0) == IDM_ABOUTBOX)
- {
- CAboutDlg dlgAbout;
- dlgAbout.DoModal();
- }
- else
- {
- CDialog::OnSysCommand(nID, lParam);
- }
- }
- // 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 CCEZSnakeDlgDemoDlg::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 CCEZSnakeDlgDemoDlg::OnQueryDragIcon()
- {
- return (HCURSOR) m_hIcon;
- }
- void CCEZSnakeDlgDemoDlg::OnStart()
- {
- UpdateData(TRUE);
- DisableControls();
- m_wndSnake.SetBkColor(m_clrBk);
- m_wndSnake.SetGradientFill(m_clrStart,m_clrEnd);
- m_wndSnake.SetSize(m_nSize);
- m_wndSnake.SetMax(m_nMax);
- m_wndSnake.SetStep(m_nStep);
- m_bStop=FALSE;
- while(!m_bStop)
- {
- Sleep(10);
- MSG msg;
- if(::PeekMessage(&msg,m_hWnd,0,0,TRUE))
- {
- ::TranslateMessage(&msg);
- ::DispatchMessage(&msg);
- }
- m_wndSnake.StepIt();
- }
-
-
- }
- void CCEZSnakeDlgDemoDlg::OnStop()
- {
- m_bStop=TRUE;
- EnableControls();
-
- }
- void CCEZSnakeDlgDemoDlg::DisableControls()
- {
- m_wndOk.EnableWindow(FALSE);
- m_wndStart.EnableWindow(FALSE);
- m_wndClrBk.EnableWindow(FALSE);
- m_wndClrEnd.EnableWindow(FALSE);
- m_wndClrStart.EnableWindow(FALSE);
- m_wndReset.EnableWindow(FALSE);
- }
- void CCEZSnakeDlgDemoDlg::EnableControls()
- {
- m_wndOk.EnableWindow();
- m_wndStart.EnableWindow();
- m_wndClrBk.EnableWindow();
- m_wndClrEnd.EnableWindow();
- m_wndClrStart.EnableWindow();
- m_wndReset.EnableWindow();
- }
- void CCEZSnakeDlgDemoDlg::OnReset()
- {
- m_wndSnake.ResetProgress();
- }