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

📄 mod_rssimdlg.cpp

📁 mod_RSsim
💻 CPP
📖 第 1 页 / 共 5 页
字号:
	ON_CBN_SELCHANGE(IDC_PROTOCOL, OnSelchangeProtocol)
	ON_BN_CLICKED(IDC_TRAININGSIM, OnTraining)
	ON_BN_CLICKED(IDC_CLEARCOMMS, OnClearcomms)
	ON_BN_CLICKED(IDC_SHOWCOMMSTIME, OnShowcommstimeClicked)
	ON_COMMAND(IDH_INJECTERROR, OnInJecterror)
	ON_COMMAND(IDC_OPEN, OnOpenPort)
	ON_COMMAND(IDC_CLOSE, OnClosePort)
	ON_COMMAND(IDH_EMULATION, OnEmulation)
	ON_COMMAND(IDH_SETTINGS, OnSettings)
	ON_COMMAND(IDH_LOAD, OnLoad)
	ON_COMMAND(IDH_SAVE, OnSave)
	ON_COMMAND(IDH_NOISE, OnNoise)
	ON_COMMAND(IDH_ERASE, OnZeroes)
	ON_COMMAND(IDH_HELP, OnAbout)
	ON_BN_CLICKED(IDB_TOGGLEDISP, OnToggleDisplay)
	ON_COMMAND(IDM_TOGGLEPORT, OnTogglePortState)
	//}}AFX_MSG_MAP
   ON_WM_GETMINMAXINFO()
   ON_REGISTERED_MESSAGE( wm_LoadRegisters, OnLoad )
END_MESSAGE_MAP()

CMOD_simDlg *pGlobalDialog;

/////////////////////////////////////////////////////////////////////////////
// CMOD_simDlg message handlers


// ----------------------------- MyProcessingLoop----------------------------
// This is a little secondary message processing loop used when creating RS servers
// This routine allows the GUI to repaint itself and update as well as perform 
// some connections/comms on any servers threads that are already running. In the 
// Ethernet simulator version, this method would handle all the extra listen socket 
// creation etc..
//
// A HourGlass cursor during this time is used to precent anyone clicking buttons and 
// getting us into any killer loops.
BOOL CMOD_simDlg::MyProcessingLoop(const int loops)
{
LONG loopCount=loops;
MSG msg;
   
   // Secondary message loop
   
   while ((PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))&&(loopCount>=0))
   {
      loopCount--;
      if (msg.message == WM_QUIT)
      {
         // Repost the QUIT message so that it will be retrieved by the
         // primary GetMessage() loop.
         PostQuitMessage(msg.wParam);
         return FALSE;
      }
      // Pre-process message if required (TranslateAccelerator etc.)
      TranslateMessage(&msg);
      DispatchMessage(&msg);
   }
   return(TRUE);
} // MyProcessingLoop

// -------------------------- PacketsReceivedInc -------------------------
void CMOD_simDlg::PacketsReceivedInc()
{
   //
   m_PacketsReceived++;
} // PacketsReceivedInc

// ---------------------------- PacketsSentInc ----------------------------
void CMOD_simDlg::PacketsSentInc()
{
   //
   m_PacketsSent++;
} // PacketsSentInc

// ------------------------------- GetWordValue -------------------------------
// return (typically 16) bits as an integer value
DWORD CMOD_simDlg::GetWordValue(const LONG area, 
                                const DWORD startBit, 
                                DWORD numBits)
{
DWORD registerValue = 0;
DWORD maximumOffset = GetPLCMemoryLimit(area);

   if (maximumOffset < startBit + numBits)
      numBits = maximumOffset - startBit;
   if (IsDlgButtonChecked(IDC_CLONE))
   {
      for (DWORD i=0 ; i<numBits ; i++)  //gather bits in backwards
         registerValue += PLCMemory[area][startBit+i]<<i;
   }
   else
   {
      for (DWORD i=0 ; i<numBits ; i++)
         registerValue += PLCMemory[area][startBit+(numBits-i-1)]<<i;
   }
   return (registerValue);
} // GetWordValue

