📄 cledshowdemodlg.cpp
字号:
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// 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 CCLedShowDemoDlg::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();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CCLedShowDemoDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CCLedShowDemoDlg::OnHand()
{
this->m_Val1.EnableWindow(TRUE);
this->m_Val2.EnableWindow(TRUE);
this->m_Val3.EnableWindow(TRUE);
this->m_Val4.EnableWindow(TRUE);
this->m_Val5.EnableWindow(TRUE);
this->m_Val6.EnableWindow(TRUE);
this->m_Val7.EnableWindow(TRUE);
this->m_Val8.EnableWindow(TRUE);
this->m_Set.EnableWindow(TRUE);
SetEditValue();
}
void CCLedShowDemoDlg::OnOntime()
{
this->m_Val1.EnableWindow(FALSE);
this->m_Val2.EnableWindow(FALSE);
this->m_Val3.EnableWindow(FALSE);
this->m_Val4.EnableWindow(FALSE);
this->m_Val5.EnableWindow(FALSE);
this->m_Val6.EnableWindow(FALSE);
this->m_Val7.EnableWindow(FALSE);
this->m_Val8.EnableWindow(FALSE);
this->m_Set.EnableWindow(FALSE);
}
void CCLedShowDemoDlg::OnSendcommand()
{
CString strId,strVal;
this->m_Id.GetWindowText(strId);
this->m_SendVal.GetWindowText(strVal);
if((strId.IsEmpty())||(strVal.IsEmpty()))
MessageBox("输入信息不完整,请输入完整信息再进行发送操作!","提示",MB_OK|MB_ICONQUESTION);
else
{
if(atoi(strVal)>1)
{
MessageBox("输入信息错误,数值应为0或者1!","提示",MB_OK|MB_ICONQUESTION);
this->m_SendVal.SetWindowText("");
this->m_SendVal.SetFocus();
return;
}
}
}
BOOL CCLedShowDemoDlg::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
// 为阴影工具提示加入鼠标事件传递
m_tooltip.RelayEvent(pMsg);
return CDialog::PreTranslateMessage(pMsg);
}
HBRUSH CCLedShowDemoDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
if(nCtlColor==CTLCOLOR_LISTBOX)
{
pDC->SetBkMode(TRANSPARENT);
pDC->SetTextColor(RGB(0,0,0));
pDC->SetBkColor(RGB(233,233,220));
HBRUSH b=CreateSolidBrush(RGB(233,233,220));
return b;
}
else if(nCtlColor==CTLCOLOR_SCROLLBAR)
{
}
else if(nCtlColor==CTLCOLOR_EDIT)
{
}
else if(nCtlColor==CTLCOLOR_STATIC)
{
}
else if(nCtlColor==CTLCOLOR_DLG)
{
}
return hbr;
}
void CCLedShowDemoDlg::OnSetstate()
{
CString strVal1,strVal2,strVal3,strVal4,strVal5,strVal6,strVal7,strVal8;
this->m_Val1.GetWindowText(strVal1);
this->m_Val2.GetWindowText(strVal2);
this->m_Val3.GetWindowText(strVal3);
this->m_Val4.GetWindowText(strVal4);
this->m_Val5.GetWindowText(strVal5);
this->m_Val6.GetWindowText(strVal6);
this->m_Val7.GetWindowText(strVal7);
this->m_Val8.GetWindowText(strVal8);
iVal[1]=atoi(strVal1);
iVal[2]=atoi(strVal2);
iVal[3]=atoi(strVal3);
iVal[4]=atoi(strVal4);
iVal[5]=atoi(strVal5);
iVal[6]=atoi(strVal6);
iVal[7]=atoi(strVal7);
iVal[8]=atoi(strVal8);
UpdateLedState();
}
void CCLedShowDemoDlg::UpdateLedState()
{
if(iVal[1])
this->m_Led1.SwitchOn();
else
this->m_Led1.SwitchOff();
//////////////
if(iVal[2])
this->m_Led2.SwitchOn();
else
this->m_Led2.SwitchOff();
//////////////
if(iVal[3])
this->m_Led3.SwitchOn();
else
this->m_Led3.SwitchOff();
//////////////
if(iVal[4])
this->m_Led4.SwitchOn();
else
this->m_Led4.SwitchOff();
//////////////
if(iVal[5])
this->m_Led5.SwitchOn();
else
this->m_Led5.SwitchOff();
//////////////
if(iVal[6])
this->m_Led6.SwitchOn();
else
this->m_Led6.SwitchOff();
//////////////
if(iVal[7])
this->m_Led7.SwitchOn();
else
this->m_Led7.SwitchOff();
//////////////
if(iVal[8])
this->m_Led8.SwitchOn();
else
this->m_Led8.SwitchOff();
//////////////
this->m_Led1.UpdateWindow();
this->m_Led2.UpdateWindow();
this->m_Led3.UpdateWindow();
this->m_Led4.UpdateWindow();
this->m_Led5.UpdateWindow();
this->m_Led6.UpdateWindow();
this->m_Led7.UpdateWindow();
this->m_Led8.UpdateWindow();
}
void CCLedShowDemoDlg::SetEditValue()
{
CString strVal1,strVal2,strVal3,strVal4,strVal5,strVal6,strVal7,strVal8;
strVal1.Format("%d",iVal[1]);
strVal2.Format("%d",iVal[2]);
strVal3.Format("%d",iVal[3]);
strVal4.Format("%d",iVal[4]);
strVal5.Format("%d",iVal[5]);
strVal6.Format("%d",iVal[6]);
strVal7.Format("%d",iVal[7]);
strVal8.Format("%d",iVal[8]);
this->m_Val1.SetWindowText(strVal1);
this->m_Val2.SetWindowText(strVal2);
this->m_Val3.SetWindowText(strVal3);
this->m_Val4.SetWindowText(strVal4);
this->m_Val5.SetWindowText(strVal5);
this->m_Val6.SetWindowText(strVal6);
this->m_Val7.SetWindowText(strVal7);
this->m_Val8.SetWindowText(strVal8);
}
void CCLedShowDemoDlg::OnOK()
{
if(MessageBox("监控系统程序正在运行,确定要退出监控界面吗?","提示",MB_OKCANCEL|MB_ICONQUESTION)==IDOK)
CDialog::OnOK();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -