📄 pansrmtcdlg.cpp
字号:
m_state = DLGC_STARTED_ST;
m_dlgc_button.SetWindowText(DLGC_STOP_STR);
}
} // end of if (!UpdateData(...))
break;
default:
MessageBox("CPansrMTCDlg::OnDlgcButton default case.");
break;
}
}
LRESULT CPansrMTCDlg::OnDialogicStopped
(WPARAM wpar,
LPARAM lpar) // must have arguments in order to use ON_MESSAGE
{
switch (m_state)
{
case DLGC_STARTED_ST:
EnableConfiguration(TRUE);
RemoveChannelDialogs();
m_state = DLGC_STOPPED_ST;
m_dlgc_button.SetWindowText(DLGC_START_STR);
m_dlgc_button.EnableWindow(TRUE);
break;
case CLOSING_ST: // Dialogic stopped as a result of closing dialog
EndDialog(CLOSING_ST);
break;
default:
MessageBox("CPansrMTCDlg::OnDialogicStopped default case.");
break;
}
return 0L;
}
CPansrMTCDlg::~CPansrMTCDlg()
{
CloseHandle(ghDLGCEvent);
}
LRESULT CPansrMTCDlg::OnDialogicState
(WPARAM chanNum,
LPARAM state)
{
return m_chan_status_ptr[chanNum - 1]->SendMessage(WM_DLGC_STATE, chanNum, state);
}
LRESULT CPansrMTCDlg::OnDialogicCode
(WPARAM chanNum,
LPARAM code)
{
return m_chan_status_ptr[chanNum - 1]->SendMessage(WM_DLGC_CODE, chanNum, code);
}
void CPansrMTCDlg::EnableConfiguration
(BOOL enable)
{
m_button_analog.EnableWindow(enable);
m_button_e1.EnableWindow(enable);
m_button_t1.EnableWindow(enable);
m_edit_d4x.EnableWindow(enable);
m_edit_num_chan.EnableWindow(enable);
m_static_d4x.EnableWindow(enable);
m_static_frontend.EnableWindow(enable);
m_static_num_chan.EnableWindow(enable);
if (enable)
{
OnRadioAnalog();
}
else
{
m_button_peb.EnableWindow(FALSE);
m_edit_dti.EnableWindow(FALSE);
m_static_dti.EnableWindow(FALSE);
}
}
int CPansrMTCDlg::TryChannelRect
(RECT *chanRect,
RECT *dlgRect, // modified in function
BOOL resizeWidth /* = FALSE */) // should the width of dlgRect be changed if needed
{ // returns positive channelsPerRow if window completely viewable
// returns negative channelsPerRow if window needs further modification
int channelsPerRow;
int chanWidth;
int chanHeight;
CWnd *desktopWnd;
RECT desktopRect;
chanWidth = chanRect->right - chanRect->left;
chanHeight = chanRect->bottom - chanRect->top;
if (m_default_client_rect.right > chanWidth)
{ // the Client width is greater than channel width
// dlgRect->right is already good.
channelsPerRow = m_default_client_rect.right / chanWidth;
dlgRect->bottom += chanHeight * ((m_maxchans - 1) / channelsPerRow + 1);
}
else
{
dlgRect->bottom += chanHeight * m_maxchans;
dlgRect->right += chanWidth - m_default_client_rect.right;
channelsPerRow = 1;
}
// now we make sure we show our window as best as we can.
// I don't want to move what we have unless I have to.
// In other words, if the new window will be completely visible,
// don't move it at all.
desktopWnd = GetDesktopWindow();
desktopWnd->GetClientRect(&desktopRect);
if ((dlgRect->bottom > desktopRect.bottom)
|| (dlgRect->top < desktopRect.top)
|| (dlgRect->right > desktopRect.right)
|| (dlgRect->left < desktopRect.left))
{ // Center the window
dlgRect->bottom -= dlgRect->top;
dlgRect->top = 0;
dlgRect->right -= dlgRect->left;
dlgRect->left = 0;
if (resizeWidth) // expand width of dialog
{
while ((dlgRect->bottom > desktopRect.bottom) // too tall
&& (dlgRect->right < desktopRect.right)) // not too wide
{
channelsPerRow++;
dlgRect->right += chanWidth;
// adding the new correction to dlgRect->bottom and subtracting the old
// dlgRect->bottom += chanHeight * ((m_maxchans - 1) / channelsPerRow + 1)
// - chanHeight * ((m_maxchans - 1) / (channelsPerRow - 1) + 1);
// and now the simplified version:
dlgRect->bottom += chanHeight * ((m_maxchans - 1) / channelsPerRow
- (m_maxchans - 1) / (channelsPerRow - 1));
}
// we don't deal with shrinking width, because that means shrinking the
// width of our main dialog, which better already fit on the screen!
}
if ((dlgRect->bottom > desktopRect.bottom) // dimensions too large
|| (dlgRect->right > desktopRect.right))
{
channelsPerRow *= -1;
}
dlgRect->top = (desktopRect.bottom - dlgRect->bottom) / 2;
dlgRect->bottom += dlgRect->top;
dlgRect->left = (desktopRect.right - dlgRect->right) / 2;
dlgRect->right += dlgRect->left;
}
else // dlgRect is in OK position
{ // do nothing
}
return channelsPerRow;
}
void CPansrMTCDlg::AddChannelDialogs()
{
int i;
int chanWidth; // individual width and height of channel dialog
int chanHeight;
int x; // x and y determine the position of our new channel dialogs
int y;
int channelsPerRow;
RECT chanRect;
RECT myRect;
RECT clientRect;
// create the dialogs
// guaranteed to have one channel, just Create this so we can get size
m_chan_status_ptr[0] = new CChanStatDialog();
if (!m_chan_status_ptr[0]->Create(1, this)) // Creation unsuccessful
{
MessageBox("Unable to create channel dialog.", "Error", MB_ICONEXCLAMATION);
}
// figure the amount of space needed for these new dialogs
// and add that space to the bottom of our current dialog
m_chan_status_ptr[0]->GetWindowRect(&chanRect);
GetWindowRect(&myRect);
if ((channelsPerRow = TryChannelRect(&chanRect, &myRect)) < 0)
{ // need to use small dialogs
m_chan_status_ptr[0]->DestroyWindow(); // get rid of old
delete m_chan_status_ptr[0];
for (i = 0; i < m_maxchans; i++)
{
m_chan_status_ptr[i] = new CChanStatSmallDialog;
if (!m_chan_status_ptr[i]->Create(i + 1, this))
{
MessageBox("Unable to create small channel dialog.", "Error", MB_ICONEXCLAMATION);
}
}
m_chan_status_ptr[0]->GetWindowRect(&chanRect);
GetWindowRect(&myRect); // needs to be restored
if ((channelsPerRow = TryChannelRect(&chanRect, &myRect, TRUE)) < 0)
{
channelsPerRow *= -1;
MessageBox("Too much dialog to display", "Ignoring", MB_OK);
}
}
else // big dialogs are ok
{
for (i = 1; i < m_maxchans; i++)
{
m_chan_status_ptr[i] = new CChanStatDialog;
if (!m_chan_status_ptr[i]->Create(i + 1, this)) // Creation unsuccessful
{
MessageBox("Unable to create channel dialog.", "Error", MB_ICONEXCLAMATION);
}
}
}
MoveWindow(&myRect); // redraws the window
// using x and y, place our dialogs sequentially below the main dialog
GetClientRect(&clientRect);
chanWidth = chanRect.right - chanRect.left;
chanHeight = chanRect.bottom - chanRect.top;
// if we have less channels than channels per row, center it accordingly
x = (clientRect.right - (chanWidth *
// minimum(m_maxchans, channelsPerRow)
((m_maxchans < channelsPerRow) ? m_maxchans : channelsPerRow)
)) / 2;
y = m_default_client_rect.bottom;
i = 0;
while (i < m_maxchans)
{
if (!m_chan_status_ptr[i]->SetWindowPos(&wndBottom, x, y, 0, 0,
SWP_NOSIZE // do not resize
| SWP_SHOWWINDOW)) // show the window
{
MessageBox("SetWindowPos failed.", "Error", MB_ICONEXCLAMATION);
}
x += chanWidth;
if ((x + chanWidth) > clientRect.right) // can't fit another in
{ // I am a centering FOOL! if our row has less than the channels per row
// center it accordingly.
x = (clientRect.right - (chanWidth *
// minimum(m_maxchans - i - 1, channelsPerRow)
(((m_maxchans - i - 1) < channelsPerRow) ? (m_maxchans - i - 1) : channelsPerRow)
)) / 2;
y += chanHeight;
}
i++;
}
m_dlgc_button.SetActiveWindow(); // so our main dialog is still the active one
}
void CPansrMTCDlg::RemoveChannelDialogs()
{
int i;
RECT myRect;
RECT myClientRect;
// destroy the dialogs
for (i = 0; i < m_maxchans; i++)
{
m_chan_status_ptr[i]->DestroyWindow();
delete m_chan_status_ptr[i];
}
// reset our main dialog's looks
GetWindowRect(&myRect);
GetClientRect(&myClientRect);
// using the default client rect we established on initializiation,
// set our size to what it would have been without the channel
// dialogs
myRect.right += m_default_client_rect.right - myClientRect.right;
myRect.bottom += m_default_client_rect.bottom - myClientRect.bottom;
MoveWindow(&myRect); // resizes and redraws window
}
void CPansrMTCDlg::OnClose()
{
switch (m_state)
{
case DLGC_STARTED_ST:
m_dlgc_button.EnableWindow(FALSE);
m_dlgc_button.SetWindowText(DLGC_STOPPING_STR);
m_state = CLOSING_ST;
if (!SetEvent(ghDLGCEvent)) // unsuccessful
{
MessageBox("Set event failed in OnDlgcButton", "error",
MB_ICONEXCLAMATION);
}
break;
case DLGC_STOPPED_ST:
CDialog::OnClose();
break;
default:
MessageBox("CPansrMTCDlg::OnClose default case.");
CDialog::OnClose();
break;
}
}
void CPansrMTCDlg::OnOK
()
{
//Sleep(1000);
SendMessage(WM_CLOSE);
}
void CPansrMTCDlg::OnCancel()
{
}
void CPansrMTCDlg::OnRadioAnalog
()
{
UpdateData(TRUE);
m_static_dti.EnableWindow(!m_analog);
m_edit_dti.EnableWindow(!m_analog);
m_button_peb.EnableWindow(m_analog);
}
void CPansrMTCDlg::OnHelpIndex()
{
WinHelp(0L, HELP_INDEX);
}
void CPansrMTCDlg::OnSetting()
{
// TODO: Add your control notification handler code here
CSettingDialog Dig;
Dig.DoModal();
}
void CPansrMTCDlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
int chdev;
if((chdev = dx_open("dxxxB1C1", 0)) == -1)
goto HERE;
else
dx_close(chdev);
if(!m_bRunning2)
{
m_bRunning2 = TRUE;
m_state = DLGC_STOPPED_ST;
OnDlgcButton();
}
HERE:
CDialog::OnTimer(nIDEvent);
}
void CPansrMTCDlg::OnButtonCompile()
{
WinExec("LVCompiler.exe", SW_SHOW);
}
void CPansrMTCDlg::OnButtonSimuphone()
{
m_bRunning2 = TRUE;
::EnableWindow(::GetDlgItem(this->m_hWnd, IDC_DLGC_BUTTON), FALSE);
::EnableWindow(::GetDlgItem(this->m_hWnd, IDC_BUTTON_SIMUPHONE), FALSE);
int iChannelCount = GetPrivateProfileInt("CHANNEL", "MAXCHANS", 4, ".\\Setup.ini" );
RunVSInterpreter(iChannelCount);
RunSimuDialogic(iChannelCount);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -