You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

144 lines
3.9 KiB
C++

#include "stdafx.h"
#include "LaiPuLaser.h"
#include "DlgTimingProgress.h"
#include "afxdialogex.h"
#include "TimingProgressMgr.h"
#include "LaiPuLaserView.h"
#include "AllThreadMgr.h"
#include "GlobalFunction.h"
#include "WorkCmdInvoker.h"
#include "ProgramLaserTuiHuo.h"
#include "CommonFlowMgr.h"
#define UPDATE_INFO_TIMER 1
#define UPDATE_INFO_TIMER_DELAY 100
IMPLEMENT_DYNAMIC(CDlgTimingProgress, CDialogEx)
BEGIN_MESSAGE_MAP(CDlgTimingProgress, CDialogEx)
ON_WM_TIMER()
ON_BN_CLICKED(NEW_STOP_BTN, &CDlgTimingProgress::OnBnClickedStopBtn)
END_MESSAGE_MAP()
CDlgTimingProgress::CDlgTimingProgress(CWnd* pParent /*=NULL*/)
: CDialogEx(CDlgTimingProgress::IDD, pParent)
{
}
CDlgTimingProgress::~CDlgTimingProgress()
{
}
void CDlgTimingProgress::DoDataExchange(CDataExchange* pDX)
{
CDialogEx::DoDataExchange(pDX);
DDX_Control(pDX, IDC_WORK_PROGRESS, m_WorkProgress);
DDX_Control(pDX, NEW_STOP_BTN, m_StopBtn);
}
//屏蔽键盘操作
BOOL CDlgTimingProgress::PreTranslateMessage(MSG* pMsg)
{
if(pMsg->message==WM_KEYDOWN)
{
char c = pMsg->wParam;
if(c==VK_RETURN || c==VK_ESCAPE)
{
return TRUE;
}
}
return CDialogEx::PreTranslateMessage(pMsg);
}
BOOL CDlgTimingProgress::OnInitDialog()
{
CDialogEx::OnInitDialog();
if(gTimingProgressMgr.IsbCloseApp())
{
Sleep(1000);
gAllThreadMgr.StopAllThread();
}
gTimingProgressMgr.SetbExecuting(true);
SetTimer(UPDATE_INFO_TIMER,UPDATE_INFO_TIMER_DELAY,NULL);
if(gProgramLaserTuiHuo->IsbAutoWorking()
|| gCommonFlowMgr->IsbXyMoveTesting()
|| gTimingProgressMgr.IsbStopBtn()
)
{
GetDlgItem(NEW_STOP_BTN)->ShowWindow(SW_SHOW);
}
gTimingProgressMgr.SetbStopBtn(false);
//让对话框在最上层显示
CRect rect;
GetClientRect(&rect);
::SetWindowPos(m_hWnd, HWND_TOPMOST, 0, 0, rect.Width(), rect.Height(), SWP_NOMOVE);
UpdateData(FALSE);
return TRUE;
}
//防止Esc 关闭对话框
void CDlgTimingProgress::OnCancel()
{
return;
}
void CDlgTimingProgress::OnTimer(UINT nIDEvent)
{
if(nIDEvent == UPDATE_INFO_TIMER)
{
KillTimer(UPDATE_INFO_TIMER);
if(!gExitApp)
{
UpdateInfo();
SetTimer(UPDATE_INFO_TIMER,UPDATE_INFO_TIMER_DELAY,NULL);
}
}
CDialog::OnTimer(nIDEvent);
}
void CDlgTimingProgress::UpdateInfo()
{
//执行时间时间增加ms
gTimingProgressMgr.AddCurExecuteTime(UPDATE_INFO_TIMER_DELAY);
//时间到了,或者强制停止(非关闭软件时)
//if(!gTimingProgressMgr.IsbCloseApp() && (gTimingProgressMgr.CheckCurExecuteTime(-1)||gTimingProgressMgr.IsbStopExecute()))
//时间到了不要自动关闭
if(!gTimingProgressMgr.IsbCloseApp() && (gTimingProgressMgr.IsbStopExecute()))
{
gTimingProgressMgr.SetShowInfo("");
gTimingProgressMgr.SetbExecuting(false);
OnOK();
}
//关闭软件时(5秒后)等待所有线程关闭才结束
if(gTimingProgressMgr.IsbCloseApp() && gTimingProgressMgr.CheckCurExecuteTime(5000))
{
//如果这个时候还有线程在运行是不正常的,显示线程的名字
if(gAllThreadMgr.HasThreadRunning())
{
gAllThreadMgr.ShowRunningThreadName();
}
else
{
OnOK();
}
}
//显示没有关闭线程的名字
if(gTimingProgressMgr.IsbCloseApp() && (!gAllThreadMgr.HasThreadRunning()) && gTimingProgressMgr.CheckCurExecuteTime(5000))
{
OnOK();
}
CString NewShowInfo = gTimingProgressMgr.GetShowInfo();
if(NewShowInfo != m_ShowInfo)//变化时刷新
{
m_ShowInfo = NewShowInfo;
GetDlgItem(IDC_STATIC_EXECUTE_INFO)->SetWindowText(m_ShowInfo);
}
double progress = gTimingProgressMgr.GetProgressVal();
m_WorkProgress.SetPos((int)progress);
}
//停止
void CDlgTimingProgress::OnBnClickedStopBtn()
{
gLogMgr->WriteDebugLog("Func---->OnBnClickedTimingProgressStopBtn");
gStopAllWrokCmd = true;
GetDlgItem(NEW_STOP_BTN)->EnableWindow(false);
}