MainFrm.cpp
上传用户:dtengfei
上传日期:2013-01-16
资源大小:393k
文件大小:15k
源码类别:

医药行业

开发平台:

Visual C++

  1. // MainFrm.cpp : implementation of the CMainFrame class
  2. //
  3. #include "stdafx.h"
  4. #include "心跳检测.h"
  5. #include "心跳检测Doc.h"
  6. #include "心跳检测View.h"
  7. #include "MainFrm.h"
  8. #ifdef _DEBUG
  9. #define new DEBUG_NEW
  10. #undef THIS_FILE
  11. static char THIS_FILE[] = __FILE__;
  12. #endif
  13. /////////////////////////////////////////////////////////////////////////////
  14. // CMainFrame
  15. IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
  16. BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
  17. //{{AFX_MSG_MAP(CMainFrame)
  18. ON_MESSAGE(WM_REFRESH,OnRefresh)
  19. ON_WM_CREATE()
  20. ON_WM_DESTROY()
  21. ON_WM_DRAWITEM()
  22. ON_WM_GETMINMAXINFO()
  23. ON_WM_MEASUREITEM()
  24. ON_WM_NCLBUTTONDBLCLK()
  25. ON_WM_NCLBUTTONDOWN()
  26. ON_WM_NCMOUSEMOVE()
  27. ON_WM_NCCALCSIZE()
  28. //}}AFX_MSG_MAP
  29. END_MESSAGE_MAP()
  30. static UINT indicators[] =
  31. {
  32. ID_SEPARATOR,           // status line indicator
  33. ID_INDICATOR_CAPS,
  34. ID_INDICATOR_NUM,
  35. ID_INDICATOR_SCRL,
  36. };
  37. /////////////////////////////////////////////////////////////////////////////
  38. // CMainFrame construction/destruction
  39. CMainFrame::CMainFrame()
  40. {
  41. // TODO: add member initialization code here
  42. TP.PointNumber=0;
  43. TP.runing=FALSE;
  44. TP.WholeNumber=1000;
  45. }
  46. CMainFrame::~CMainFrame()
  47. {
  48. ::PostThreadMessage(m_JiqiThreadID,WM_THREADEND,NULL,NULL);
  49. }
  50. int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
  51. {
  52. if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
  53. return -1;
  54. /* if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
  55. | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
  56. !m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
  57. {
  58. TRACE0("Failed to create toolbarn");
  59. return -1;      // fail to create
  60. }
  61. */
  62. if (!m_wndStatusBar.Create(this) ||
  63. !m_wndStatusBar.SetIndicators(indicators,
  64.   sizeof(indicators)/sizeof(UINT)))
  65. {
  66. TRACE0("Failed to create status barn");
  67. return -1;      // fail to create
  68. }
  69. // TODO: Delete these three lines if you don't want the toolbar to
  70. //  be dockable
  71. /* m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
  72. EnableDocking(CBRS_ALIGN_ANY);
  73. DockControlBar(&m_wndToolBar);
  74. */
  75. //建立Jiqi线程
  76. m_pJiqiThread=(CJiqi *)AfxBeginThread(RUNTIME_CLASS(CJiqi));
  77. m_JiqiThreadID=m_pJiqiThread->m_nThreadID;
  78. m_MainThreadID=::GetCurrentThreadId();
  79. m_pJiqiThread->m_MainThreadID=m_MainThreadID;
  80. m_pJiqiThread->hMainWnd=AfxGetMainWnd()->GetSafeHwnd();
  81. CControl m_Dlg;
  82. if(m_Dlg.Init()!=1)
  83. {
  84. MessageBox("板卡初始化失败!请检查后重新运行");
  85. _exit(0);
  86. }
  87. return 0;
  88. }
  89. BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
  90. {
  91. if( !CFrameWnd::PreCreateWindow(cs) )
  92. return FALSE;
  93. // TODO: Modify the Window class or styles here by modifying
  94. //  the CREATESTRUCT cs
  95. /*
  96. cs.style = WS_OVERLAPPED | WS_CAPTION | FWS_ADDTOTITLE
  97. | WS_THICKFRAME | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_MAXIMIZE;
  98. */
  99. /* if(cs.hMenu!=NULL) 
  100. {
  101. ::DestroyMenu(cs.hMenu); // 如果菜单已经载入,则删除掉
  102. cs.hMenu = NULL;      // 设置窗口菜单为NULL
  103. }
  104. */
  105.     cs.cx=1024;
  106. cs.cy=768;
  107. cs.style^=WS_MAXIMIZEBOX|WS_MINIMIZEBOX;
  108. return TRUE;
  109. }
  110. /////////////////////////////////////////////////////////////////////////////
  111. // CMainFrame diagnostics
  112. #ifdef _DEBUG
  113. void CMainFrame::AssertValid() const
  114. {
  115. CFrameWnd::AssertValid();
  116. }
  117. void CMainFrame::Dump(CDumpContext& dc) const
  118. {
  119. CFrameWnd::Dump(dc);
  120. }
  121. #endif //_DEBUG
  122. /////////////////////////////////////////////////////////////////////////////
  123. // CMainFrame message handlers
  124. LRESULT CMainFrame::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam) 
  125. {
  126. // TODO: Add your specialized code here and/or call the base class
  127. LRESULT lrst=CFrameWnd::DefWindowProc(message, wParam, lParam);
  128. if (!::IsWindow(m_hWnd))
  129. return lrst;
  130. if (message == WM_MOVE || message == WM_NCPAINT ||message == WM_NCACTIVATE ||message == WM_NOTIFY)
  131. {
  132. CDC* pWinDC = GetWindowDC();
  133. if (pWinDC)
  134. DrawTitleBar(pWinDC);
  135. ReleaseDC(pWinDC);
  136. }
  137. return lrst;
  138. return CFrameWnd::DefWindowProc(message, wParam, lParam);
  139. }
  140. void CMainFrame::DrawTitleBar(CDC *pDC)
  141. {
  142. if (m_hWnd)
  143. {
  144. CBrush Brush(RGB(0,100,255));
  145. CBrush* pOldBrush = pDC->SelectObject(&Brush);
  146. CRect rtWnd, rtTitle, rtButtons;
  147. GetWindowRect(&rtWnd); 
  148. //取得标题栏的位置
  149. rtTitle.left = GetSystemMetrics(SM_CXFRAME);
  150. rtTitle.top = GetSystemMetrics(SM_CYFRAME);
  151. rtTitle.right = rtWnd.right - rtWnd.left - GetSystemMetrics(SM_CXFRAME);
  152. rtTitle.bottom = rtTitle.top + GetSystemMetrics(SM_CYSIZE);
  153. CPoint point;
  154. //填充顶部框架
  155. point.x = rtWnd.Width();
  156. point.y = GetSystemMetrics(SM_CYSIZE) + GetSystemMetrics(SM_CYFRAME)+1;
  157. pDC->PatBlt(0, 0, point.x, point.y, PATCOPY);
  158. //填充左侧框架
  159. point.x = GetSystemMetrics(SM_CXFRAME);
  160. point.y = rtWnd.Height();
  161. // pDC->PatBlt(0, 0, point.x, point.y, PATCOPY);
  162. pDC->PatBlt(0, 0, 300, 41, PATCOPY);
  163. //填充底部框架
  164. point.x = rtWnd.Width(); 
  165. point.y = GetSystemMetrics(SM_CYFRAME);
  166. pDC->PatBlt(0, rtWnd.Height()-point.y, point.x, point.y, PATCOPY);
  167. //填充右侧框架
  168. point.x = GetSystemMetrics(SM_CXFRAME);
  169. point.y = rtWnd.Height();
  170. pDC->PatBlt(rtWnd.Width()-point.x, 0, point.x, point.y, PATCOPY);
  171. //填充菜单下部框架
  172. point.x = rtWnd.Width();
  173. point.y = GetSystemMetrics(SM_CYFRAME)-1;
  174. pDC->PatBlt(0, GetSystemMetrics(SM_CYMENU)+GetSystemMetrics(SM_CYSIZE)+point.y, point.x, point.y, PATCOPY);
  175. //填充菜单右侧框架
  176. point.x = rtWnd.Width() - 230;
  177. point.y = GetSystemMetrics(SM_CYMENU);
  178. pDC->PatBlt(230, GetSystemMetrics(SM_CYSIZE)+GetSystemMetrics(SM_CYFRAME), point.x, point.y, PATCOPY);
  179. //绘制美化线条
  180. CBrush BrushLine(RGB(255, 255, 255));
  181. pDC->SelectObject(&BrushLine);
  182. point.x = rtWnd.Width() - 150;
  183. point.y = GetSystemMetrics(SM_CYFRAME) + 2;
  184. pDC->PatBlt(GetSystemMetrics(SM_CXFRAME), point.y, point.x, 1, PATCOPY);
  185. point.y += 5;
  186. pDC->PatBlt(GetSystemMetrics(SM_CXFRAME), point.y, point.x, 1, PATCOPY);
  187. point.y += 5;
  188. pDC->PatBlt(GetSystemMetrics(SM_CXFRAME), point.y, point.x, 1, PATCOPY);
  189. point.x += 60;
  190. point.y += 12;
  191. pDC->PatBlt(point.x, point.y, 85, 1, PATCOPY);
  192. point.y += 5;
  193. pDC->PatBlt(point.x, point.y, 85, 1, PATCOPY);
  194. point.x -= 60 - GetSystemMetrics(SM_CXFRAME);
  195. point.y += 5;
  196. pDC->PatBlt(point.x, point.y, 145-GetSystemMetrics(SM_CXFRAME) , 1, PATCOPY);
  197. point.y -= 32;
  198. pDC->PatBlt(point.x, point.y, 1 , 32, PATCOPY);
  199. pDC->SelectObject(pOldBrush);
  200. //重画图标
  201. m_rtIcon.left = rtWnd.Width() - 135;
  202. m_rtIcon.top = GetSystemMetrics(SM_CYFRAME);
  203. m_rtIcon.right = m_rtIcon.left + 32;
  204. m_rtIcon.bottom = m_rtIcon.top + 32;
  205. ::DrawIconEx(pDC->m_hDC, m_rtIcon.left, m_rtIcon.top, AfxGetApp()->LoadIcon(IDI_EOAPP), 
  206. m_rtIcon.Width(), m_rtIcon.Height(), 0, NULL, DI_NORMAL);
  207. m_rtIcon.OffsetRect(rtWnd.TopLeft()); 
  208. //准备画XP风格按钮
  209. CBitmap* pBitmap = new CBitmap;
  210. CBitmap* pOldBitmap;
  211. CDC* pDisplayMemDC=new CDC;
  212. pDisplayMemDC->CreateCompatibleDC(pDC);
  213. //重画关闭button
  214. rtButtons.left = rtTitle.right - 19;
  215. rtButtons.top = rtTitle.top;
  216. rtButtons.right = rtButtons.left + 19;
  217. rtButtons.bottom = rtButtons.top + 19;
  218. pBitmap->LoadBitmap(IDB_EXIT_NORMAL);
  219. pOldBitmap=(CBitmap*)pDisplayMemDC->SelectObject(pBitmap);
  220. pDC->BitBlt(rtButtons.left, rtButtons.top, rtButtons.Width(), rtButtons.Height(), pDisplayMemDC, 0, 0, SRCCOPY);
  221. pDisplayMemDC->SelectObject(pOldBitmap);
  222. m_rtButtExit = rtButtons;
  223. m_rtButtExit.OffsetRect(rtWnd.TopLeft()); 
  224. pBitmap->DeleteObject();
  225. //重画最大化/恢复button
  226. rtButtons.right = rtButtons.left - 3;
  227. rtButtons.left = rtButtons.right - 19;
  228. if (IsZoomed())
  229. pBitmap->LoadBitmap(IDB_RESTORE_NORMAL);
  230. else
  231. pBitmap->LoadBitmap(IDB_MAX_NORMAL);
  232. pOldBitmap=(CBitmap*)pDisplayMemDC->SelectObject(pBitmap);
  233. pDC->BitBlt(rtButtons.left, rtButtons.top, rtButtons.Width(), rtButtons.Height(), pDisplayMemDC, 0, 0, SRCCOPY);
  234. pDisplayMemDC->SelectObject(pOldBitmap);
  235. m_rtButtMax = rtButtons;
  236. m_rtButtMax.OffsetRect(rtWnd.TopLeft());
  237. pBitmap->DeleteObject();
  238. //重画最小化button
  239. rtButtons.right = rtButtons.left - 3;
  240. rtButtons.left = rtButtons.right - 19;
  241. pBitmap->LoadBitmap(IDB_MIN_NORMAL);
  242. pOldBitmap=(CBitmap*)pDisplayMemDC->SelectObject(pBitmap);
  243. pDC->BitBlt(rtButtons.left, rtButtons.top, rtButtons.Width(), rtButtons.Height(), pDisplayMemDC, 0, 0, SRCCOPY);
  244. pDisplayMemDC->SelectObject(pOldBitmap);
  245. m_rtButtMin = rtButtons;
  246. m_rtButtMin.OffsetRect(rtWnd.TopLeft());
  247. pBitmap->DeleteObject();
  248. //重画帮助button
  249. rtButtons.right = rtButtons.left - 3;
  250. rtButtons.left = rtButtons.right - 19;
  251. pBitmap->LoadBitmap(IDB_HELP_NORMAL);
  252. pOldBitmap=(CBitmap*)pDisplayMemDC->SelectObject(pBitmap);
  253. pDC->BitBlt(rtButtons.left, rtButtons.top, rtButtons.Width(), rtButtons.Height(), pDisplayMemDC, 0, 0, SRCCOPY);
  254. pDisplayMemDC->SelectObject(pOldBitmap);
  255. m_rtButtHelp = rtButtons;
  256. m_rtButtHelp.OffsetRect(rtWnd.TopLeft());
  257. pBitmap->DeleteObject();
  258. //重画caption
  259. int nOldMode = pDC->SetBkMode(TRANSPARENT);
  260. COLORREF clOldText=pDC->SetTextColor(RGB(255, 255, 255));
  261. pDC->SelectStockObject(SYSTEM_FIXED_FONT);
  262. rtTitle.left += 240; 
  263. rtTitle.top += GetSystemMetrics(SM_CYSIZE) + 2;
  264. rtTitle.bottom = rtTitle.top + 30;
  265. CString m_strTitle;
  266. m_strTitle.Format ("心       率       信       号       检       测");
  267. pDC->DrawText(m_strTitle, &rtTitle, DT_LEFT);
  268. pDC->SetBkMode(nOldMode);
  269. pDC->SetTextColor(clOldText);
  270. ReleaseDC(pDisplayMemDC);
  271. delete pDisplayMemDC;
  272. delete pBitmap;
  273. }
  274. }
  275. void CMainFrame::OnDestroy() 
  276. {
  277. CFrameWnd::OnDestroy();
  278. // TODO: Add your message handler code here
  279. }
  280. void CMainFrame::OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct) 
  281. {
  282. // TODO: Add your message handler code here and/or call default
  283. if(lpDrawItemStruct->CtlType == ODT_MENU)
  284. {
  285. // m_hMenu.DrawItem(lpDrawItemStruct);
  286. return ;
  287. }
  288. CFrameWnd::OnDrawItem(nIDCtl, lpDrawItemStruct);
  289. }
  290. void CMainFrame::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI) 
  291. {
  292. // TODO: Add your message handler code here and/or call default
  293.     CRect rectWindow;
  294.     GetWindowRect(&rectWindow);
  295.     CRect rectClient;
  296.     GetClientRect(&rectClient);
  297.       // get offset of toolbars, scrollbars, etc.
  298.     int nWidthOffset = rectWindow.Width() - rectClient.Width();
  299.     int nHeightOffset = rectWindow.Height() - rectClient.Height();
  300.     lpMMI->ptMinTrackSize.x = 500 + nWidthOffset;
  301.     lpMMI->ptMinTrackSize.y = 300 + nHeightOffset;
  302. CFrameWnd::OnGetMinMaxInfo(lpMMI);
  303. }
  304. void CMainFrame::OnMeasureItem(int nIDCtl, LPMEASUREITEMSTRUCT lpMeasureItemStruct) 
  305. {
  306. // TODO: Add your message handler code here and/or call default
  307. if(lpMeasureItemStruct->CtlType == ODT_MENU)
  308. {
  309. // m_hMenu.MeasureItem(lpMeasureItemStruct);
  310. return ;
  311. }
  312. CFrameWnd::OnMeasureItem(nIDCtl, lpMeasureItemStruct);
  313. }
  314. void CMainFrame::OnNcLButtonDblClk(UINT nHitTest, CPoint point) 
  315. {
  316. if (IsZoomed())
  317. SendMessage(WM_SYSCOMMAND, SC_RESTORE, MAKELPARAM(point.x, point.y));
  318. else
  319. SendMessage(WM_SYSCOMMAND, SC_MAXIMIZE, MAKELPARAM(point.x, point.y));
  320. CFrameWnd::OnNcLButtonDblClk(nHitTest, point);
  321. }
  322. void CMainFrame::OnNcLButtonDown(UINT nHitTest, CPoint point) 
  323. {
  324. //检测各按钮是否按到
  325. if (m_rtIcon.PtInRect(point))
  326. AfxMessageBox("欢迎访问森太公司主页 www.ccut.edu.cn");
  327. else if (m_rtButtHelp.PtInRect(point))
  328. //     AfxMessageBox("如有问题,请与本人联系:gwqlxq@mail.ccut.edu.cn");
  329. //      m_dlgconnect.DoModal ();
  330. {
  331. // CAboutDlg mDlg;
  332. // mDlg.DoModal();
  333. }
  334. else if (m_rtButtExit.PtInRect(point))
  335. SendMessage(WM_CLOSE);
  336. else if (m_rtButtMin.PtInRect(point))
  337. SendMessage(WM_SYSCOMMAND, SC_MINIMIZE, MAKELPARAM(point.x, point.y));
  338. else if (m_rtButtMax.PtInRect(point))
  339. {
  340. if (IsZoomed())
  341. SendMessage(WM_SYSCOMMAND, SC_RESTORE, MAKELPARAM(point.x, point.y));
  342. else
  343. SendMessage(WM_SYSCOMMAND, SC_MAXIMIZE, MAKELPARAM(point.x, point.y));
  344. }
  345. else if (!IsZoomed())
  346. Default();
  347. else if (nHitTest&HTMENU)
  348. CFrameWnd::OnNcLButtonDown(nHitTest, point);
  349. }
  350. void CMainFrame::OnNcMouseMove(UINT nHitTest, CPoint point) 
  351. {
  352. // TODO: Add your message handler code here and/or call default
  353. CDC* pDC = GetWindowDC();
  354. CDC* pDisplayMemDC=new CDC;
  355. pDisplayMemDC->CreateCompatibleDC(pDC);
  356. CBitmap* pBitmap = new CBitmap;
  357. CBitmap* pOldBitmap;
  358. CRect rtWnd, rtButton;
  359. if (pDC)
  360. {
  361. GetWindowRect(&rtWnd);
  362. //关闭button
  363. if (m_rtButtExit.PtInRect(point))
  364. pBitmap->LoadBitmap(IDB_EXIT_FOCUS);
  365. else
  366. pBitmap->LoadBitmap(IDB_EXIT_NORMAL);
  367. rtButton = m_rtButtExit;
  368. rtButton.OffsetRect(-rtWnd.left, -rtWnd.top);
  369. pOldBitmap=(CBitmap*)pDisplayMemDC->SelectObject(pBitmap);
  370. pDC->BitBlt(rtButton.left, rtButton.top, rtButton.Width(), rtButton.Height(), pDisplayMemDC, 0, 0, SRCCOPY);
  371. pDisplayMemDC->SelectObject(pOldBitmap);
  372. pBitmap->DeleteObject();
  373. //最大化/恢复button
  374. if (m_rtButtMax.PtInRect(point))
  375. {
  376. if (IsZoomed())
  377. pBitmap->LoadBitmap(IDB_RESTORE_FOCUS);
  378. else
  379. pBitmap->LoadBitmap(IDB_MAX_FOCUS);
  380. }
  381. else
  382. {
  383. if (IsZoomed())
  384. pBitmap->LoadBitmap(IDB_RESTORE_NORMAL);
  385. else
  386. pBitmap->LoadBitmap(IDB_MAX_NORMAL);
  387. }
  388. rtButton = m_rtButtMax;
  389. rtButton.OffsetRect(-rtWnd.left, -rtWnd.top);
  390. pOldBitmap=(CBitmap*)pDisplayMemDC->SelectObject(pBitmap);
  391. pDC->BitBlt(rtButton.left, rtButton.top, rtButton.Width(), rtButton.Height(), pDisplayMemDC, 0, 0, SRCCOPY);
  392. pDisplayMemDC->SelectObject(pOldBitmap);
  393. pBitmap->DeleteObject();
  394. //最小化button
  395. if (m_rtButtMin.PtInRect(point))
  396. pBitmap->LoadBitmap(IDB_MIN_FOCUS);
  397. else
  398. pBitmap->LoadBitmap(IDB_MIN_NORMAL);
  399. rtButton = m_rtButtMin;
  400. rtButton.OffsetRect(-rtWnd.left, -rtWnd.top);
  401. pOldBitmap=(CBitmap*)pDisplayMemDC->SelectObject(pBitmap);
  402. pDC->BitBlt(rtButton.left, rtButton.top, rtButton.Width(), rtButton.Height(), pDisplayMemDC, 0, 0, SRCCOPY);
  403. pDisplayMemDC->SelectObject(pOldBitmap);
  404. pBitmap->DeleteObject();
  405. //帮助button
  406. if (m_rtButtHelp.PtInRect(point))
  407. pBitmap->LoadBitmap(IDB_HELP_FOCUS);
  408. else
  409. pBitmap->LoadBitmap(IDB_HELP_NORMAL);
  410. rtButton = m_rtButtHelp;
  411. rtButton.OffsetRect(-rtWnd.left, -rtWnd.top);
  412. pOldBitmap=(CBitmap*)pDisplayMemDC->SelectObject(pBitmap);
  413. pDC->BitBlt(rtButton.left, rtButton.top, rtButton.Width(), rtButton.Height(), pDisplayMemDC, 0, 0, SRCCOPY);
  414. pDisplayMemDC->SelectObject(pOldBitmap);
  415. pBitmap->DeleteObject();
  416. }
  417. ReleaseDC(pDisplayMemDC);
  418. ReleaseDC(pDC);
  419. delete pDisplayMemDC;
  420. delete pBitmap;
  421. CFrameWnd::OnNcMouseMove(nHitTest, point);
  422. }
  423. void CMainFrame::OnRefresh(int Point)
  424. {
  425. CMyView* pView=(CMyView *)GetActiveView();
  426. pView->Draw(Point);
  427. }
  428. BOOL CMainFrame::PreTranslateMessage(MSG* pMsg) 
  429. {
  430. // TODO: Add your specialized code here and/or call the base class
  431. if(pMsg->message==WM_REFRESH)
  432. {
  433. OnRefresh(TP.PointNumber);
  434. return TRUE;
  435. }
  436. else
  437. return CFrameWnd::PreTranslateMessage(pMsg);
  438. }
  439. void CMainFrame::OnNcCalcSize(BOOL bCalcValidRects, NCCALCSIZE_PARAMS FAR* lpncsp) 
  440. {
  441. // TODO: Add your message handler code here and/or call default
  442. CFrameWnd::OnNcCalcSize(bCalcValidRects, lpncsp);
  443. }