MainFrm.cpp
资源名称:心跳检测.rar [点击查看]
上传用户:dtengfei
上传日期:2013-01-16
资源大小:393k
文件大小:15k
源码类别:
医药行业
开发平台:
Visual C++
- // MainFrm.cpp : implementation of the CMainFrame class
- //
- #include "stdafx.h"
- #include "心跳检测.h"
- #include "心跳检测Doc.h"
- #include "心跳检测View.h"
- #include "MainFrm.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CMainFrame
- IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
- BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
- //{{AFX_MSG_MAP(CMainFrame)
- ON_MESSAGE(WM_REFRESH,OnRefresh)
- ON_WM_CREATE()
- ON_WM_DESTROY()
- ON_WM_DRAWITEM()
- ON_WM_GETMINMAXINFO()
- ON_WM_MEASUREITEM()
- ON_WM_NCLBUTTONDBLCLK()
- ON_WM_NCLBUTTONDOWN()
- ON_WM_NCMOUSEMOVE()
- ON_WM_NCCALCSIZE()
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- static UINT indicators[] =
- {
- ID_SEPARATOR, // status line indicator
- ID_INDICATOR_CAPS,
- ID_INDICATOR_NUM,
- ID_INDICATOR_SCRL,
- };
- /////////////////////////////////////////////////////////////////////////////
- // CMainFrame construction/destruction
- CMainFrame::CMainFrame()
- {
- // TODO: add member initialization code here
- TP.PointNumber=0;
- TP.runing=FALSE;
- TP.WholeNumber=1000;
- }
- CMainFrame::~CMainFrame()
- {
- ::PostThreadMessage(m_JiqiThreadID,WM_THREADEND,NULL,NULL);
- }
- int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
- {
- if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
- return -1;
- /* if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
- | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
- !m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
- {
- TRACE0("Failed to create toolbarn");
- return -1; // fail to create
- }
- */
- if (!m_wndStatusBar.Create(this) ||
- !m_wndStatusBar.SetIndicators(indicators,
- sizeof(indicators)/sizeof(UINT)))
- {
- TRACE0("Failed to create status barn");
- return -1; // fail to create
- }
- // TODO: Delete these three lines if you don't want the toolbar to
- // be dockable
- /* m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
- EnableDocking(CBRS_ALIGN_ANY);
- DockControlBar(&m_wndToolBar);
- */
- //建立Jiqi线程
- m_pJiqiThread=(CJiqi *)AfxBeginThread(RUNTIME_CLASS(CJiqi));
- m_JiqiThreadID=m_pJiqiThread->m_nThreadID;
- m_MainThreadID=::GetCurrentThreadId();
- m_pJiqiThread->m_MainThreadID=m_MainThreadID;
- m_pJiqiThread->hMainWnd=AfxGetMainWnd()->GetSafeHwnd();
- CControl m_Dlg;
- if(m_Dlg.Init()!=1)
- {
- MessageBox("板卡初始化失败!请检查后重新运行");
- _exit(0);
- }
- return 0;
- }
- BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
- {
- if( !CFrameWnd::PreCreateWindow(cs) )
- return FALSE;
- // TODO: Modify the Window class or styles here by modifying
- // the CREATESTRUCT cs
- /*
- cs.style = WS_OVERLAPPED | WS_CAPTION | FWS_ADDTOTITLE
- | WS_THICKFRAME | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_MAXIMIZE;
- */
- /* if(cs.hMenu!=NULL)
- {
- ::DestroyMenu(cs.hMenu); // 如果菜单已经载入,则删除掉
- cs.hMenu = NULL; // 设置窗口菜单为NULL
- }
- */
- cs.cx=1024;
- cs.cy=768;
- cs.style^=WS_MAXIMIZEBOX|WS_MINIMIZEBOX;
- return TRUE;
- }
- /////////////////////////////////////////////////////////////////////////////
- // CMainFrame diagnostics
- #ifdef _DEBUG
- void CMainFrame::AssertValid() const
- {
- CFrameWnd::AssertValid();
- }
- void CMainFrame::Dump(CDumpContext& dc) const
- {
- CFrameWnd::Dump(dc);
- }
- #endif //_DEBUG
- /////////////////////////////////////////////////////////////////////////////
- // CMainFrame message handlers
- LRESULT CMainFrame::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam)
- {
- // TODO: Add your specialized code here and/or call the base class
- LRESULT lrst=CFrameWnd::DefWindowProc(message, wParam, lParam);
- if (!::IsWindow(m_hWnd))
- return lrst;
- if (message == WM_MOVE || message == WM_NCPAINT ||message == WM_NCACTIVATE ||message == WM_NOTIFY)
- {
- CDC* pWinDC = GetWindowDC();
- if (pWinDC)
- DrawTitleBar(pWinDC);
- ReleaseDC(pWinDC);
- }
- return lrst;
- return CFrameWnd::DefWindowProc(message, wParam, lParam);
- }
- void CMainFrame::DrawTitleBar(CDC *pDC)
- {
- if (m_hWnd)
- {
- CBrush Brush(RGB(0,100,255));
- CBrush* pOldBrush = pDC->SelectObject(&Brush);
- CRect rtWnd, rtTitle, rtButtons;
- GetWindowRect(&rtWnd);
- //取得标题栏的位置
- rtTitle.left = GetSystemMetrics(SM_CXFRAME);
- rtTitle.top = GetSystemMetrics(SM_CYFRAME);
- rtTitle.right = rtWnd.right - rtWnd.left - GetSystemMetrics(SM_CXFRAME);
- rtTitle.bottom = rtTitle.top + GetSystemMetrics(SM_CYSIZE);
- CPoint point;
- //填充顶部框架
- point.x = rtWnd.Width();
- point.y = GetSystemMetrics(SM_CYSIZE) + GetSystemMetrics(SM_CYFRAME)+1;
- pDC->PatBlt(0, 0, point.x, point.y, PATCOPY);
- //填充左侧框架
- point.x = GetSystemMetrics(SM_CXFRAME);
- point.y = rtWnd.Height();
- // pDC->PatBlt(0, 0, point.x, point.y, PATCOPY);
- pDC->PatBlt(0, 0, 300, 41, PATCOPY);
- //填充底部框架
- point.x = rtWnd.Width();
- point.y = GetSystemMetrics(SM_CYFRAME);
- pDC->PatBlt(0, rtWnd.Height()-point.y, point.x, point.y, PATCOPY);
- //填充右侧框架
- point.x = GetSystemMetrics(SM_CXFRAME);
- point.y = rtWnd.Height();
- pDC->PatBlt(rtWnd.Width()-point.x, 0, point.x, point.y, PATCOPY);
- //填充菜单下部框架
- point.x = rtWnd.Width();
- point.y = GetSystemMetrics(SM_CYFRAME)-1;
- pDC->PatBlt(0, GetSystemMetrics(SM_CYMENU)+GetSystemMetrics(SM_CYSIZE)+point.y, point.x, point.y, PATCOPY);
- //填充菜单右侧框架
- point.x = rtWnd.Width() - 230;
- point.y = GetSystemMetrics(SM_CYMENU);
- pDC->PatBlt(230, GetSystemMetrics(SM_CYSIZE)+GetSystemMetrics(SM_CYFRAME), point.x, point.y, PATCOPY);
- //绘制美化线条
- CBrush BrushLine(RGB(255, 255, 255));
- pDC->SelectObject(&BrushLine);
- point.x = rtWnd.Width() - 150;
- point.y = GetSystemMetrics(SM_CYFRAME) + 2;
- pDC->PatBlt(GetSystemMetrics(SM_CXFRAME), point.y, point.x, 1, PATCOPY);
- point.y += 5;
- pDC->PatBlt(GetSystemMetrics(SM_CXFRAME), point.y, point.x, 1, PATCOPY);
- point.y += 5;
- pDC->PatBlt(GetSystemMetrics(SM_CXFRAME), point.y, point.x, 1, PATCOPY);
- point.x += 60;
- point.y += 12;
- pDC->PatBlt(point.x, point.y, 85, 1, PATCOPY);
- point.y += 5;
- pDC->PatBlt(point.x, point.y, 85, 1, PATCOPY);
- point.x -= 60 - GetSystemMetrics(SM_CXFRAME);
- point.y += 5;
- pDC->PatBlt(point.x, point.y, 145-GetSystemMetrics(SM_CXFRAME) , 1, PATCOPY);
- point.y -= 32;
- pDC->PatBlt(point.x, point.y, 1 , 32, PATCOPY);
- pDC->SelectObject(pOldBrush);
- //重画图标
- m_rtIcon.left = rtWnd.Width() - 135;
- m_rtIcon.top = GetSystemMetrics(SM_CYFRAME);
- m_rtIcon.right = m_rtIcon.left + 32;
- m_rtIcon.bottom = m_rtIcon.top + 32;
- ::DrawIconEx(pDC->m_hDC, m_rtIcon.left, m_rtIcon.top, AfxGetApp()->LoadIcon(IDI_EOAPP),
- m_rtIcon.Width(), m_rtIcon.Height(), 0, NULL, DI_NORMAL);
- m_rtIcon.OffsetRect(rtWnd.TopLeft());
- //准备画XP风格按钮
- CBitmap* pBitmap = new CBitmap;
- CBitmap* pOldBitmap;
- CDC* pDisplayMemDC=new CDC;
- pDisplayMemDC->CreateCompatibleDC(pDC);
- //重画关闭button
- rtButtons.left = rtTitle.right - 19;
- rtButtons.top = rtTitle.top;
- rtButtons.right = rtButtons.left + 19;
- rtButtons.bottom = rtButtons.top + 19;
- pBitmap->LoadBitmap(IDB_EXIT_NORMAL);
- pOldBitmap=(CBitmap*)pDisplayMemDC->SelectObject(pBitmap);
- pDC->BitBlt(rtButtons.left, rtButtons.top, rtButtons.Width(), rtButtons.Height(), pDisplayMemDC, 0, 0, SRCCOPY);
- pDisplayMemDC->SelectObject(pOldBitmap);
- m_rtButtExit = rtButtons;
- m_rtButtExit.OffsetRect(rtWnd.TopLeft());
- pBitmap->DeleteObject();
- //重画最大化/恢复button
- rtButtons.right = rtButtons.left - 3;
- rtButtons.left = rtButtons.right - 19;
- if (IsZoomed())
- pBitmap->LoadBitmap(IDB_RESTORE_NORMAL);
- else
- pBitmap->LoadBitmap(IDB_MAX_NORMAL);
- pOldBitmap=(CBitmap*)pDisplayMemDC->SelectObject(pBitmap);
- pDC->BitBlt(rtButtons.left, rtButtons.top, rtButtons.Width(), rtButtons.Height(), pDisplayMemDC, 0, 0, SRCCOPY);
- pDisplayMemDC->SelectObject(pOldBitmap);
- m_rtButtMax = rtButtons;
- m_rtButtMax.OffsetRect(rtWnd.TopLeft());
- pBitmap->DeleteObject();
- //重画最小化button
- rtButtons.right = rtButtons.left - 3;
- rtButtons.left = rtButtons.right - 19;
- pBitmap->LoadBitmap(IDB_MIN_NORMAL);
- pOldBitmap=(CBitmap*)pDisplayMemDC->SelectObject(pBitmap);
- pDC->BitBlt(rtButtons.left, rtButtons.top, rtButtons.Width(), rtButtons.Height(), pDisplayMemDC, 0, 0, SRCCOPY);
- pDisplayMemDC->SelectObject(pOldBitmap);
- m_rtButtMin = rtButtons;
- m_rtButtMin.OffsetRect(rtWnd.TopLeft());
- pBitmap->DeleteObject();
- //重画帮助button
- rtButtons.right = rtButtons.left - 3;
- rtButtons.left = rtButtons.right - 19;
- pBitmap->LoadBitmap(IDB_HELP_NORMAL);
- pOldBitmap=(CBitmap*)pDisplayMemDC->SelectObject(pBitmap);
- pDC->BitBlt(rtButtons.left, rtButtons.top, rtButtons.Width(), rtButtons.Height(), pDisplayMemDC, 0, 0, SRCCOPY);
- pDisplayMemDC->SelectObject(pOldBitmap);
- m_rtButtHelp = rtButtons;
- m_rtButtHelp.OffsetRect(rtWnd.TopLeft());
- pBitmap->DeleteObject();
- //重画caption
- int nOldMode = pDC->SetBkMode(TRANSPARENT);
- COLORREF clOldText=pDC->SetTextColor(RGB(255, 255, 255));
- pDC->SelectStockObject(SYSTEM_FIXED_FONT);
- rtTitle.left += 240;
- rtTitle.top += GetSystemMetrics(SM_CYSIZE) + 2;
- rtTitle.bottom = rtTitle.top + 30;
- CString m_strTitle;
- m_strTitle.Format ("心 率 信 号 检 测");
- pDC->DrawText(m_strTitle, &rtTitle, DT_LEFT);
- pDC->SetBkMode(nOldMode);
- pDC->SetTextColor(clOldText);
- ReleaseDC(pDisplayMemDC);
- delete pDisplayMemDC;
- delete pBitmap;
- }
- }
- void CMainFrame::OnDestroy()
- {
- CFrameWnd::OnDestroy();
- // TODO: Add your message handler code here
- }
- void CMainFrame::OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct)
- {
- // TODO: Add your message handler code here and/or call default
- if(lpDrawItemStruct->CtlType == ODT_MENU)
- {
- // m_hMenu.DrawItem(lpDrawItemStruct);
- return ;
- }
- CFrameWnd::OnDrawItem(nIDCtl, lpDrawItemStruct);
- }
- void CMainFrame::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI)
- {
- // TODO: Add your message handler code here and/or call default
- CRect rectWindow;
- GetWindowRect(&rectWindow);
- CRect rectClient;
- GetClientRect(&rectClient);
- // get offset of toolbars, scrollbars, etc.
- int nWidthOffset = rectWindow.Width() - rectClient.Width();
- int nHeightOffset = rectWindow.Height() - rectClient.Height();
- lpMMI->ptMinTrackSize.x = 500 + nWidthOffset;
- lpMMI->ptMinTrackSize.y = 300 + nHeightOffset;
- CFrameWnd::OnGetMinMaxInfo(lpMMI);
- }
- void CMainFrame::OnMeasureItem(int nIDCtl, LPMEASUREITEMSTRUCT lpMeasureItemStruct)
- {
- // TODO: Add your message handler code here and/or call default
- if(lpMeasureItemStruct->CtlType == ODT_MENU)
- {
- // m_hMenu.MeasureItem(lpMeasureItemStruct);
- return ;
- }
- CFrameWnd::OnMeasureItem(nIDCtl, lpMeasureItemStruct);
- }
- void CMainFrame::OnNcLButtonDblClk(UINT nHitTest, CPoint point)
- {
- if (IsZoomed())
- SendMessage(WM_SYSCOMMAND, SC_RESTORE, MAKELPARAM(point.x, point.y));
- else
- SendMessage(WM_SYSCOMMAND, SC_MAXIMIZE, MAKELPARAM(point.x, point.y));
- CFrameWnd::OnNcLButtonDblClk(nHitTest, point);
- }
- void CMainFrame::OnNcLButtonDown(UINT nHitTest, CPoint point)
- {
- //检测各按钮是否按到
- if (m_rtIcon.PtInRect(point))
- AfxMessageBox("欢迎访问森太公司主页 www.ccut.edu.cn");
- else if (m_rtButtHelp.PtInRect(point))
- // AfxMessageBox("如有问题,请与本人联系:gwqlxq@mail.ccut.edu.cn");
- // m_dlgconnect.DoModal ();
- {
- // CAboutDlg mDlg;
- // mDlg.DoModal();
- }
- else if (m_rtButtExit.PtInRect(point))
- SendMessage(WM_CLOSE);
- else if (m_rtButtMin.PtInRect(point))
- SendMessage(WM_SYSCOMMAND, SC_MINIMIZE, MAKELPARAM(point.x, point.y));
- else if (m_rtButtMax.PtInRect(point))
- {
- if (IsZoomed())
- SendMessage(WM_SYSCOMMAND, SC_RESTORE, MAKELPARAM(point.x, point.y));
- else
- SendMessage(WM_SYSCOMMAND, SC_MAXIMIZE, MAKELPARAM(point.x, point.y));
- }
- else if (!IsZoomed())
- Default();
- else if (nHitTest&HTMENU)
- CFrameWnd::OnNcLButtonDown(nHitTest, point);
- }
- void CMainFrame::OnNcMouseMove(UINT nHitTest, CPoint point)
- {
- // TODO: Add your message handler code here and/or call default
- CDC* pDC = GetWindowDC();
- CDC* pDisplayMemDC=new CDC;
- pDisplayMemDC->CreateCompatibleDC(pDC);
- CBitmap* pBitmap = new CBitmap;
- CBitmap* pOldBitmap;
- CRect rtWnd, rtButton;
- if (pDC)
- {
- GetWindowRect(&rtWnd);
- //关闭button
- if (m_rtButtExit.PtInRect(point))
- pBitmap->LoadBitmap(IDB_EXIT_FOCUS);
- else
- pBitmap->LoadBitmap(IDB_EXIT_NORMAL);
- rtButton = m_rtButtExit;
- rtButton.OffsetRect(-rtWnd.left, -rtWnd.top);
- pOldBitmap=(CBitmap*)pDisplayMemDC->SelectObject(pBitmap);
- pDC->BitBlt(rtButton.left, rtButton.top, rtButton.Width(), rtButton.Height(), pDisplayMemDC, 0, 0, SRCCOPY);
- pDisplayMemDC->SelectObject(pOldBitmap);
- pBitmap->DeleteObject();
- //最大化/恢复button
- if (m_rtButtMax.PtInRect(point))
- {
- if (IsZoomed())
- pBitmap->LoadBitmap(IDB_RESTORE_FOCUS);
- else
- pBitmap->LoadBitmap(IDB_MAX_FOCUS);
- }
- else
- {
- if (IsZoomed())
- pBitmap->LoadBitmap(IDB_RESTORE_NORMAL);
- else
- pBitmap->LoadBitmap(IDB_MAX_NORMAL);
- }
- rtButton = m_rtButtMax;
- rtButton.OffsetRect(-rtWnd.left, -rtWnd.top);
- pOldBitmap=(CBitmap*)pDisplayMemDC->SelectObject(pBitmap);
- pDC->BitBlt(rtButton.left, rtButton.top, rtButton.Width(), rtButton.Height(), pDisplayMemDC, 0, 0, SRCCOPY);
- pDisplayMemDC->SelectObject(pOldBitmap);
- pBitmap->DeleteObject();
- //最小化button
- if (m_rtButtMin.PtInRect(point))
- pBitmap->LoadBitmap(IDB_MIN_FOCUS);
- else
- pBitmap->LoadBitmap(IDB_MIN_NORMAL);
- rtButton = m_rtButtMin;
- rtButton.OffsetRect(-rtWnd.left, -rtWnd.top);
- pOldBitmap=(CBitmap*)pDisplayMemDC->SelectObject(pBitmap);
- pDC->BitBlt(rtButton.left, rtButton.top, rtButton.Width(), rtButton.Height(), pDisplayMemDC, 0, 0, SRCCOPY);
- pDisplayMemDC->SelectObject(pOldBitmap);
- pBitmap->DeleteObject();
- //帮助button
- if (m_rtButtHelp.PtInRect(point))
- pBitmap->LoadBitmap(IDB_HELP_FOCUS);
- else
- pBitmap->LoadBitmap(IDB_HELP_NORMAL);
- rtButton = m_rtButtHelp;
- rtButton.OffsetRect(-rtWnd.left, -rtWnd.top);
- pOldBitmap=(CBitmap*)pDisplayMemDC->SelectObject(pBitmap);
- pDC->BitBlt(rtButton.left, rtButton.top, rtButton.Width(), rtButton.Height(), pDisplayMemDC, 0, 0, SRCCOPY);
- pDisplayMemDC->SelectObject(pOldBitmap);
- pBitmap->DeleteObject();
- }
- ReleaseDC(pDisplayMemDC);
- ReleaseDC(pDC);
- delete pDisplayMemDC;
- delete pBitmap;
- CFrameWnd::OnNcMouseMove(nHitTest, point);
- }
- void CMainFrame::OnRefresh(int Point)
- {
- CMyView* pView=(CMyView *)GetActiveView();
- pView->Draw(Point);
- }
- BOOL CMainFrame::PreTranslateMessage(MSG* pMsg)
- {
- // TODO: Add your specialized code here and/or call the base class
- if(pMsg->message==WM_REFRESH)
- {
- OnRefresh(TP.PointNumber);
- return TRUE;
- }
- else
- return CFrameWnd::PreTranslateMessage(pMsg);
- }
- void CMainFrame::OnNcCalcSize(BOOL bCalcValidRects, NCCALCSIZE_PARAMS FAR* lpncsp)
- {
- // TODO: Add your message handler code here and/or call default
- CFrameWnd::OnNcCalcSize(bCalcValidRects, lpncsp);
- }