📄 wjcdlg.cpp
字号:
// WJCDlg.cpp : implementation file
//
#include "stdafx.h"
#include "WJC.h"
#include "WJCDlg.h"
#include "OScopeCtrl.h"
#include "BtnST.h"
#include "MaterialDlg.h"
#include "SensorSet.h"
#include "UserDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CWJCDlg dialog
CWJCDlg::CWJCDlg(CWnd* pParent /*=NULL*/)
: CDialog(CWJCDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CWJCDlg)
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
isInitView = FALSE;
nowTime = CTime::GetCurrentTime();
isRun = FALSE;
}
void CWJCDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CWJCDlg)
DDX_Control(pDX, IDC_STATIC_BAR, m_stbar);
DDX_Control(pDX, IDC_AUTO_ZERO, m_btnZero);
DDX_Control(pDX, IDC_BTN_DOWN, m_btnDown);
DDX_Control(pDX, IDC_BTN_START, m_btnStart);
DDX_Control(pDX, IDC_BTN_UP, m_btnUp);
DDX_Control(pDX, IDC_Timer, m_cTimer);
DDX_Control(pDX, IDC_Time_Force, m_cTF);
DDX_Control(pDX, IDC_MAX_FORCE, m_ctrLenMF);
DDX_Control(pDX, IDC_VIEW_TEST, m_ctrlVT);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CWJCDlg, CDialog)
//{{AFX_MSG_MAP(CWJCDlg)
ON_WM_ERASEBKGND()
ON_WM_SYSCOMMAND()
ON_WM_DESTROY()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_COMMAND(IC_TEST, OnTest)
ON_COMMAND(IC_EXIT, OnExit)
ON_COMMAND(IC_HELP, OnHelp)
ON_COMMAND(IC_ABOUT, OnAbout)
ON_COMMAND(IC_EXIT_TEST, OnExitTest)
ON_WM_TIMER()
ON_COMMAND(IC_MATERIAL, OnMaterial)
ON_COMMAND(ID_SENSOR_SET, OnSensorSet)
ON_COMMAND(IC_LOGO_IN, OnLogoIn)
ON_COMMAND(IC_LOGO_OUT, OnLogoOut)
ON_COMMAND(IC_MATERIAL_UPDATE, OnMaterialUpdate)
ON_COMMAND(IC_SAVE_DATA, OnSaveData)
ON_COMMAND(IC_TEST_SET, OnTestSet)
ON_COMMAND(IC_TEST_UPDATE, OnTestUpdate)
ON_COMMAND(IC_USER_UPDATE, OnUserUpdate)
ON_COMMAND(ID_SENSOR_UPDATE, OnSensorUpdate)
ON_BN_CLICKED(IDC_AUTO_ZERO, OnAutoZero)
ON_BN_CLICKED(IDC_BTN_DOWN, OnBtnDown)
ON_BN_CLICKED(IDC_BTN_START, OnBtnStart)
ON_BN_CLICKED(IDC_BTN_UP, OnBtnUp)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CWJCDlg message handlers
BOOL CWJCDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
DWORD dwStyles = m_stbar.GetTBar().GetStyle();
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
}
void CWJCDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
void CWJCDlg::OnDestroy()
{
WinHelp(0L, HELP_QUIT);
CDialog::OnDestroy();
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CWJCDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
//ExchangeBG(1);
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CWJCDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
//
BOOL CWJCDlg::OnEraseBkgnd(CDC* pDC)
{
CDC memDC;
CBitmap MJBmp;
if(!isInitView)
{
if(!MJBmp.LoadBitmap(IDB_BITMAP1))
return FALSE; ;
}
else
{
if(!MJBmp.LoadBitmap(IDB_BITMAP2))
return FALSE; ;
}
memDC.CreateCompatibleDC(pDC);
CBitmap *pOldBmp=memDC.SelectObject(&MJBmp);
CRect rect;
GetClientRect(&rect);
pDC->BitBlt(0,0,rect.Width(),rect.Height(),&memDC,0,0,SRCCOPY);
memDC.SelectObject(pOldBmp);
return TRUE;
}
void CWJCDlg::OnTest()
{
// TODO: Add your command handler code here
m_ctrLenMF.MoveWindow(490,55,135,35);
m_ctrLenMF.SetColor(DARKGREEN, LIGHTGREEN);
m_ctrLenMF.SetText("0000.00");
VERIFY(m_ctrLenMF.ModifyDigiStyle(0, CDigistring::DS_SZ_PROP));
m_btnZero.MoveWindow(360,55,100,35);
m_btnZero.SetTooltipText("自动调零!");
m_btnZero.DrawTransparent();
m_btnStart.MoveWindow(65,115,60,60);
m_btnStart.SetTooltipText("开始按钮!");
m_btnStart.DrawTransparent();
m_btnUp.MoveWindow(108,214,30,30);
m_btnUp.SetTooltipText("上升按钮!");
m_btnUp.DrawTransparent();
m_btnDown.MoveWindow(45,214,30,30);
m_btnDown.SetTooltipText("下降按钮!");
m_btnDown.DrawTransparent();
m_cTF.MoveWindow(200,55,135,35);
m_cTF.SetColor(DARKGREEN, LIGHTGREEN);
m_cTF.SetText("0000.00");
VERIFY(m_cTF.ModifyDigiStyle(0, CDigistring::DS_SZ_PROP));
m_cTimer.MoveWindow(25,300,135,35);
m_cTimer.SetColor(DARKRED, LIGHTRED);
m_cTimer.SetText("00:00:00");
VERIFY(m_cTimer.ModifyDigiStyle(CDigistring::DS_SZ_PROP, 0));
m_ctrlVT.MoveWindow(180,100,600,410);
m_ctrlVT.MoveWindow(180,100,600,410);
if(!isInitView)
{
CRect rect;
GetDlgItem(IDC_VIEW_TEST)->GetWindowRect(rect) ;
ScreenToClient(rect) ;
// create the control
m_ctr_View.Create(WS_VISIBLE | WS_CHILD, rect, this) ;
m_ctr_View.MoveWindow(180,100,600,410);
isInitView = TRUE;
}
else
{
m_ctr_View.MoveWindow(180,100,600,410);
}
m_ctr_View.SetType(0);
m_ctr_View.SetRangeH(0,13000);
m_ctr_View.SetRangeV(0,2300);
m_ctr_View.SetYUnits("应力");
m_ctr_View.SetBackgroundColor(RGB(60,38,120));
m_ctr_View.SetGridColor(RGB(0,255,255));
m_ctr_View.SetXUnits("应变");
m_ctr_View.SetTopic("应力—应变图");
m_ctr_View.SetGridN(5);
ExchangeBG(2);
}
void CWJCDlg::OnExit()
{
// TODO: Add your command handler code here
CDialog::OnOK();
}
void CWJCDlg::OnHelp()
{
// TODO: Add your command handler code here
CDialog::OnHelp();
}
void CWJCDlg::OnAbout()
{
// TODO: Add your command handler code here
CAboutDlg aboutDlg;
aboutDlg.DoModal();
}
void CWJCDlg::OnExitTest()
{
// TODO: Add your command handler code here
m_ctrlVT.MoveWindow(40,100,1,10);
m_ctr_View.MoveWindow(40,100,1,10);
ExchangeBG(1);
}
void CWJCDlg::ExchangeBG(int n)
{
CDC *pDC = CWJCDlg::GetDC();
CDC memDC;
CBitmap MJBmp;
if(n == 1)
{
if(!MJBmp.LoadBitmap(IDB_BITMAP1))
return ;
}
else
{
if(!MJBmp.LoadBitmap(IDB_BITMAP2))
return ;
}
memDC.CreateCompatibleDC(pDC);
CBitmap *pOldBmp=memDC.SelectObject(&MJBmp);
CRect rect;
GetClientRect(&rect);
pDC->BitBlt(0,0,rect.Width(),rect.Height(),&memDC,0,0,SRCCOPY);
memDC.SelectObject(pOldBmp);
}
void CWJCDlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
//nowTime = CTime::GetCurrentTime();
UpdateTime();
m_cTimer.SetText(theTime.str);
CDialog::OnTimer(nIDEvent);
}
void CWJCDlg::OnMaterial()
{
// TODO: Add your command handler code here
CMaterialDlg dlgMaterial;
dlgMaterial.DoModal();
}
void CWJCDlg::OnSensorSet()
{
// TODO: Add your command handler code here
CSensorSet dlgSensor;
dlgSensor.DoModal();
}
void CWJCDlg::OnLogoIn()
{
// TODO: Add your command handler code here
CUserDlg dlgUser;
dlgUser.DoModal();
}
void CWJCDlg::OnLogoOut()
{
// TODO: Add your command handler code here
}
void CWJCDlg::OnMaterialUpdate()
{
// TODO: Add your command handler code here
}
void CWJCDlg::OnSaveData()
{
// TODO: Add your command handler code here
}
void CWJCDlg::OnTestSet()
{
// TODO: Add your command handler code here
}
void CWJCDlg::OnTestUpdate()
{
// TODO: Add your command handler code here
}
void CWJCDlg::OnUserUpdate()
{
// TODO: Add your command handler code here
}
void CWJCDlg::OnSensorUpdate()
{
// TODO: Add your command handler code here
}
void CWJCDlg::OnAutoZero()
{
// TODO: Add your control notification handler code here
}
void CWJCDlg::OnBtnDown()
{
// TODO: Add your control notification handler code here
}
void CWJCDlg::OnBtnStart()
{
// TODO: Add your control notification handler code here
theTime.hou =0;
theTime.min =0;
theTime.sec = 0;
theTime.str = "";
isRun ^= TRUE;
if(isRun)
{
m_btnStart.SetState(isRun);
SetTimer(1,1,NULL);
return;
}
m_btnStart.SetState(FALSE);
KillTimer(1);
}
void CWJCDlg::OnBtnUp()
{
// TODO: Add your control notification handler code here
}
void CWJCDlg::UpdateTime()
{
theTime.sec++;
if(theTime.sec == 60)
{
theTime.sec = 0;
theTime.min++;
}
if(theTime.min == 60)
{
theTime.hou++;
theTime.min = 0;
}
CString temp;
temp.Format("%d",theTime.hou);
if(temp.GetLength() == 1)
{
temp ="0"+temp;
}
theTime.str=temp;
temp.Format("%d",theTime.min);
if(temp.GetLength() == 1)
{
temp ="0"+temp;
}
theTime.str=theTime.str+":"+temp;
temp.Format("%d",theTime.sec);
if(temp.GetLength() == 1)
{
temp ="0"+temp;
}
theTime.str=theTime.str+":"+temp;
}
BOOL CWJCDlg::PreTranslateMessage(MSG* pMsg)
{
if(m_stbar.m_hWnd)
m_stbar.PreTranslate(pMsg);
return CDialog::PreTranslateMessage(pMsg);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -