Annotation of DewFind/DewFindDlg.cpp, revision 1.1

1.1     ! nick        1: // DewFindDlg.cpp : implementation file
        !             2: //
        !             3: 
        !             4: #include "stdafx.h"
        !             5: #include "DewFind.h"
        !             6: #include "DewFindDlg.h"
        !             7: #include "word.h"
        !             8: 
        !             9: #ifdef _DEBUG
        !            10: #define new DEBUG_NEW
        !            11: #endif
        !            12: 
        !            13: 
        !            14: // CAboutDlg dialog used for App About
        !            15: 
        !            16: class CAboutDlg : public CDialog
        !            17: {
        !            18: public:
        !            19:        CAboutDlg();
        !            20: 
        !            21: // Dialog Data
        !            22:        enum { IDD = IDD_ABOUTBOX };
        !            23: 
        !            24:        protected:
        !            25:        virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
        !            26: 
        !            27: // Implementation
        !            28: protected:
        !            29:        DECLARE_MESSAGE_MAP()
        !            30: };
        !            31: 
        !            32: CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
        !            33: {
        !            34: }
        !            35: 
        !            36: void CAboutDlg::DoDataExchange(CDataExchange* pDX)
        !            37: {
        !            38:        CDialog::DoDataExchange(pDX);
        !            39: }
        !            40: 
        !            41: BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
        !            42: END_MESSAGE_MAP()
        !            43: 
        !            44: 
        !            45: // CDewFindDlg dialog
        !            46: 
        !            47: 
        !            48: 
        !            49: CDewFindDlg::CDewFindDlg(CWnd* pParent /*=NULL*/)
        !            50:        : CDialog(CDewFindDlg::IDD, pParent)
        !            51: {
        !            52:        m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
        !            53: }
        !            54: 
        !            55: void CDewFindDlg::DoDataExchange(CDataExchange* pDX)
        !            56: {
        !            57:        CDialog::DoDataExchange(pDX);
        !            58: }
        !            59: 
        !            60: BEGIN_MESSAGE_MAP(CDewFindDlg, CDialog)
        !            61:        ON_WM_SYSCOMMAND()
        !            62:        ON_WM_PAINT()
        !            63:        ON_WM_QUERYDRAGICON()
        !            64:        //}}AFX_MSG_MAP
        !            65:        ON_WM_LBUTTONDOWN()
        !            66:        ON_WM_RBUTTONDOWN()
        !            67:        ON_COMMAND(ID_FILE_NEWGAME, OnFileNewgame)
        !            68:        ON_COMMAND(ID_FILE_QUITGAME, OnFileQuitgame)
        !            69: END_MESSAGE_MAP()
        !            70: 
        !            71: 
        !            72: // CDewFindDlg message handlers
        !            73: 
        !            74: BOOL CDewFindDlg::OnInitDialog()
        !            75: {
        !            76:        CDialog::OnInitDialog();
        !            77: 
        !            78:        // Add "About..." menu item to system menu.
        !            79: 
        !            80:        // IDM_ABOUTBOX must be in the system command range.
        !            81:        ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
        !            82:        ASSERT(IDM_ABOUTBOX < 0xF000);
        !            83: 
        !            84:        CMenu* pSysMenu = GetSystemMenu(FALSE);
        !            85:        if (pSysMenu != NULL)
        !            86:        {
        !            87:                CString strAboutMenu;
        !            88:                strAboutMenu.LoadString(IDS_ABOUTBOX);
        !            89:                if (!strAboutMenu.IsEmpty())
        !            90:                {
        !            91:                        pSysMenu->AppendMenu(MF_SEPARATOR);
        !            92:                        pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
        !            93:                }
        !            94:        }
        !            95: 
        !            96:        // Set the icon for this dialog.  The framework does this automatically
        !            97:        //  when the application's main window is not a dialog
        !            98:        SetIcon(m_hIcon, TRUE);                 // Set big icon
        !            99:        SetIcon(m_hIcon, FALSE);                // Set small icon
        !           100:        
        !           101:        srand(time(NULL));
        !           102:        gameboard_.ClearBoard();
        !           103:        gameboard_.ClearWords();
        !           104:        gameboard_.LoadWordsFromFile("words.txt");
        !           105:        gameboard_.SetUpBoard();
        !           106:        
        !           107:        return TRUE;  // return TRUE  unless you set the focus to a control
        !           108: }
        !           109: 
        !           110: void CDewFindDlg::OnSysCommand(UINT nID, LPARAM lParam)
        !           111: {
        !           112:        if ((nID & 0xFFF0) == IDM_ABOUTBOX)
        !           113:        {
        !           114:                CAboutDlg dlgAbout;
        !           115:                dlgAbout.DoModal();
        !           116:        }
        !           117:        else
        !           118:        {
        !           119:                CDialog::OnSysCommand(nID, lParam);
        !           120:        }
        !           121: }
        !           122: 
        !           123: // If you add a minimize button to your dialog, you will need the code below
        !           124: //  to draw the icon.  For MFC applications using the document/view model,
        !           125: //  this is automatically done for you by the framework.
        !           126: void CDewFindDlg::DrawScreen()
        !           127: {
        !           128:        Word wd;
        !           129:        CDC *xDC = GetDC();
        !           130:        gameboard_.DrawBoard(xDC);
        !           131:        gameboard_.DrawWords(xDC);
        !           132:        wd.SetColor(2);
        !           133:        wd.Write(gameboard_.GetWordsFound(),130,10,0,xDC);
        !           134:        wd.Write("/",169,10,xDC);
        !           135:        wd.Write(gameboard_.GetWordCount(),190,10,0,xDC);
        !           136: 
        !           137:        if (gameboard_.IsGameOver() == true)
        !           138:        {
        !           139:                wd.Write("Game Over!",360,10,xDC);
        !           140:        }
        !           141:     ReleaseDC(xDC);
        !           142: }
        !           143: 
        !           144: 
        !           145: void CDewFindDlg::OnPaint() 
        !           146: {
        !           147:        DrawScreen();
        !           148: 
        !           149:        if (IsIconic())
        !           150:        {
        !           151:                CPaintDC dc(this); // device context for painting
        !           152: 
        !           153:                SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
        !           154: 
        !           155:                // Center icon in client rectangle
        !           156:                int cxIcon = GetSystemMetrics(SM_CXICON);
        !           157:                int cyIcon = GetSystemMetrics(SM_CYICON);
        !           158:                CRect rect;
        !           159:                GetClientRect(&rect);
        !           160:                int x = (rect.Width() - cxIcon + 1) / 2;
        !           161:                int y = (rect.Height() - cyIcon + 1) / 2;
        !           162: 
        !           163:                // Draw the icon
        !           164:                dc.DrawIcon(x, y, m_hIcon);
        !           165:        }
        !           166:        else
        !           167:        {
        !           168:                CDialog::OnPaint();
        !           169:        }
        !           170: }
        !           171: 
        !           172: // The system calls this function to obtain the cursor to display while the user drags
        !           173: //  the minimized window.
        !           174: HCURSOR CDewFindDlg::OnQueryDragIcon()
        !           175: {
        !           176:        return static_cast<HCURSOR>(m_hIcon);
        !           177: }
        !           178: 
        !           179: void CDewFindDlg::OnLButtonDown(UINT nFlags, CPoint point)
        !           180: {
        !           181:        if (gameboard_.IsGameOver() == false)
        !           182:        {
        !           183:                if (gameboard_.SelectSquareMouse(point.x,point.y) == true)
        !           184:                {
        !           185:                        //Redraws the screen
        !           186:                        DrawScreen();
        !           187:                }
        !           188:        }
        !           189: 
        !           190:        CDialog::OnLButtonDown(nFlags, point);
        !           191: }
        !           192: 
        !           193: void CDewFindDlg::OnRButtonDown(UINT nFlags, CPoint point)
        !           194: {
        !           195:        //will clear selection coming soon!!!!
        !           196:        gameboard_.ClearSelected();
        !           197:        DrawScreen();
        !           198:        CDialog::OnRButtonDown(nFlags, point);
        !           199: }
        !           200: 
        !           201: 
        !           202: 
        !           203: void CDewFindDlg::OnFileNewgame()
        !           204: {
        !           205:        gameboard_.ClearBoard();
        !           206:        gameboard_.SetUpBoard();
        !           207:        Invalidate(true);
        !           208:        UpdateWindow();
        !           209:        DrawScreen();
        !           210: }
        !           211: 
        !           212: void CDewFindDlg::OnFileQuitgame()
        !           213: {
        !           214:        CDialog::OnCancel();
        !           215: }
        !           216: 
        !           217: BOOL CDewFindDlg::PreTranslateMessage(MSG* pMsg)
        !           218: {
        !           219:        // TODO: Add your specialized code here and/or call the base class
        !           220:        if (pMsg->message==WM_KEYDOWN)
        !           221:        {
        !           222:                switch(pMsg->wParam)
        !           223:                {
        !           224:                case VK_F8:
        !           225:                        OnFileNewgame();
        !           226:                        return true;
        !           227:                }
        !           228:        }
        !           229: 
        !           230:        return CDialog::PreTranslateMessage(pMsg);
        !           231: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>