// ------------------------------- SetWordValue -------------------------------
// re-pack (typically 16) bits into their individual bits
void CMOD_simDlg::SetWordValue(const LONG area, const DWORD startBit, const DWORD dwValue, const DWORD numBits)
{
// lock the memory for writting
CMemWriteLock lk(PLCMemory.GetMutex());

   if (lk.IsLocked())
      return;
   if (IsDlgButtonChecked(IDC_CLONE))
   {
      for (DWORD i=0 ; i<numBits ; i++)  //gather bits in backwards
         //registerValue += PLCMemory[pGlobalDialog->m_memAreaDisplayed][startBit+i]<<i;
         PLCMemory.SetAt(area, startBit+i, ((dwValue & (0x0001<<i))?1:0));
   }
   else
   {
      for (DWORD i=0 ; i<numBits ; i++)
         //registerValue += PLCMemory[pGlobalDialog->m_memAreaDisplayed][startBit+(numBits-i-1)]<<i;
         PLCMemory.SetAt(area, startBit+(numBits-i-1), ((dwValue & (0x0001<<i))?1:0));
   }
} // SetWordValue

// ------------------------------ FillComboBox ----------------------
// load an array of strings into a combo-box, then select one of them.
void CMOD_simDlg::FillComboBox(UINT id,char ** strTable, const DWORD currentsetting)
{
DWORD count;
CComboBox *pCombo = ((CComboBox*)GetDlgItem(id));

   pCombo->ResetContent();
   for (count = 0; strlen(strTable[count]); count++)
   {
#ifdef _UI_DEBUGGING
      OutputDebugString(strTable[count]);
      OutputDebugString(" added\n");
#endif
      
      pCombo->AddString(strTable[count]);
      pCombo->SetItemData(count,  count);
      if (count == currentsetting)
         pCombo->SetCurSel(count);
   }
} // FillComboBox

// -------------------------------------- SetAddressFormatHex -----------------
// call the contained control
void CMOD_simDlg::SetAddressFormatHex(BOOL formatHEX /*= TRUE*/) 
{
   m_listCtrlData.SetAddressFormatHex(formatHEX);
}

// -------------------------------------- IsAddressFormatHex -------------------
// call the contained control
BOOL CMOD_simDlg::IsAddressFormatHex() 
{
   return (m_listCtrlData.IsAddressFormatHex());
}

// -------------------------------- SetupMySystemMenu --------------------------
// Just populate the little pop-up system menu, along with some other misc. stuff
//
void CMOD_simDlg::SetupMySystemMenu(CMenu *pSysMenu)
{
	// 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);

	if (pSysMenu != NULL)
	{
   CString strAboutMenu, strOnTop, strEmulation;
   CString strToggle;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
      strOnTop.LoadString(IDS_MNU_ONTOP);
      strEmulation.LoadString(IDS_EMULATION);

		if (!strAboutMenu.IsEmpty())
		{
         // about menu
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
         //always on top
		   pSysMenu->AppendMenu(MF_STRING, IDM_ONTOP, strOnTop);
         pSysMenu->CheckMenuItem(IDM_ONTOP, MF_UNCHECKED);

         // emu. settings
		   pSysMenu->AppendMenu(MF_STRING, IDM_EMULATE, strEmulation);
         pSysMenu->CheckMenuItem(IDM_EMULATE, MF_UNCHECKED);
      
         m_portToggleMnuIndex = 6;  // index of the port open/close item
         // The window transparency code for XP and 2000 users comes in here....
         GetTNImport();
         if (NULL != m_pSetLayeredWindowAttributes)
         {
         CString alphaMenu;
		      alphaMenu.LoadString(IDS_ALPHA);
		      if (!alphaMenu.IsEmpty())
		      {
   			   pSysMenu->AppendMenu(MF_SEPARATOR);
			      pSysMenu->AppendMenu(MF_STRING, IDM_ALPHA, alphaMenu);
		      }
            // up-down blend setting not working at this time
		      alphaMenu.LoadString(IDS_ALPHA_60);
		      if (!alphaMenu.IsEmpty())
		      {
			      pSysMenu->AppendMenu(MF_STRING, IDM_ALPHA_60, alphaMenu);
		      }
		      alphaMenu.LoadString(IDS_ALPHA_70);
		      if (!alphaMenu.IsEmpty())
		      {
			      pSysMenu->AppendMenu(MF_STRING, IDM_ALPHA_70, alphaMenu);
		      }      
            m_portToggleMnuIndex+=3; // index of the port open/close item
         }
         alphaBlendON = FALSE;
         alphaBlendFactor = 70;
         // port open/close menu item
         strToggle.LoadString(IDS_PORTTOGGLE);
         pSysMenu->AppendMenu(MF_STRING, IDM_TOGGLEPORT, strToggle);

		}
	}

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIconMB, TRUE);			// Set big icon
	SetIcon(m_hIconMB, FALSE);		   // Set small icon

} // SetupMySystemMenu


// ------------------------------ SetupMyToolBar ------------------------------
// populate the little toolbar with the controls and bitmaps
void CMOD_simDlg::SetupMyToolBar()
{
BOOL  ret;

   // TOOLBAR 
   // Tooltips for the buttons are handled by a MSG handler
   CWindowRect toolRect(GetDlgItem(IDB_TOOLBARID));
   ScreenToClient(toolRect);
   CRect borders(0,0,0,0);
   ret = m_ToolBar.CreateEx(this, /*TBSTYLE_FLAT*/TBSTYLE_BUTTON|TBSTYLE_TOOLTIPS, WS_CHILD|WS_VISIBLE|CBRS_ALIGN_TOP|CBRS_TOOLTIPS, borders, IDB_TOOLBARID);
   
   m_ToolBar.LoadBitmap(IDR_TOOLBAR1);
   m_ToolBar.SetButtons(NULL, 11);
                       // BN position, control ID, bitmap index
   m_ToolBar.SetButtonInfo(0, IDC_SAVE,      TBBS_BUTTON, 0);
   m_ToolBar.SetButtonInfo(1, IDC_LOAD,      TBBS_BUTTON, 1);
   m_ToolBar.SetButtonInfo(2, IDC_ZEROES,    TBBS_BUTTON, 2);
   m_ToolBar.SetButtonInfo(3, IDC_SETTINGS,  TBBS_BUTTON, 3);
   m_ToolBar.SetButtonInfo(4, IDC_SIMULATE,  TBBS_BUTTON, 4);
   m_ToolBar.SetButtonInfo(5, IDC_NOISE,  TBBS_BUTTON, 10);       //bitmaps 10,11

   m_ToolBar.SetButtonInfo(6, ID_SEPARATOR,  TBBS_SEPARATOR , 5);  // seperator
   m_ToolBar.SetButtonInfo(7, IDS_ABOUTBOX,  TBBS_BUTTON, 5);


   if (NULL != m_pSetLayeredWindowAttributes)
      // HF fixed index of bitmaps  m_ToolBar.SetButtonInfo(8, IDB_ALPHABLEND,  TBBS_BUTTON, 8);   //bitmaps 7,8 & 9
      m_ToolBar.SetButtonInfo(8, IDB_ALPHABLEND,  TBBS_BUTTON, 7);   //bitmaps 7,8 & 9
   else // pleb O/S's just get a seperator not a button
      m_ToolBar.SetButtonInfo(8, ID_SEPARATOR,  TBBS_SEPARATOR , 5);    // seperator
   m_ToolBar.SetButtonInfo(9, IDC_EMULATION,      TBBS_BUTTON, 12);
   //m_ToolBar.SetButtonInfo(10, ID_SEPARATOR,  TBBS_SEPARATOR , 5);      // seperator
   m_ToolBar.SetButtonInfo(10, IDC_CLOSE,      TBBS_BUTTON, 13);
   
   //ret = m_ToolBar.LoadToolBar(IDR_TOOLBAR1);

⌨️ 快捷键说明

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