FighterDlg.cpp
上传用户:hydatong
上传日期:2022-08-07
资源大小:219k
文件大小:64k
源码类别:

游戏

开发平台:

Visual C++

  1. // FighterDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "Fighter.h"
  5. #include "mmsystem.h"
  6. #include "FighterDlg.h"
  7. #include "FighterInfo.h"
  8. #include "CongraduationDlg.h"
  9. #include "AboutPage.h"
  10. #include "RankPage.h"
  11. #include "SettingPage.h"
  12. #include "OperationPage.h"
  13. #include "BCMenu.h"
  14. #include "QuitDlg.h"
  15. #ifdef _DEBUG
  16. #define new DEBUG_NEW
  17. #undef THIS_FILE
  18. static char THIS_FILE[] = __FILE__;
  19. #endif
  20. HRGN BitmapToRegion(HBITMAP hBmp, COLORREF cTransparentColor = 0, COLORREF cTolerance = 0x101010);
  21. /*/////////////////////////////////////////////////////////////////////////////
  22. // CAboutDlg dialog used for App About
  23. class CAboutDlg : public CDialog
  24. {
  25. public:
  26. CAboutDlg();
  27. // Dialog Data
  28. //{{AFX_DATA(CAboutDlg)
  29. enum { IDD = IDD_ABOUTBOX };
  30. //}}AFX_DATA
  31. // ClassWizard generated virtual function overrides
  32. //{{AFX_VIRTUAL(CAboutDlg)
  33. protected:
  34. virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
  35. //}}AFX_VIRTUAL
  36. // Implementation
  37. protected:
  38. //{{AFX_MSG(CAboutDlg)
  39. //}}AFX_MSG
  40. DECLARE_MESSAGE_MAP()
  41. };
  42. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  43. {
  44. //{{AFX_DATA_INIT(CAboutDlg)
  45. //}}AFX_DATA_INIT
  46. }
  47. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  48. {
  49. CDialog::DoDataExchange(pDX);
  50. //{{AFX_DATA_MAP(CAboutDlg)
  51. //}}AFX_DATA_MAP
  52. }
  53. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  54. //{{AFX_MSG_MAP(CAboutDlg)
  55. // No message handlers
  56. //}}AFX_MSG_MAP
  57. END_MESSAGE_MAP()
  58. */
  59. /////////////////////////////////////////////////////////////////////////////
  60. // CFighterDlg dialog
  61. CFighterDlg::CFighterDlg(CWnd* pParent /*=NULL*/)
  62. : CDialog(CFighterDlg::IDD, pParent)
  63. {
  64. //{{AFX_DATA_INIT(CFighterDlg)
  65. //}}AFX_DATA_INIT
  66. // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
  67. m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  68. m_pPic = NULL;
  69. // m_pOldBitmap = NULL;
  70. m_bShowHandCursor = FALSE;
  71. m_bShowShootingCursor = FALSE;
  72. m_bLoadFrame = FALSE;
  73. m_bLoadWelcomeString = TRUE;
  74. m_bSound = TRUE;
  75. m_bByComputer = TRUE;
  76. m_bShow = TRUE;
  77. m_nFighterDown = 0;
  78. m_nFighterHit = 0;
  79. m_nBomb = 0;
  80. for(int i=0; i<10; i++)
  81. for(int j=0; j<10; j++)
  82. {
  83. m_nSky[i][j] = 0;
  84. m_nShootingResult[i][j] = 0;
  85. }
  86. m_rectSky = CRect(70, 54, 70+300, 54+300);
  87. m_ptNew = CPoint(m_rectSky.right+10, m_rectSky.top);
  88. m_rectCommentFrame = CRect(m_rectSky.right+20, m_rectSky.top+100, m_rectSky.right+132, m_rectSky.top+172);
  89. m_ptComment = CPoint(m_rectCommentFrame.left, m_rectCommentFrame.top);
  90. m_rectFighterDown = CRect(m_rectSky.right+20, m_rectCommentFrame.bottom+40, m_rectCommentFrame.right, m_rectCommentFrame.bottom+55);
  91. m_rectBomb = CRect(m_rectSky.right+20, m_rectCommentFrame.bottom+70, m_rectCommentFrame.right, m_rectCommentFrame.bottom+85);
  92. m_rectFighterHit = CRect(m_rectSky.right+20, m_rectCommentFrame.bottom+100, m_rectCommentFrame.right, m_rectCommentFrame.bottom+115);
  93. m_nCommentTimer = 0;
  94. m_nWelcomeTimer = 0;
  95. m_strComment5 = "";
  96. m_strComment4 = "";
  97. m_strComment3 = "";
  98. m_strComment2 = "";
  99. m_strComment1 = "";
  100. m_nGameStatus = FIGHTER_STOP;
  101. }
  102. CFighterDlg::~CFighterDlg()
  103. {
  104. // if(m_pOldBitmap)
  105. // {
  106. // memDC.SelectObject(m_pOldBitmap);
  107. // m_FrameBitmap.DeleteObject();
  108. // }
  109. }
  110. void CFighterDlg::DoDataExchange(CDataExchange* pDX)
  111. {
  112. CDialog::DoDataExchange(pDX);
  113. //{{AFX_DATA_MAP(CFighterDlg)
  114. DDX_Control(pDX, IDC_BUTTON_LOAD, m_ctrlLoad);
  115. DDX_Control(pDX, IDC_BUTTON_SAVE, m_ctrlSave);
  116. DDX_Control(pDX, IDC_BUTTON_QUIT, m_ctrlQuit);
  117. DDX_Control(pDX, IDC_BUTTON_OPTION, m_ctrlOption);
  118. DDX_Control(pDX, IDC_BUTTON_POSITION, m_ctrlPosition);
  119. DDX_Control(pDX, IDC_BUTTON_NEW, m_ctrlNew);
  120. //}}AFX_DATA_MAP
  121. }
  122. BEGIN_MESSAGE_MAP(CFighterDlg, CDialog)
  123. //{{AFX_MSG_MAP(CFighterDlg)
  124. ON_WM_SYSCOMMAND()
  125. ON_WM_PAINT()
  126. ON_WM_QUERYDRAGICON()
  127. ON_WM_SETCURSOR()
  128. ON_WM_MOUSEMOVE()
  129. ON_WM_LBUTTONDOWN()
  130. ON_WM_LBUTTONDBLCLK()
  131. ON_WM_RBUTTONDOWN()
  132. ON_WM_TIMER()
  133. ON_WM_KEYDOWN()
  134. ON_COMMAND(ID_MENU_SHOW, OnMenuShow)
  135. ON_WM_DESTROY()
  136. ON_COMMAND(ID_MENU_LOAD, OnMenuLoad)
  137. ON_COMMAND(ID_MENU_QUIT, OnMenuQuit)
  138. ON_COMMAND(ID_MENU_SAVE, OnMenuSave)
  139. ON_COMMAND(ID_MENU_SOUND, OnMenuSound)
  140. ON_BN_CLICKED(IDC_BUTTON_NEW, OnButtonNew)
  141. ON_BN_CLICKED(IDC_BUTTON_LOAD, OnButtonLoad)
  142. ON_BN_CLICKED(IDC_BUTTON_OPTION, OnButtonOption)
  143. ON_BN_CLICKED(IDC_BUTTON_POSITION, OnButtonPosition)
  144. ON_BN_CLICKED(IDC_BUTTON_QUIT, OnButtonQuit)
  145. ON_BN_CLICKED(IDC_BUTTON_SAVE, OnButtonSave)
  146. ON_COMMAND(ID_MENU_HOMEPAGE, OnMenuHomepage)
  147. //}}AFX_MSG_MAP
  148. ON_MESSAGE(WM_CLICK_TRAYICON,OnClickTrayIcon)
  149. END_MESSAGE_MAP()
  150. /////////////////////////////////////////////////////////////////////////////
  151. // CFighterDlg message handlers
  152. BOOL CFighterDlg::OnInitDialog()
  153. {
  154. CDialog::OnInitDialog();
  155. // Add "About..." menu item to system menu.
  156. // IDM_ABOUTBOX must be in the system command range.
  157. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
  158. ASSERT(IDM_ABOUTBOX < 0xF000);
  159. CMenu* pSysMenu = GetSystemMenu(FALSE);
  160. if (pSysMenu != NULL)
  161. {
  162. CString strAboutMenu;
  163. strAboutMenu.LoadString(IDS_ABOUTBOX);
  164. if (!strAboutMenu.IsEmpty())
  165. {
  166. pSysMenu->AppendMenu(MF_SEPARATOR);
  167. pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
  168. }
  169. }
  170. // Set the icon for this dialog.  The framework does this automatically
  171. //  when the application's main window is not a dialog
  172. SetIcon(m_hIcon, TRUE); // Set big icon
  173. SetIcon(m_hIcon, FALSE); // Set small icon
  174. // TODO: Add extra initialization here
  175. ModifyStyle(WS_CAPTION, 0);
  176. // if (m_ctrlFrame.Load(MAKEINTRESOURCE(IDR_GIF_FRAME),_T("Gif")))
  177. // m_ctrlFrame.Draw();
  178. m_ctrlNew.SetMyBitmap(IDB_NEW);
  179. // m_ctrlNew.SetBitmap((HBITMAP)m_bmpNew);
  180. m_ctrlNew.MoveWindow(m_ptNew.x, m_ptNew.y, 60, 25, SWP_NOZORDER| SWP_NOMOVE);
  181. m_ctrlPosition.SetMyBitmap(IDB_POSITION);
  182. // m_ctrlPosition.SetBitmap((HBITMAP)m_bmpPosition);
  183. m_ctrlPosition.MoveWindow(m_ptNew.x+BUTTON_INTERVAL_H, m_ptNew.y, 60, 25, SWP_NOZORDER| SWP_NOMOVE);
  184. m_ctrlSave.SetMyBitmap(IDB_SAVE);
  185. // m_ctrlSave.SetBitmap((HBITMAP)m_bmpSave);
  186. m_ctrlSave.MoveWindow(m_ptNew.x, m_ptNew.y+BUTTON_INTERVAL_V, 60, 25, SWP_NOZORDER| SWP_NOMOVE);
  187. m_ctrlOption.SetMyBitmap(IDB_OPTION);
  188. // m_ctrlOption.SetBitmap((HBITMAP)m_bmpOption);
  189. m_ctrlOption.MoveWindow(m_ptNew.x+BUTTON_INTERVAL_H, m_ptNew.y+BUTTON_INTERVAL_V, 60, 25, SWP_NOZORDER| SWP_NOMOVE);
  190. m_ctrlQuit.SetMyBitmap(IDB_QUIT);
  191. // m_ctrlQuit.SetBitmap((HBITMAP)m_bmpQuit);
  192. m_ctrlQuit.MoveWindow(m_ptNew.x+BUTTON_INTERVAL_H, m_ptNew.y+BUTTON_INTERVAL_V*2, 60, 25, SWP_NOZORDER| SWP_NOMOVE);
  193. m_ctrlLoad.SetMyBitmap(IDB_LOAD);
  194. // m_ctrlLoad.SetBitmap((HBITMAP)m_bmpLoad);
  195. m_ctrlLoad.MoveWindow(m_ptNew.x, m_ptNew.y+BUTTON_INTERVAL_V*2, 60, 25, SWP_NOZORDER| SWP_NOMOVE);
  196. CBitmap bmpMask;
  197. bmpMask.LoadBitmap(IDB_FRAME);
  198. HRGN hRgn;
  199. hRgn = ::BitmapToRegion((HBITMAP)bmpMask, RGB(0, 0, 0));//获取外框的形状
  200. SetWindowRgn(hRgn, TRUE);//设置屏幕形状
  201. ::DeleteObject(hRgn);
  202. bmpMask.DeleteObject();
  203. // m_bmpFrame.LoadBitmap(IDB_FRAME);
  204. // LoadJPG("frame.jpg");
  205. /* if(LoadJPG("frame.gif"))
  206. {
  207. DrawBackground();
  208. m_bLoadFrame = TRUE;
  209. }
  210. else
  211. {
  212. m_bLoadFrame = FALSE;
  213. PostMessage(WM_CLOSE);
  214. return FALSE;
  215. }
  216. */
  217. m_hNewCursor = LoadCursorFromFile("shooting.ani");
  218. // m_hOldCursor = (HCURSOR)GetClassLong(GetSafeHwnd(), GCL_HCURSOR);
  219. m_nWelcomeTimer = SetTimer(FIGHTER_WELCOME_TIMER, FIGHTER_SCRROLTIME, NULL);
  220. m_ctrlNew.GetWindowRect(&m_rectNew);
  221. ScreenToClient(&m_rectNew);
  222. m_ctrlPosition.GetWindowRect(&m_rectPosition);
  223. ScreenToClient(&m_rectPosition);
  224. m_ctrlSave.GetWindowRect(&m_rectSave);
  225. ScreenToClient(&m_rectSave);
  226. m_ctrlOption.GetWindowRect(&m_rectOption);
  227. ScreenToClient(&m_rectOption);
  228. m_ctrlLoad.GetWindowRect(&m_rectLoad);
  229. ScreenToClient(&m_rectLoad);
  230. m_ctrlQuit.GetWindowRect(&m_rectQuit);
  231. ScreenToClient(&m_rectQuit);
  232. char pathname[_MAX_PATH];
  233. char drive[_MAX_DRIVE];
  234. char dir[_MAX_DIR];
  235. char fname[_MAX_FNAME];
  236. char ext[_MAX_EXT];
  237. GetModuleFileName(NULL, pathname, _MAX_PATH);
  238. _splitpath(pathname, drive, dir, fname, ext);
  239. m_strBossFile.Format("%s%sSetting.txt", drive, dir);
  240. NOTIFYICONDATA tnd;
  241. tnd.cbSize=sizeof(NOTIFYICONDATA);
  242. tnd.hWnd=this->m_hWnd;
  243. tnd.uID=IDR_MAINFRAME;
  244. tnd.uFlags=NIF_MESSAGE|NIF_ICON|NIF_TIP;
  245. tnd.uCallbackMessage=WM_CLICK_TRAYICON;
  246. tnd.hIcon=LoadIcon(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDR_MAINFRAME));
  247. strcpy(tnd.szTip,"打飞机");
  248. Shell_NotifyIcon(NIM_ADD,&tnd);
  249. if(!ReadRankFile(&m_TopTen))
  250. {
  251. for(int i=0; i<10; i++)
  252. {
  253. sprintf(m_TopTen.name[i], "NULL");
  254. m_TopTen.bomb[i] = 0; //虚