⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mod_rssimdlg.cpp

📁 用于开发Modbus工业级通信
💻 CPP
📖 第 1 页 / 共 5 页
字号:
   //comms debug view
   {IDC_COMMSLIST,       {CResizer::eFixed, IDC_MAIN, CResizer::eLeft},   // left side
                         {CResizer::eFixed, IDC_MAIN, CResizer::eTop},    // top
                         {CResizer::eFixed, IDC_MAIN, CResizer::eRight},  // right side
                         {CResizer::eFixed, IDC_MAIN, CResizer::eBottom}},// bottom

   {IDC_TRAININGSIM,     {CResizer::eFixed, IDC_MAIN, CResizer::eRight},   // left side
                         {CResizer::eFixed, IDC_MAIN, CResizer::eBottom},    // top
                         {CResizer::eWidth, IDC_MAIN, CResizer::eRight},  // right side
                         {CResizer::eHeight,IDC_MAIN, CResizer::eBottom}},// bottom
   {IDB_TOGGLEDISP,      {CResizer::eFixed, IDC_MAIN, CResizer::eRight},   // left side
                         {CResizer::eFixed, IDC_MAIN, CResizer::eBottom},    // top
                         {CResizer::eWidth, IDC_MAIN, CResizer::eRight},  // right side
                         {CResizer::eHeight,IDC_MAIN, CResizer::eBottom}},// bottom
   {IDC_PAUSECOMMS,      {CResizer::eFixed, IDC_MAIN, CResizer::eLeft},   // left side
                         {CResizer::eFixed, IDC_MAIN, CResizer::eTop},    // top
                         {CResizer::eWidth, IDC_MAIN, CResizer::eRight},  // right side
                         {CResizer::eHeight,IDC_MAIN, CResizer::eBottom}},// bottom
   {IDC_TRACKCOMMS,      {CResizer::eFixed, IDC_MAIN, CResizer::eLeft},   // left side
                         {CResizer::eFixed, IDC_MAIN, CResizer::eTop},    // top
                         {CResizer::eWidth, IDC_MAIN, CResizer::eRight},  // right side
                         {CResizer::eHeight,IDC_MAIN, CResizer::eBottom}},// bottom
   {IDC_CLEARCOMMS,      {CResizer::eFixed, IDC_MAIN, CResizer::eLeft},   // left side
                         {CResizer::eFixed, IDC_MAIN, CResizer::eTop},    // top
                         {CResizer::eWidth, IDC_MAIN, CResizer::eRight},  // right side
                         {CResizer::eHeight,IDC_MAIN, CResizer::eBottom}},// bottom
   {IDC_SHOWCOMMSTIME,      {CResizer::eFixed, IDC_MAIN, CResizer::eLeft},   // left side
                         {CResizer::eFixed, IDC_MAIN, CResizer::eTop},    // top
                         {CResizer::eWidth, IDC_MAIN, CResizer::eRight},  // right side
                         {CResizer::eHeight,IDC_MAIN, CResizer::eBottom}},// bottom

   {IDC_DRAG,            {CResizer::eFixed, IDC_MAIN, CResizer::eRight},   // left side
                         {CResizer::eFixed, IDC_MAIN, CResizer::eBottom},    // top
                         {CResizer::eWidth, IDC_MAIN, CResizer::eRight},  // right side
                         {CResizer::eHeight, IDC_MAIN, CResizer::eBottom}} // bottom
};


