📄 mainfrm.cpp
字号:
// 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 toolbar\n");
return -1; // fail to create
}
*/
if (!m_wndStatusBar.Create(this) ||
!m_wndStatusBar.SetIndicators(indicators,
sizeof(indicators)/sizeof(UINT)))
{
TRACE0("Failed to create status bar\n");
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);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -