mainfrm.cpp
来自「故障诊断工作涉及的领域相当广泛」· C++ 代码 · 共 289 行
CPP
289 行
// MainFrm.cpp : implementation of the CMainFrame class
//
#include "stdafx.h"
#include "richtest.h"
#include "MainFrm.h"
#include "Splash.h"
#include "systeminfo.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
BOOL
WINAPI
AnimateWindow(
HWND hWnd,
DWORD dwTime,
DWORD dwFlags);
/////////////////////////////////////////////////////////////////////////////
// CMainFrame
IMPLEMENT_DYNAMIC(CMainFrame, CMDIFrameWnd)
BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)
//{{AFX_MSG_MAP(CMainFrame)
ON_WM_CREATE()
ON_WM_CLOSE()
// ON_COMMAND(ID_SYSINFO, OnSysinfo)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
static UINT indicators[] =
{
ID_SEPARATOR, // status line indicator
ID_INDICATOR_CAPS,
ID_INDICATOR_NUM,
ID_INDICATOR_SCRL,
};
static UINT DrawButtons[]=
{
ID_DRAW_LINE,
ID_DRAW_CIRCLE,
ID_DRAW_ARC,
ID_DRAW_RECTANGLE,
ID_SEPARATOR,
ID_DRAW_FILLED_CIRCLE,
ID_DRAW_FILLED_RECTANGLE,
ID_SEPARATOR,
ID_DRAW_POINT,
ID_DRAW_TEXT,
};
/////////////////////////////////////////////////////////////////////////////
// CMainFrame construction/destruction
static UINT PropertyButtons[]=
{
ID_SETDLG,
ID_REDRAW,
ID_SEPARATOR,
ID_SEPARATOR,//颜色组合框
ID_SEPARATOR,
ID_SEPARATOR,//线型组合框
};
/////////////////////////////////////////////////////////////////////////////
// CMainFrame construction/destruction
CMainFrame::CMainFrame()
{ CDialog dlg(IDD_ABOUTBOX);
m_cxPaneWidth=-1;
m_bMenuSelected=FALSE;
}
CMainFrame::~CMainFrame()
{
}
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CMDIFrameWnd::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_wndDrawBar.Create(this, WS_CHILD | WS_VISIBLE |
CBRS_SIZE_DYNAMIC | CBRS_TOP | CBRS_TOOLTIPS | CBRS_FLYBY ,
IDR_DRAW_BAR) ||
!m_wndDrawBar.LoadBitmap(IDR_DRAW_BAR)||
!m_wndDrawBar.SetButtons(DrawButtons, sizeof(DrawButtons)/sizeof(UINT)))
{
TRACE0("Failed to create toolbar\n");
return -1; // fail to create
}
if (!CreatePropertyBar())
return -1;
if(!m_wndStatusBar.Init(this))
return -1;
// 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);
m_wndDrawBar.EnableDocking(CBRS_ALIGN_ANY);
EnableDocking(CBRS_ALIGN_ANY);
DockControlBar(&m_wndDrawBar);
m_wndDrawBar.SetWindowText("Draw");
// m_wndDialogBar.Create(this,IDD_DIALOGBAR,CBRS_TOP|CBRS_GRIPPER|CBRS_TOOLTIPS|CBRS_FLYBY|\
CBRS_SIZE_DYNAMIC,IDD_DIALOGBAR);
// m_wndDialogBar.EnableDocking(CBRS_ALIGN_ANY);
// EnableDocking(CBRS_ALIGN_ANY);
// DockControlBar(&m_wndDialogBar);
// CG: The following line was added by the Splash Screen component. CSplashWnd::ShowSplashScreen(this);
//AnimateWindow(GetSafeHwnd(),1000,AW_SLIDE|AW_HOR_POSITIVE);
return 0;
}
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
if( !CMDIFrameWnd::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;
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CMainFrame diagnostics
#ifdef _DEBUG
void CMainFrame::AssertValid() const
{
CMDIFrameWnd::AssertValid();
}
void CMainFrame::Dump(CDumpContext& dc) const
{
CMDIFrameWnd::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CMainFrame message handlers
void CMainFrame::OnClose()
{
// TODO: Add your message handler code here and/or call default
// AnimateWindow(GetSafeHwnd(),1000,AW_HIDE|AW_CENTER);
CMDIFrameWnd::OnClose();
}
BOOL CMainFrame::CreatePropertyBar()
{
const int nDropHeight = 100;
if (!m_wndPropertyBar.Create(this, WS_CHILD|WS_VISIBLE|CBRS_TOP|CBRS_SIZE_DYNAMIC |
CBRS_TOOLTIPS|CBRS_FLYBY, IDR_PROPERTY_BAR) ||
!m_wndPropertyBar.LoadBitmap(IDR_PROPERTY_BAR) ||
!m_wndPropertyBar.SetButtons(PropertyButtons, sizeof(PropertyButtons)/sizeof(UINT)))
{
TRACE0("Failed to create propertybar\n");
return FALSE; // fail to create
}
//第一个按钮与线型下拉列表框的间隔设置为12个象数宽
m_wndPropertyBar.SetButtonInfo(2, ID_SEPARATOR, TBBS_SEPARATOR, 12);
//设置线型下拉列表框的宽度
m_wndPropertyBar.SetButtonInfo(3, IDW_LINETYPE, TBBS_SEPARATOR, 200);
m_wndPropertyBar.SetButtonInfo(4, ID_SEPARATOR, TBBS_SEPARATOR, 12);
//设置颜色下拉列表框的宽度
m_wndPropertyBar.SetButtonInfo(5, IDW_COLOR, TBBS_SEPARATOR, 100);
CRect rect;
m_wndPropertyBar.GetItemRect(3, &rect);
rect.bottom = rect.top + nDropHeight;
//创建线型下拉列表框
if (!m_wndPropertyBar.m_wndLineTypeCmb.Create(
CBS_DROPDOWNLIST|WS_VISIBLE|WS_TABSTOP|
WS_VSCROLL|CBS_OWNERDRAWVARIABLE,
rect, &m_wndPropertyBar, IDW_LINETYPE))
{
TRACE0("Failed to create combo-box\n");
return FALSE;
}
//填充下拉列表项
m_wndPropertyBar.m_wndLineTypeCmb.AddItem(PS_SOLID,"Solid");
m_wndPropertyBar.m_wndLineTypeCmb.AddItem(PS_DASH,"Dash");
m_wndPropertyBar.m_wndLineTypeCmb.AddItem(PS_DOT,"Dot");
m_wndPropertyBar.m_wndLineTypeCmb.AddItem(PS_DASHDOT,"DashDot");
m_wndPropertyBar.m_wndLineTypeCmb.AddItem(PS_DASHDOTDOT,"DashDotDot");
m_wndPropertyBar.m_wndLineTypeCmb.AddItem(PS_NULL,"Null");
m_wndPropertyBar.m_wndLineTypeCmb.AddItem(PS_INSIDEFRAME,"InsideFrame");
//预先设定实线线型
m_wndPropertyBar.m_wndLineTypeCmb.SetCurSel(0);
//创建颜色下拉列表框
m_wndPropertyBar.GetItemRect(5, &rect);
rect.bottom = rect.top + nDropHeight;
if (!m_wndPropertyBar.m_wndColorCmb.Create(
CBS_DROPDOWNLIST|WS_VISIBLE|WS_TABSTOP|
WS_VSCROLL|CBS_OWNERDRAWVARIABLE,
rect, &m_wndPropertyBar, IDW_COLOR))
{
TRACE0("Failed to create combo-box\n");
return FALSE;
}
//填充列表项
m_wndPropertyBar.m_wndColorCmb.AddItem(RGB(255,0,0),"Red");
m_wndPropertyBar.m_wndColorCmb.AddItem(RGB(0,255,0),"Green");
m_wndPropertyBar.m_wndColorCmb.AddItem(RGB(0,0,255),"Blue");
m_wndPropertyBar.m_wndColorCmb.AddItem(RGB(255,255,0),"Yellow");
m_wndPropertyBar.m_wndColorCmb.AddItem(RGB(0,255,255),"LightBlue");
m_wndPropertyBar.m_wndColorCmb.AddItem(RGB(255,0,255),"Cyan");
m_wndPropertyBar.m_wndColorCmb.AddItem(RGB(0,0,0),"Black");
//预先设定黑色
m_wndPropertyBar.m_wndColorCmb.SetCurSel(6);
return TRUE;
}
void CMainFrame::OnInitMenuPopup(CMenu* pPopupMenu, UINT nIndex, BOOL bSysMenu)
{
CFrameWnd::OnInitMenuPopup(pPopupMenu, nIndex, bSysMenu);
if(m_cxPaneWidth==-1&&m_bMenuSelected)
{
m_wndStatusBar.GetPaneInfo(0,m_nPaneID,m_nPaneStyle,m_cxPaneWidth);
m_wndStatusBar.SetPaneInfo(0,m_nPaneID,SBPS_NOBORDERS|SBPS_STRETCH,10000);
}
}
void CMainFrame:: OnMenuSelect( UINT nItemID, UINT nFlags, HMENU hSysMenu )
{
CFrameWnd:: OnMenuSelect(nItemID,nFlags,hSysMenu);
if(nFlags==0xFFFF&&hSysMenu==0&&m_cxPaneWidth!=-1)
{
m_bMenuSelected=FALSE;
m_wndStatusBar.SetPaneInfo(0,m_nPaneID,m_nPaneStyle,m_cxPaneWidth);
m_cxPaneWidth=-1;
}
else
{
m_bMenuSelected=TRUE;
}
}
void CMainFrame::OnPaint()
{
CPaintDC dc(this); // device context for painting
// TODO: Add your message handler code here
//绘制状态条的SNAP,GRID,OTHRO窗格
CMyStatusBar* pStatus=(CMyStatusBar*)
AfxGetApp()->m_pMainWnd->GetDescendantWindow(ID_VIEW_STATUS_BAR);
pStatus->Redraw();
// Do not call CFrameWnd::OnPaint() for painting messages
}
//void CMainFrame::OnSysinfo()
//{
// TODO: Add your command handler code here
// systeminfo item;
// item.DoModal();
//}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?