// --------------------------------------- OnInitDialog ------------------------
BOOL CMOD_simDlg::OnInitDialog()
{
CString tickText;
BOOL ret;

	CDialog::OnInitDialog();

   CSplashWnd::EnableSplashScreen(TRUE);
   CSplashWnd::m_splashShowDelay = 1;
   CSplashWnd::ShowSplashScreen(this); 	
      
   m_dragCorner.SubclassDlgItem(IDC_DRAG, this);
   m_dragCorner.SetCornerType(CDragSizerBmp::CORNER_BOTTOMRIGHT, IDB_DRAGSE, TRUE);

   CMenu* pSysMenu = GetSystemMenu(FALSE);
   SetupMySystemMenu(pSysMenu);
	
   const nSize = sizeof(s_bi)/sizeof(s_bi[0]);
   //Second we initialize resizer with this array. 
   //At the same time it will store the original controls positions.
   m_resizer.Init(m_hWnd, NULL, s_bi, nSize);

   m_hAccel = ::LoadAccelerators(AfxGetResourceHandle(), 
                                 m_lpszTemplateName); 
   ASSERT(m_hAccel);
	// TODO: Add extra initialization here
   // load user settings from registry
   LoadApplicationSettings();

   // set mem sizes
   PLCMemory.SetSize(GetNumMemoryAreas());
   SetMemAreaSizes();
   m_listCtrlData.SubclassDlgItem(IDC_DATALIST, this);
   // set display to Hex
   SetAddressFormatHex(m_appSettingAdressHex);
   CheckRadioButton(IDC_VIEWHEX, IDC_VIEWDEC, (IsAddressFormatHex() ? IDC_VIEWHEX : IDC_VIEWDEC));


   // set protcol selection in the list-box
   m_protocolCombo.SetCurSel(m_selectedProtocol);

   //IDC_DATAFORMAT
   FillCharCBox(&m_dataFormatCombo, PLCDataFormatsTable, &ViewerFormatNames[1], sizeof(PLCDataFormatsTable)/sizeof(PLCDataFormatsTable[0]), m_listCtrlData.GetViewFormat());

   m_vScrollBarStations.SetScrollRange(0, MAX_SCROLLINDEX, FALSE);
   // set up the tick-boxes
   for (int stationIndex=0;stationIndex<STATIONTICKBOXESMAX;stationIndex++) 
   {
      //tickText.Format("%02d", stationIndex);
      if (stationIndex < STATIONTICKBOXES)
      {
         ret = m_microTicks[stationIndex].SubclassDlgItem(IDC_STATION00+stationIndex, this);
         //colors
         m_microTicks[stationIndex].SetCheckedColor(m_mTickColorEnabled);
         m_microTicks[stationIndex].SetUnCheckedColor(m_mTickColorDisabled);
         m_microTicks[stationIndex].SetActiveColor(m_mTickColorActive);
         m_microTicks[stationIndex].SetInactiveColor(m_mTickColorInactive);

         m_microTicks[stationIndex].SetTextColor(m_mTickColorText);
         m_microTicks[stationIndex].SetUnCheckedTextColor(m_mTickDisColorText);
         m_microTicks[stationIndex].SetBorderWidth(2);

      }
      
      m_microTicksCountDown[stationIndex] = 0;        // tick-box coloring
      m_microTicksBackState[stationIndex] = FALSE;    // inactive/recently active
      m_microTicksEnableState[stationIndex] = (m_startAsOff ? FALSE : TRUE);
   }

   // RX/TX diodes
   m_lampRX.SubclassDlgItem(IDC_LAMPRX ,this);
   m_lampTX.SubclassDlgItem(IDC_LAMPTX ,this);
   m_lampTraining.SubclassDlgItem(IDC_PLANTSIM, this);

   m_lampRX.SetupLamp(500);
   m_lampTX.SetupLamp(500);

   m_lampTraining.SetONcolor(RGB(0,200,0)); // set the ON color for this lamp to be GREEN
   m_lampTraining.SetOFFcolor(RGB(0,110,0));

   // start the comms side
   InitiateCommsProcessors(m_selectedProtocol);
   OnSelchangeProtocol();  // update icon

   //m_listCtrlData.SetAreaDisplayed(m_startUpRegisterArea);
   OnSelchangeComboArea();
   //SetupListViewControl(10);//NUMBER_LISTCOLS);

   //TOOLTIPS START
   m_ToolTip.Create (this);
   m_ToolTip.Activate (TRUE);

   CWnd*    pWnd = GetWindow (GW_CHILD);
   while (pWnd)
   {
       int nID = pWnd->GetDlgCtrlID ();
       if (nID != -1)
       {
           m_ToolTip.AddTool (pWnd, pWnd->GetDlgCtrlID ());
       }
       pWnd = pWnd->GetWindow (GW_HWNDNEXT);
   }
   //TOOLTIPS END

   ConfigureStationButtons();

   SetupMyToolBar();

   // Animation and updates timer
   SetTimer(0,500,NULL);

   // load registers if we have to now.
   if (m_autoLoad)
      PostMessage(wm_LoadRegisters); //calls OnLoad();

   SetDisplayToggleButton();
//   SetDlgItemText(IDB_TOGGLEDISP, (m_registerShow ?"Comms":"Registers"));
   SetDlgItemText(IDC_TRACKCOMMS, (m_commsTobottom? "Stop tracking" : "Track comms"));
   SetDlgItemText(IDC_PAUSECOMMS, (m_paused? "Resume" : "Pause"));


   CRect rect;
   DWORD x=0,y=0;

   {
   CString registryPath;
   DRegKey key;

      m_appSettingAdressHex = m_listCtrlData.IsAddressFormatHex();
      // Save the baud rate etc
      registryPath = APPREGISTRY_SETTINGSKEY;
      key.Open(DRegKey::local_machine, registryPath);
      key.QueryValue("WindowPositionX", &x);//(rect.left+ rect.right<<16)); 
      key.QueryValue("WindowPositionY", &y);//(rect.top+ rect.bottom<<16)); 
      rect.left = x & 0xFFFF;
      rect.right = x >> 16;
      rect.top = y & 0xFFFF;
      rect.bottom = y >> 16;
   }
   if (x && y)
   {
   int cx,cy;
      CWnd *pTop = FindWindow(SIMULATOR_WINDOW_CLASSNAME, NULL);
      cx = GetSystemMetrics(SM_CXFULLSCREEN);
      cy = GetSystemMetrics(SM_CYFULLSCREEN);
      // figure out how to cascade later once we have some time.

      //while ((pTop)&&(pTop->m_hWnd == m_hWnd))
      //   pTop = pTop->GetWindow(GW_HWNDNEXT);

      //if (pTop)
      //{
      //   // other copy, move our asses
      //   pTop->GetWindowRect(&rect);
      //   rect.left += 12;
      //   rect.right+=12;
      //   rect.top+=12;
      //   rect.bottom +=12;
      //}
      if ((rect.left >=0) && (rect.right <= cx) && (rect.top >=0) && (rect.bottom <= cy))
         SetWindowPos(&CWnd::wndTop, rect.left, rect.top, rect.right-rect.left, rect.bottom-rect.top, SWP_SHOWWINDOW);

   }
   // tell the splash screen to close by sending a click
   //PostMessage(WM_NCLBUTTONDOWN,0,0);  

	return TRUE;  // return TRUE  unless you set the focus to a control
} // OnInitDialog


