FighterDlg.cpp
资源名称:Fly ight.zip [点击查看]
上传用户:baina_li
上传日期:2013-03-23
资源大小:960k
文件大小:64k
源码类别:
射击游戏
开发平台:
Visual C++
- // FighterDlg.cpp : implementation file
- //
- #include "stdafx.h"
- #include "Fighter.h"
- #include "mmsystem.h"
- #include "FighterDlg.h"
- #include "FighterInfo.h"
- #include "CongraduationDlg.h"
- #include "AboutPage.h"
- #include "RankPage.h"
- #include "SettingPage.h"
- #include "OperationPage.h"
- #include "BCMenu.h"
- #include "QuitDlg.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- HRGN BitmapToRegion(HBITMAP hBmp, COLORREF cTransparentColor = 0, COLORREF cTolerance = 0x101010);
- /*/////////////////////////////////////////////////////////////////////////////
- // 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()
- */
- /////////////////////////////////////////////////////////////////////////////
- // CFighterDlg dialog
- CFighterDlg::CFighterDlg(CWnd* pParent /*=NULL*/)
- : CDialog(CFighterDlg::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CFighterDlg)
- //}}AFX_DATA_INIT
- // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
- m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
- m_pPic = NULL;
- // m_pOldBitmap = NULL;
- m_bShowHandCursor = FALSE;
- m_bShowShootingCursor = FALSE;
- m_bLoadFrame = FALSE;
- m_bLoadWelcomeString = TRUE;
- m_bSound = TRUE;
- m_bByComputer = TRUE;
- m_bShow = TRUE;
- m_nFighterDown = 0;
- m_nFighterHit = 0;
- m_nBomb = 0;
- for(int i=0; i<10; i++)
- for(int j=0; j<10; j++)
- {
- m_nSky[i][j] = 0;
- m_nShootingResult[i][j] = 0;
- }
- m_rectSky = CRect(70, 54, 70+300, 54+300);
- m_ptNew = CPoint(m_rectSky.right+10, m_rectSky.top);
- m_rectCommentFrame = CRect(m_rectSky.right+20, m_rectSky.top+100, m_rectSky.right+132, m_rectSky.top+172);
- m_ptComment = CPoint(m_rectCommentFrame.left, m_rectCommentFrame.top);
- m_rectFighterDown = CRect(m_rectSky.right+20, m_rectCommentFrame.bottom+40, m_rectCommentFrame.right, m_rectCommentFrame.bottom+55);
- m_rectBomb = CRect(m_rectSky.right+20, m_rectCommentFrame.bottom+70, m_rectCommentFrame.right, m_rectCommentFrame.bottom+85);
- m_rectFighterHit = CRect(m_rectSky.right+20, m_rectCommentFrame.bottom+100, m_rectCommentFrame.right, m_rectCommentFrame.bottom+115);
- m_nCommentTimer = 0;
- m_nWelcomeTimer = 0;
- m_strComment5 = "";
- m_strComment4 = "";
- m_strComment3 = "";
- m_strComment2 = "";
- m_strComment1 = "";
- m_nGameStatus = FIGHTER_STOP;
- }
- CFighterDlg::~CFighterDlg()
- {
- // if(m_pOldBitmap)
- // {
- // memDC.SelectObject(m_pOldBitmap);
- // m_FrameBitmap.DeleteObject();
- // }
- }
- void CFighterDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CFighterDlg)
- DDX_Control(pDX, IDC_BUTTON_LOAD, m_ctrlLoad);
- DDX_Control(pDX, IDC_BUTTON_SAVE, m_ctrlSave);
- DDX_Control(pDX, IDC_BUTTON_QUIT, m_ctrlQuit);
- DDX_Control(pDX, IDC_BUTTON_OPTION, m_ctrlOption);
- DDX_Control(pDX, IDC_BUTTON_POSITION, m_ctrlPosition);
- DDX_Control(pDX, IDC_BUTTON_NEW, m_ctrlNew);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CFighterDlg, CDialog)
- //{{AFX_MSG_MAP(CFighterDlg)
- ON_WM_SYSCOMMAND()
- ON_WM_PAINT()
- ON_WM_QUERYDRAGICON()
- ON_WM_SETCURSOR()
- ON_WM_MOUSEMOVE()
- ON_WM_LBUTTONDOWN()
- ON_WM_LBUTTONDBLCLK()
- ON_WM_RBUTTONDOWN()
- ON_WM_TIMER()
- ON_WM_KEYDOWN()
- ON_COMMAND(ID_MENU_SHOW, OnMenuShow)
- ON_WM_DESTROY()
- ON_COMMAND(ID_MENU_LOAD, OnMenuLoad)
- ON_COMMAND(ID_MENU_QUIT, OnMenuQuit)
- ON_COMMAND(ID_MENU_SAVE, OnMenuSave)
- ON_COMMAND(ID_MENU_SOUND, OnMenuSound)
- ON_BN_CLICKED(IDC_BUTTON_NEW, OnButtonNew)
- ON_BN_CLICKED(IDC_BUTTON_LOAD, OnButtonLoad)
- ON_BN_CLICKED(IDC_BUTTON_OPTION, OnButtonOption)
- ON_BN_CLICKED(IDC_BUTTON_POSITION, OnButtonPosition)
- ON_BN_CLICKED(IDC_BUTTON_QUIT, OnButtonQuit)
- ON_BN_CLICKED(IDC_BUTTON_SAVE, OnButtonSave)
- ON_COMMAND(ID_MENU_HOMEPAGE, OnMenuHomepage)
- //}}AFX_MSG_MAP
- ON_MESSAGE(WM_CLICK_TRAYICON,OnClickTrayIcon)
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CFighterDlg message handlers
- BOOL CFighterDlg::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
- ModifyStyle(WS_CAPTION, 0);
- // if (m_ctrlFrame.Load(MAKEINTRESOURCE(IDR_GIF_FRAME),_T("Gif")))
- // m_ctrlFrame.Draw();
- m_ctrlNew.SetMyBitmap(IDB_NEW);
- // m_ctrlNew.SetBitmap((HBITMAP)m_bmpNew);
- m_ctrlNew.MoveWindow(m_ptNew.x, m_ptNew.y, 60, 25, SWP_NOZORDER| SWP_NOMOVE);
- m_ctrlPosition.SetMyBitmap(IDB_POSITION);
- // m_ctrlPosition.SetBitmap((HBITMAP)m_bmpPosition);
- m_ctrlPosition.MoveWindow(m_ptNew.x+BUTTON_INTERVAL_H, m_ptNew.y, 60, 25, SWP_NOZORDER| SWP_NOMOVE);
- m_ctrlSave.SetMyBitmap(IDB_SAVE);
- // m_ctrlSave.SetBitmap((HBITMAP)m_bmpSave);
- m_ctrlSave.MoveWindow(m_ptNew.x, m_ptNew.y+BUTTON_INTERVAL_V, 60, 25, SWP_NOZORDER| SWP_NOMOVE);
- m_ctrlOption.SetMyBitmap(IDB_OPTION);
- // m_ctrlOption.SetBitmap((HBITMAP)m_bmpOption);
- m_ctrlOption.MoveWindow(m_ptNew.x+BUTTON_INTERVAL_H, m_ptNew.y+BUTTON_INTERVAL_V, 60, 25, SWP_NOZORDER| SWP_NOMOVE);
- m_ctrlQuit.SetMyBitmap(IDB_QUIT);
- // m_ctrlQuit.SetBitmap((HBITMAP)m_bmpQuit);
- m_ctrlQuit.MoveWindow(m_ptNew.x+BUTTON_INTERVAL_H, m_ptNew.y+BUTTON_INTERVAL_V*2, 60, 25, SWP_NOZORDER| SWP_NOMOVE);
- m_ctrlLoad.SetMyBitmap(IDB_LOAD);
- // m_ctrlLoad.SetBitmap((HBITMAP)m_bmpLoad);
- m_ctrlLoad.MoveWindow(m_ptNew.x, m_ptNew.y+BUTTON_INTERVAL_V*2, 60, 25, SWP_NOZORDER| SWP_NOMOVE);
- CBitmap bmpMask;
- bmpMask.LoadBitmap(IDB_FRAME);
- HRGN hRgn;
- hRgn = ::BitmapToRegion((HBITMAP)bmpMask, RGB(0, 0, 0));//获取外框的形状
- SetWindowRgn(hRgn, TRUE);//设置屏幕形状
- ::DeleteObject(hRgn);
- bmpMask.DeleteObject();
- // m_bmpFrame.LoadBitmap(IDB_FRAME);
- // LoadJPG("frame.jpg");
- /* if(LoadJPG("frame.gif"))
- {
- DrawBackground();
- m_bLoadFrame = TRUE;
- }
- else
- {
- m_bLoadFrame = FALSE;
- PostMessage(WM_CLOSE);
- return FALSE;
- }
- */
- m_hNewCursor = LoadCursorFromFile("shooting.ani");
- // m_hOldCursor = (HCURSOR)GetClassLong(GetSafeHwnd(), GCL_HCURSOR);
- m_nWelcomeTimer = SetTimer(FIGHTER_WELCOME_TIMER, FIGHTER_SCRROLTIME, NULL);
- m_ctrlNew.GetWindowRect(&m_rectNew);
- ScreenToClient(&m_rectNew);
- m_ctrlPosition.GetWindowRect(&m_rectPosition);
- ScreenToClient(&m_rectPosition);
- m_ctrlSave.GetWindowRect(&m_rectSave);
- ScreenToClient(&m_rectSave);
- m_ctrlOption.GetWindowRect(&m_rectOption);
- ScreenToClient(&m_rectOption);
- m_ctrlLoad.GetWindowRect(&m_rectLoad);
- ScreenToClient(&m_rectLoad);
- m_ctrlQuit.GetWindowRect(&m_rectQuit);
- ScreenToClient(&m_rectQuit);
- char pathname[_MAX_PATH];
- char drive[_MAX_DRIVE];
- char dir[_MAX_DIR];
- char fname[_MAX_FNAME];
- char ext[_MAX_EXT];
- GetModuleFileName(NULL, pathname, _MAX_PATH);
- _splitpath(pathname, drive, dir, fname, ext);
- m_strBossFile.Format("%s%sSetting.txt", drive, dir);
- NOTIFYICONDATA tnd;
- tnd.cbSize=sizeof(NOTIFYICONDATA);
- tnd.hWnd=this->m_hWnd;
- tnd.uID=IDR_MAINFRAME;
- tnd.uFlags=NIF_MESSAGE|NIF_ICON|NIF_TIP;
- tnd.uCallbackMessage=WM_CLICK_TRAYICON;
- tnd.hIcon=LoadIcon(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDR_MAINFRAME));
- strcpy(tnd.szTip,"打飞机");
- Shell_NotifyIcon(NIM_ADD,&tnd);
- if(!ReadRankFile(&m_TopTen))
- {
- for(int i=0; i<10; i++)
- {
- sprintf(m_TopTen.name[i], "NULL");
- m_TopTen.bomb[i] = 0; //虚