Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

291 lines
6.6 KiB

  1. /*************************************************
  2. * mainfrm.cpp *
  3. * *
  4. * Copyright (C) 1995-1999 Microsoft Inc. *
  5. * *
  6. *************************************************/
  7. // mainfrm.cpp : implementation of the CMainFrame class
  8. //
  9. #include "stdafx.h"
  10. #include "cblocks.h"
  11. #include "mybar.h"
  12. #include "dib.h"
  13. #include "dibpal.h"
  14. #include "spriteno.h"
  15. #include "sprite.h"
  16. #include "phsprite.h"
  17. #include "myblock.h"
  18. #include "splstno.h"
  19. #include "spritlst.h"
  20. #include "osbview.h"
  21. #include "slot.h"
  22. #include "about.h"
  23. #include "blockvw.h"
  24. #include "blockdoc.h"
  25. #include "mainfrm.h"
  26. #ifdef _DEBUG
  27. #undef THIS_FILE
  28. static char BASED_CODE THIS_FILE[] = __FILE__;
  29. #endif
  30. extern long GScore;
  31. extern CString GHint;
  32. /////////////////////////////////////////////////////////////////////////////
  33. // CMainFrame
  34. IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
  35. BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
  36. //{{AFX_MSG_MAP(CMainFrame)
  37. ON_WM_CREATE()
  38. ON_WM_PALETTECHANGED()
  39. ON_WM_QUERYNEWPALETTE()
  40. ON_WM_MENUSELECT()
  41. ON_COMMAND(ID_FIRE,OnFire)
  42. ON_COMMAND(ID_TOOL_PAUSE,OnToolPause)
  43. ON_COMMAND(ID_TOOL_RESUME,OnToolResume)
  44. ON_COMMAND(ID_TOOL_RESUME,OnToolPause)
  45. ON_WM_DESTROY()
  46. //}}AFX_MSG_MAP
  47. ON_UPDATE_COMMAND_UI(ID_SCOREPROMPT,OnUpdateStatus)
  48. ON_UPDATE_COMMAND_UI(ID_SCORE,OnUpdateStatus)
  49. ON_UPDATE_COMMAND_UI(ID_HINT,OnUpdateStatus)
  50. END_MESSAGE_MAP()
  51. /////////////////////////////////////////////////////////////////////////////
  52. // arrays of IDs used to initialize control bars
  53. // toolbar buttons - IDs are command buttons
  54. static UINT BASED_CODE buttons[] =
  55. {
  56. // same order as in the bitmap 'toolbar.bmp'
  57. ID_FILE_SUSPEND,
  58. ID_SEPARATOR,
  59. ID_SEPARATOR,
  60. ID_ACTION_SLOW,
  61. ID_ACTION_NORMALSLOW,
  62. ID_ACTION_NORMAL,
  63. ID_ACTION_NORMALFAST,
  64. ID_ACTION_FAST,
  65. ID_SEPARATOR,
  66. ID_SEPARATOR,
  67. ID_OPTION_BEGINER,
  68. ID_OPTION_ORDINARY,
  69. ID_OPTION_EXPERT,
  70. ID_SEPARATOR,
  71. ID_SEPARATOR,
  72. ID_HELP_RULE
  73. };
  74. static UINT BASED_CODE indicators[] =
  75. {
  76. ID_SEPARATOR, // status line indicator
  77. ID_HINT,
  78. ID_SCOREPROMPT,
  79. ID_SCORE
  80. // ID_BLANK5
  81. };
  82. /////////////////////////////////////////////////////////////////////////////
  83. // CMainFrame construction/destruction
  84. CMainFrame::CMainFrame()
  85. {
  86. // TODO: add member initialization code here
  87. }
  88. CMainFrame::~CMainFrame()
  89. {
  90. }
  91. HFONT hFont=NULL;
  92. int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
  93. {
  94. if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
  95. return -1;
  96. if (!m_wndToolBar.Create(this) ||
  97. !m_wndToolBar.LoadBitmap(IDR_MAINFRAME) ||
  98. !m_wndToolBar.SetButtons(buttons,
  99. sizeof(buttons)/sizeof(UINT)))
  100. {
  101. TRACE0("Failed to create toolbar\n");
  102. return -1; // fail to create
  103. }
  104. if (!m_wndStatusBar.Create(this) ||
  105. !m_wndStatusBar.SetIndicators(indicators,
  106. sizeof(indicators)/sizeof(UINT)))
  107. {
  108. TRACE0("Failed to create status bar\n");
  109. return -1; // fail to create
  110. }
  111. m_wndToolBar.SetBarStyle(m_wndToolBar.GetBarStyle() |
  112. CBRS_TOOLTIPS | CBRS_FLYBY);
  113. UINT nID, nStyle;
  114. int cxWidth;
  115. CString szPrompt;
  116. szPrompt.LoadString(ID_SCOREPROMPT);
  117. CRect rc;
  118. GetClientRect(&rc);
  119. LOGFONT lf;
  120. memset(&lf,0,sizeof(LOGFONT));
  121. lf.lfHeight = 12;
  122. lf.lfCharSet = CHINESEBIG5_CHARSET;
  123. lstrcpy(lf.lfFaceName,TEXT("�ө���"));
  124. HFONT hFont = CreateFontIndirect(&lf);
  125. m_wndStatusBar.SendMessage(WM_SETFONT,(WPARAM)hFont,0);
  126. // m_wndStatusBar.GetPaneInfo(0,nID,nStyle,cxWidth);
  127. // m_wndStatusBar.SetPaneInfo(0,nID,nStyle,rc.Width()/4);
  128. // m_wndStatusBar.GetPaneInfo(m_wndStatusBar.CommandToIndex(ID_SCOREPROMPT),nID,nStyle,cxWidth);
  129. // m_wndStatusBar.SetPaneInfo(m_wndStatusBar.CommandToIndex(ID_SCOREPROMPT),nID,SBPS_NOBORDERS,cxWidth);
  130. // m_wndStatusBar.GetPaneInfo(m_wndStatusBar.CommandToIndex(ID_SCORE),nID,nStyle,cxWidth);
  131. // m_wndStatusBar.SetPaneInfo(m_wndStatusBar.CommandToIndex(ID_SCORE),nID,nStyle,cxWidth);
  132. // m_wndStatusBar.GetPaneInfo(m_wndStatusBar.CommandToIndex(ID_HINT),nID,nStyle,cxWidth);
  133. // m_wndStatusBar.SetPaneInfo(m_wndStatusBar.CommandToIndex(ID_HINT),nID,nStyle,cxWidth);
  134. return 0;
  135. }
  136. BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
  137. {
  138. cs.style = WS_OVERLAPPED | WS_CAPTION | FWS_ADDTOTITLE
  139. | WS_SYSMENU | WS_MINIMIZEBOX;
  140. return CFrameWnd::PreCreateWindow(cs);
  141. }
  142. /////////////////////////////////////////////////////////////////////////////
  143. // CMainFrame diagnostics
  144. #ifdef _DEBUG
  145. void CMainFrame::AssertValid() const
  146. {
  147. CFrameWnd::AssertValid();
  148. }
  149. void CMainFrame::Dump(CDumpContext& dc) const
  150. {
  151. CFrameWnd::Dump(dc);
  152. }
  153. #endif //_DEBUG
  154. /////////////////////////////////////////////////////////////////////////////
  155. // CMainFrame message handlers
  156. void CMainFrame::OnPaletteChanged(CWnd* pFocusWnd)
  157. {
  158. CFrameWnd::OnPaletteChanged(pFocusWnd);
  159. CView *pview = GetActiveView();
  160. if (pview) {
  161. // OnPaletteChanged is not public
  162. pview->SendMessage(WM_PALETTECHANGED,
  163. (WPARAM)(pFocusWnd->GetSafeHwnd()),
  164. (LPARAM)0);
  165. }
  166. }
  167. BOOL CMainFrame::OnQueryNewPalette()
  168. {
  169. CView *pview = GetActiveView();
  170. if (pview) {
  171. return (BOOL)(pview->SendMessage(WM_QUERYNEWPALETTE,
  172. (WPARAM)0,
  173. (LPARAM)0) );
  174. }
  175. return CFrameWnd::OnQueryNewPalette();
  176. }
  177. void CMainFrame::OnUpdateStatus(CCmdUI* pCmdUI)
  178. {
  179. static long nScore = -1;
  180. static CString szHint="1";
  181. pCmdUI->Enable();
  182. if (pCmdUI->m_nID == ID_SCORE)
  183. {
  184. if (nScore != GScore)
  185. {
  186. static char szBuf[20];
  187. wsprintf(szBuf,"%ld",GScore);
  188. m_wndStatusBar.SetPaneText(m_wndStatusBar.CommandToIndex(ID_SCORE),szBuf);
  189. nScore = GScore;
  190. }
  191. }
  192. else if (pCmdUI->m_nID == ID_HINT)
  193. {
  194. if (szHint != GHint)
  195. {
  196. m_wndStatusBar.SetPaneText(m_wndStatusBar.CommandToIndex(ID_HINT),GHint);
  197. szHint = GHint;
  198. }
  199. }
  200. }
  201. void CMainFrame::OnMenuSelect( UINT nItemID, UINT nFlag, HMENU hMenu )
  202. {
  203. CWnd::OnMenuSelect( nItemID, nFlag, hMenu );
  204. CView* pView = GetActiveView();
  205. pView->SendMessage(WM_MENUSELECT, MAKELONG(nItemID, nFlag), (LPARAM)hMenu );
  206. }
  207. void CMainFrame::OnFire()
  208. {
  209. static BOOL bOn = TRUE;
  210. CBlockView *pView = (CBlockView *)GetActiveView();
  211. if (pView)
  212. {
  213. if (bOn)
  214. pView->ForceSpeed(0);
  215. else
  216. pView->ForceSpeed(GSpeed);
  217. bOn = !bOn;
  218. //pView->GetDocument()->UpdateAllViews(NULL);
  219. }
  220. }
  221. void CMainFrame::OnToolPause()
  222. {
  223. CBlockView *pView = (CBlockView *)GetActiveView();
  224. if (pView)
  225. {
  226. pView->ForceSpeed(0);
  227. }
  228. }
  229. void CMainFrame::OnToolResume()
  230. {
  231. CBlockView *pView = (CBlockView *)GetActiveView();
  232. if (pView)
  233. {
  234. pView->ForceSpeed(GSpeed);
  235. }
  236. }
  237. void CMainFrame::OnDestroy()
  238. {
  239. CFrameWnd::OnDestroy();
  240. if (hFont != NULL)
  241. DeleteObject(hFont);
  242. }