// ----------------------------------- SetMemAreaSizes -------------------------
// set up how many bits/registers each modbus type has got
void CMOD_simDlg::SetMemAreaSizes()
{
   switch (m_selectedProtocol)
   {
      case PROTOCOL_SELMOD232:
      case PROTOCOL_SELMODETH:
         PLCMemory[0].SetSize(this->m_numOutputs);
         PLCMemory[1].SetSize(this->m_numInputs);
         PLCMemory[2].SetSize(this->m_numAnalogs);
         PLCMemory[3].SetSize(this->m_numHolding);
         PLCMemory[4].SetSize(this->m_numExtended);
         FillComboBox(IDC_COMBOAREA, PLCMemoryTypes, m_startUpRegisterArea);//m_listCtrlData.GetAreaDisplayed());
         {
            int count = ((CComboBox*)GetDlgItem(IDC_COMBOAREA))->GetCurSel();
            if (-1 == count)
               ((CComboBox*)GetDlgItem(IDC_COMBOAREA))->SetCurSel(0);
         }
         break;
      case PROTOCOL_SELJOY232:
      case PROTOCOL_SELAB232:
         {
            int i, max = GetNumMemoryAreas();
            for (i=0; i < max; i++)
               PLCMemory[i].SetSize(255);

            // init the memory
            if (PROTOCOL_SELJOY232 == m_selectedProtocol)
            {
               for (i=0; i < max; i++)
               {
                  PLCMemory.SetAt(i, 1, JOY_MINROOFPRESSURE);
                  PLCMemory.SetAt(i,2, JOY_MINROOFPRESSURE);
                  PLCMemory.SetAt(i,6, JOY_12VOLTS);
               }
            }
            // fill a combo box with AB file #/names
         LONG count;
         CComboBox *pCombo = ((CComboBox*)GetDlgItem(IDC_COMBOAREA));
         CString entry;
         BOOL noSel = TRUE;

            pCombo->ResetContent();
            for (count = 0; count < max; count++)
            {
               entry.Format("File %d", count);
               pCombo->AddString(entry);
               pCombo->SetItemData(count,  count);
               if (count == m_listCtrlData.GetAreaDisplayed())
                  pCombo->SetCurSel(count);
            }
            count = pCombo->GetCurSel();
            if (-1 == count)
               pCombo->SetCurSel(0);
         }
         break;
   }
   //populate the LB as well
}


// ---------------------------------- SetupListViewControl ---------------------
// PURPOSE; Set up the list-view control headdings and col. widths
// NOTES;
// Data on the control comes in via a callback func
void CMOD_simDlg::SetupListViewControl(const DWORD cols)
{

   m_isClone = IsDlgButtonChecked(IDC_CLONE);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -