LIFTTDlg.cpp
资源名称:LIFTT.rar [点击查看]
上传用户:jmteguang
上传日期:2022-05-24
资源大小:61k
文件大小:11k
源码类别:
进程与线程
开发平台:
Visual C++
- // LIFTTDlg.cpp : 实现文件
- //
- #include "stdafx.h"
- #include "LIFTT.h"
- #include "LIFTTDlg.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #endif
- // 用于应用程序“关于”菜单项的 CAboutDlg 对话框
- class CAboutDlg : public CDialog
- {
- public:
- CAboutDlg();
- // 对话框数据
- enum { IDD = IDD_ABOUTBOX };
- protected:
- virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持
- // 实现
- protected:
- DECLARE_MESSAGE_MAP()
- };
- CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
- {
- }
- void CAboutDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- }
- BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
- END_MESSAGE_MAP()
- // CLIFTTDlg 对话框
- CLIFTTDlg::CLIFTTDlg(CWnd* pParent /*=NULL*/)
- : CDialog(CLIFTTDlg::IDD, pParent)
- {
- m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
- }
- void CLIFTTDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- }
- BEGIN_MESSAGE_MAP(CLIFTTDlg, CDialog)
- ON_WM_SYSCOMMAND()
- ON_WM_PAINT()
- ON_WM_QUERYDRAGICON()
- //}}AFX_MSG_MAP
- ON_WM_CLOSE()
- ON_MESSAGE(WM_BUTTONCLICK,&CLIFTTDlg::OnGetButton)
- END_MESSAGE_MAP()
- // CLIFTTDlg 消息处理程序
- BOOL CLIFTTDlg::OnInitDialog()
- {
- CDialog::OnInitDialog();
- // 将“关于...”菜单项添加到系统菜单中。
- // IDM_ABOUTBOX 必须在系统命令范围内。
- 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);
- }
- }
- // 设置此对话框的图标。当应用程序主窗口不是对话框时,框架将自动
- // 执行此操作
- SetIcon(m_hIcon, TRUE); // 设置大图标
- SetIcon(m_hIcon, FALSE); // 设置小图标
- // TODO: 在此添加额外的初始化代码
- for (int i = 0;i < 20;i ++)
- {
- theApp.liftButton[i].SetAllNum(LIFTUP);
- theApp.liftButton[i].SetButtonNum(i+1);
- theApp.liftButton[i].Create(L"↑",WS_VISIBLE|BS_VCENTER|BS_CENTER|WS_CHILD,CRect(30,505-i*25,80,530-i*25),this,0);
- }
- for (int i = 0;i < 20;i ++)
- {
- theApp.liftButton[i+20].SetAllNum(LIFTDOWN);
- theApp.liftButton[i+20].SetButtonNum(i+1);
- theApp.liftButton[i+20].Create(L"↓",WS_VISIBLE|BS_VCENTER|BS_CENTER|WS_CHILD,CRect(80,505-i*25,130,530-i*25),this,0);
- }
- theApp.liftButton[19].EnableWindow(FALSE);
- theApp.liftButton[20].EnableWindow(FALSE);
- CString cstr;
- for (int i = 0;i < 20;i ++)
- {
- cstr.Format(L"%d",i+1);
- theApp.liftButton[i+40].SetAllNum(LIFTIN);
- theApp.liftButton[i+40].SetButtonNum(i+1);
- theApp.liftButton[i+40].Create(cstr,WS_VISIBLE|BS_VCENTER|BS_CENTER|WS_CHILD,CRect(130,505-i*25,180,530-i*25),this,0);
- theApp.liftButton[i+40].EnableWindow(FALSE);
- }
- for (int i = 0;i < 5;i ++)
- {
- cstr.Format(L"%d",i+1);
- liftThread[i].liftSet.SetAllNum(LIFTCTR);
- liftThread[i].liftSet.SetButtonNum(i+1);
- liftThread[i].liftSet.Create(cstr,WS_VISIBLE|BS_VCENTER|BS_CENTER|WS_CHILD,CRect(180,430-i*100,230,530-i*100),this,0);
- }
- for (int i = 0;i < 5;i ++)
- {
- liftThread[i].liftMove.SetAllNum(LIFTWARN);
- liftThread[i].liftMove.SetButtonNum(i+1);
- liftThread[i].liftMove.Create(L"关",WS_VISIBLE|BS_VCENTER|BS_CENTER|WS_CHILD,CRect(280+i*100,505,380+i*100,530),this,i+120);
- }
- theApp.liftButton[70].SetAllNum(LIFTOPEN);
- theApp.liftButton[70].SetButtonNum(0);
- theApp.liftButton[71].SetAllNum(LIFTCLOSE);
- theApp.liftButton[71].SetButtonNum(0);
- theApp.liftButton[70].Create(L"O",WS_VISIBLE|BS_VCENTER|BS_CENTER|WS_CHILD,CRect(230,30,280,280),this,0);
- theApp.liftButton[70].EnableWindow(FALSE);
- theApp.liftButton[71].Create(L"C",WS_VISIBLE|BS_VCENTER|BS_CENTER|WS_CHILD,CRect(230,280,280,530),this,0);
- theApp.liftButton[71].EnableWindow(FALSE);
- for (int i = 0;i < 5;i ++)
- {
- liftThread[i].StartLiftThread();
- }
- return TRUE; // 除非将焦点设置到控件,否则返回 TRUE
- }
- void CLIFTTDlg::OnSysCommand(UINT nID, LPARAM lParam)
- {
- if ((nID & 0xFFF0) == IDM_ABOUTBOX)
- {
- CAboutDlg dlgAbout;
- dlgAbout.DoModal();
- }
- else
- {
- CDialog::OnSysCommand(nID, lParam);
- }
- }
- // 如果向对话框添加最小化按钮,则需要下面的代码
- // 来绘制该图标。对于使用文档/视图模型的 MFC 应用程序,
- // 这将由框架自动完成。
- void CLIFTTDlg::OnPaint()
- {
- if (IsIconic())
- {
- CPaintDC dc(this); // 用于绘制的设备上下文
- SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
- // 使图标在工作矩形中居中
- 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;
- // 绘制图标
- dc.DrawIcon(x, y, m_hIcon);
- }
- else
- {
- CDialog::OnPaint();
- }
- }
- //当用户拖动最小化窗口时系统调用此函数取得光标显示。
- //
- HCURSOR CLIFTTDlg::OnQueryDragIcon()
- {
- return static_cast<HCURSOR>(m_hIcon);
- }
- void CLIFTTDlg::OnCancel()
- {
- }
- void CLIFTTDlg::OnOK()
- {
- }
- void CLIFTTDlg::OnClose()
- {
- CDialog::OnCancel();
- }
- LRESULT CLIFTTDlg::OnGetButton(WPARAM liftInfo,LPARAM lParam)
- {
- lift * liftlx = (lift *)liftInfo;
- switch(liftlx->allNumber)
- {
- case LIFTWARN:
- liftThread[liftlx->buttonNumber-1].SetLiftTo(*liftlx);
- break;
- case LIFTOPEN:
- case LIFTCLOSE:
- liftThread[theApp.liftButton[70].GetLiftInfo().buttonNumber-1].SetLiftTo(*liftlx);
- break;
- case LIFTCTR:
- for (int i = 0;i < 20;i ++)
- {
- theApp.liftButton[i+40].SetAllNum(liftlx->buttonNumber);
- theApp.liftButton[i+40].EnableWindow(TRUE);
- }
- theApp.liftButton[70].SetButtonNum(liftlx->buttonNumber);
- theApp.liftButton[70].EnableWindow(TRUE);
- theApp.liftButton[71].SetButtonNum(liftlx->buttonNumber);
- theApp.liftButton[71].EnableWindow(TRUE);
- break;
- default:
- if (liftlx->allNumber != LIFTUP && liftlx->allNumber != LIFTDOWN)
- {
- if (liftThread[theApp.liftButton[70].GetLiftInfo().buttonNumber-1].GetLiftState() == LIFTUP)
- {
- if (liftlx->buttonNumber > liftThread[theApp.liftButton[70].GetLiftInfo().buttonNumber-1].GetLiftFloor())
- {
- liftlx->allNumber = LIFTUP;
- }
- else
- {
- liftlx->allNumber = LIFTDOWN;
- }
- }
- if (liftThread[theApp.liftButton[70].GetLiftInfo().buttonNumber-1].GetLiftState() == LIFTDOWN)
- {
- if (liftlx->buttonNumber < liftThread[theApp.liftButton[70].GetLiftInfo().buttonNumber-1].GetLiftFloor())
- {
- liftlx->allNumber = LIFTDOWN;
- }
- else
- {
- liftlx->allNumber = LIFTUP;
- }
- }
- if (liftThread[theApp.liftButton[70].GetLiftInfo().buttonNumber-1].GetLiftState() == LIFTCLOSE)
- {
- if (liftlx->buttonNumber > liftThread[theApp.liftButton[70].GetLiftInfo().buttonNumber-1].GetLiftFloor())
- {
- liftlx->allNumber = LIFTUP;
- }
- else
- {
- liftlx->allNumber = LIFTDOWN;
- }
- }
- liftThread[theApp.liftButton[70].GetLiftInfo().buttonNumber-1].SetLiftTo(*liftlx);
- }
- else
- {
- for (int i = 0;i < 5;i ++)
- {
- if (!liftThread[i].liftWarn)
- {
- if (liftThread[i].GetLiftState() == LIFTUP)
- {
- if (liftThread[i].GetLiftFloor() > liftlx->buttonNumber && liftlx->allNumber == LIFTUP && liftlx->buttonNumber < liftThread[i].liftTurn.liftMax && liftlx->buttonNumber > liftThread[i].liftTurn.liftMin)
- {
- liftThread[i].setTo = liftThread[i].liftTurn.liftMax * 2 - liftThread[i].liftTurn.liftMin * 2 + liftlx->buttonNumber - liftThread[i].GetLiftFloor() + (int)liftThread[i].liftTurn.upDown.size() * 3;
- }
- if ((liftThread[i].GetLiftFloor() < liftlx->buttonNumber && liftlx->allNumber == LIFTUP && liftlx->buttonNumber < liftThread[i].liftTurn.liftMax && liftlx->buttonNumber > liftThread[i].liftTurn.liftMin) || (liftlx->buttonNumber < liftThread[i].liftTurn.liftMin && liftlx->allNumber == LIFTUP && liftThread[i].GetLiftFloor() < liftlx->buttonNumber) || (liftlx->buttonNumber > liftThread[i].liftTurn.liftMax && liftThread[i].GetLiftFloor() < liftlx->buttonNumber))
- {
- liftThread[i].setTo = liftlx->buttonNumber - liftThread[i].GetLiftFloor() + (int)liftThread[i].liftTurn.upDown.size() * 3;
- }
- if ((liftlx->allNumber == LIFTDOWN && liftlx->buttonNumber < liftThread[i].liftTurn.liftMax && liftlx->buttonNumber > liftThread[i].liftTurn.liftMin) || (liftlx->buttonNumber < liftThread[i].liftTurn.liftMin && liftThread[i].GetLiftFloor() > liftlx->buttonNumber) || (liftlx->buttonNumber < liftThread[i].liftTurn.liftMin && liftlx->allNumber == LIFTDOWN && liftThread[i].GetLiftFloor() < liftlx->buttonNumber))
- {
- liftThread[i].setTo = liftThread[i].liftTurn.liftMax * 2 - liftlx->buttonNumber - liftThread[i].GetLiftFloor() + (int)liftThread[i].liftTurn.upDown.size() * 3;
- }
- }
- if (liftThread[i].GetLiftState() == LIFTDOWN)
- {
- if ((liftlx->allNumber == LIFTUP && liftlx->buttonNumber < liftThread[i].liftTurn.liftMax && liftlx->buttonNumber > liftThread[i].liftTurn.liftMin) || (liftlx->buttonNumber > liftThread[i].liftTurn.liftMax && liftThread[i].GetLiftFloor() < liftlx->buttonNumber) || (liftlx->buttonNumber > liftThread[i].liftTurn.liftMax && liftThread[i].GetLiftFloor() > liftlx->buttonNumber && liftlx->allNumber == LIFTUP))
- {
- liftThread[i].setTo = liftlx->buttonNumber + liftThread[i].GetLiftFloor() - liftThread[i].liftTurn.liftMin * 2 + (int)liftThread[i].liftTurn.upDown.size() * 3;
- }
- if ((liftThread[i].GetLiftFloor() > liftlx->buttonNumber && liftlx->allNumber == LIFTDOWN && liftlx->buttonNumber < liftThread[i].liftTurn.liftMax && liftlx->buttonNumber > liftThread[i].liftTurn.liftMin) || (liftlx->buttonNumber < liftThread[i].liftTurn.liftMin && liftThread[i].GetLiftFloor() > liftlx->buttonNumber) || (liftlx->buttonNumber > liftThread[i].liftTurn.liftMax && liftThread[i].GetLiftFloor() > liftlx->buttonNumber && liftlx->allNumber == LIFTDOWN))
- {
- liftThread[i].setTo = liftThread[i].GetLiftFloor() - liftlx->buttonNumber + (int)liftThread[i].liftTurn.upDown.size() * 3;
- }
- if (liftThread[i].GetLiftFloor() < liftlx->buttonNumber && liftlx->allNumber == LIFTDOWN && liftlx->buttonNumber < liftThread[i].liftTurn.liftMax && liftlx->buttonNumber > liftThread[i].liftTurn.liftMin)
- {
- liftThread[i].setTo = liftThread[i].liftTurn.liftMax * 2 - liftThread[i].liftTurn.liftMin * 2 - liftlx->buttonNumber + liftThread[i].GetLiftFloor() + (int)liftThread[i].liftTurn.upDown.size() * 3;
- }
- }
- if (liftThread[i].GetLiftState() == LIFTCLOSE)
- {
- if (liftThread[i].GetLiftFloor() > liftlx->buttonNumber)
- {
- liftThread[i].setTo = liftThread[i].GetLiftFloor() - liftlx->buttonNumber;
- }
- else
- {
- liftThread[i].setTo = liftlx->buttonNumber - liftThread[i].GetLiftFloor();
- }
- }
- }
- }
- int tempSetTo = 0;
- int tempToSet = liftThread[0].setTo;
- for (int i = 0;i < 5;i ++)
- {
- if (liftThread[i].liftWarn)
- {
- continue;
- }
- if (liftThread[i].setTo < tempToSet)
- {
- tempSetTo = i;
- tempToSet = liftThread[i].setTo;
- }
- }
- liftThread[tempSetTo].SetLiftTo(*liftlx);
- }
- break;
- }
- return 0;
- }