📄 settings.cpp
字号:
BEGIN_MESSAGE_MAP(CTrapSettingsDlg, CDialog)
//{{AFX_MSG_MAP(CTrapSettingsDlg)
ON_BN_CLICKED(IDC_LIMITMSGLNGTH, OnLimitMessageLength)
ON_BN_CLICKED(IDC_RADIO_DISABLE, OnRadioDisable)
ON_BN_CLICKED(IDC_RADIO_ENABLE, OnRadioEable)
ON_BN_CLICKED(IDC_BUTTON_RESET, OnButtonReset)
ON_COMMAND(ID_HELP, OnHelp)
ON_WM_HELPINFO()
ON_WM_CONTEXTMENU()
ON_WM_CLOSE()
ON_MESSAGE(WM_UIREQUEST, OnUIRequest)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CTrapSettingsDlg message handlers
LRESULT CTrapSettingsDlg::OnUIRequest(WPARAM cmd, LPARAM lParam)
{
switch(cmd)
{
case UICMD_ENABLE_RESET:
m_btnResetThrottle.EnableWindow((BOOL)lParam);
break;
default:
break;
}
return (LRESULT)0;
}
void CTrapSettingsDlg::OnLimitMessageLength()
{
// The LimitMsgLength checkbox was clicked.
// Enable/disable the edit control.
// Get the controls.
CButton* pbtnLimitBox = (CButton*) GetDlgItem(IDC_LIMITMSGLNGTH);
CButton *pRadio1 = (CButton*)GetDlgItem(IDC_RADIO1);
CButton *pRadio2 = (CButton*)GetDlgItem(IDC_RADIO2);
// It's checked; enable
if (pbtnLimitBox->GetCheck() == 1)
{
m_edtMessageLength.EnableWindow();
pRadio1->EnableWindow();
pRadio2->EnableWindow();
GetDlgItem(IDC_STATIC_BYTES)->EnableWindow();
m_statTrapLength.EnableWindow();
}
// Disable
else
{
m_edtMessageLength.EnableWindow(FALSE);
pRadio1->EnableWindow(FALSE);
pRadio2->EnableWindow(FALSE);
GetDlgItem(IDC_STATIC_BYTES)->EnableWindow(FALSE);
m_statTrapLength.EnableWindow(FALSE);
}
}
BOOL CTrapSettingsDlg::OnInitDialog()
{
CDialog::OnInitDialog();
CButton *pRadio1 = (CButton*)GetDlgItem(IDC_RADIO1);
CButton *pRadio2 = (CButton*)GetDlgItem(IDC_RADIO2);
m_statTrapLength.EnableWindow(m_bLimitMsgLength);
m_edtMessageLength.EnableWindow(m_bLimitMsgLength);
if (m_bLimitMsgLength)
{
pRadio1->EnableWindow();
pRadio2->EnableWindow();
GetDlgItem(IDC_STATIC_BYTES)->EnableWindow();
}
// Disable
else
{
pRadio1->EnableWindow(FALSE);
pRadio2->EnableWindow(FALSE);
GetDlgItem(IDC_STATIC_BYTES)->EnableWindow(FALSE);
}
if (m_bTrimMessagesFirst)
CheckRadioButton(IDC_RADIO1, IDC_RADIO2, IDC_RADIO2);
else
CheckRadioButton(IDC_RADIO1, IDC_RADIO2, IDC_RADIO1);
if (m_bThrottleEnabled)
CheckRadioButton(IDC_RADIO_ENABLE, IDC_RADIO_DISABLE, IDC_RADIO_ENABLE);
else
CheckRadioButton(IDC_RADIO_ENABLE, IDC_RADIO_DISABLE, IDC_RADIO_DISABLE);
EnableThrottleWindows(m_bThrottleEnabled);
m_pthRegNotification = AfxBeginThread((AFX_THREADPROC)_thrRun, this);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CTrapSettingsDlg::OnOK()
{
LONG nchMessageLength;
LONG nTraps;
LONG nSeconds;
SCODE sc = GetMessageLength(&nchMessageLength);
if (FAILED(sc))
{
return;
}
sc = GetTrapsPerSecond(&nTraps, &nSeconds);
if (FAILED(sc))
{
return;
}
// Pull various values off of the dialog and store them into member variables.
// Note that there are other member variables that are set directly
// as a response to user input.
//===========================================================================
m_bTrimMessagesFirst = (GetCheckedRadioButton(IDC_RADIO1, IDC_RADIO2) == IDC_RADIO2);
m_bThrottleEnabled = (GetCheckedRadioButton(IDC_RADIO_ENABLE, IDC_RADIO_DISABLE) == IDC_RADIO_ENABLE);
if (g_reg.m_params.m_trapsize.m_dwMaxTrapSize != (DWORD) nchMessageLength) {
g_reg.SetDirty(TRUE);
g_reg.m_params.m_trapsize.m_dwMaxTrapSize = nchMessageLength;
}
if(g_reg.m_params.m_throttle.m_nSeconds != nSeconds) {
g_reg.SetDirty(TRUE);
g_reg.m_params.m_throttle.m_nSeconds = nSeconds;
}
if (g_reg.m_params.m_throttle.m_nTraps != nTraps) {
g_reg.SetDirty(TRUE);
g_reg.m_params.m_throttle.m_nTraps = nTraps;
}
TerminateBackgroundThread();
CDialog::OnOK();
}
BOOL CTrapSettingsDlg::EditSettings()
{
m_bLimitMsgLength = g_reg.m_params.m_trapsize.m_bTrimFlag;
m_bTrimMessagesFirst = g_reg.m_params.m_trapsize.m_bTrimMessages;
m_bThrottleEnabled = g_reg.m_params.m_throttle.m_bIsEnabled;
// Save the data.
if (DoModal() == IDOK)
{
if (BOOLS_ARE_DIFFERENT(g_reg.m_params.m_trapsize.m_bTrimFlag, m_bLimitMsgLength)) {
g_reg.m_params.m_trapsize.m_bTrimFlag = m_bLimitMsgLength;
g_reg.SetDirty(TRUE);
}
if (BOOLS_ARE_DIFFERENT(g_reg.m_params.m_trapsize.m_bTrimMessages, m_bTrimMessagesFirst)) {
g_reg.m_params.m_trapsize.m_bTrimMessages = m_bTrimMessagesFirst;
g_reg.SetDirty(TRUE);
}
if (BOOLS_ARE_DIFFERENT(g_reg.m_params.m_throttle.m_bIsEnabled, m_bThrottleEnabled)) {
g_reg.m_params.m_throttle.m_bIsEnabled = m_bThrottleEnabled;
g_reg.SetDirty(TRUE);
}
return TRUE;
}
else {
return FALSE;
}
}
void CTrapSettingsDlg::OnRadioDisable()
{
EnableThrottleWindows(FALSE);
}
void CTrapSettingsDlg::OnRadioEable()
{
EnableThrottleWindows(TRUE);
}
void CTrapSettingsDlg::EnableThrottleWindows(BOOL bEnableThrottle)
{
m_edtSeconds.EnableWindow(bEnableThrottle);
GetDlgItem(IDC_STATIC_MSG)->EnableWindow(bEnableThrottle);
GetDlgItem(IDC_STATIC_NTRAPS)->EnableWindow(bEnableThrottle);
GetDlgItem(IDC_STATIC_INTERVAL)->EnableWindow(bEnableThrottle);
m_edtTrapCount.EnableWindow(bEnableThrottle);
}
//****************************************************************
// CTrapSettingsDlg::OnButtonReset
//
// Reset the extension agent so that it starts sending traps again.
// The extension agent will stop sending traps if the throttle limit
// is exceeded (more than x number of traps per second are set).
//
// Parameters:
// None.
//
// Returns.
// Nothing.
//
//*****************************************************************
void CTrapSettingsDlg::OnButtonReset()
{
if (SUCCEEDED(g_reg.m_params.ResetExtensionAgent())) {
m_btnResetThrottle.EnableWindow(FALSE);
}
}
BOOL CTrapSettingsDlg::OnHelpInfo(HELPINFO *pHelpInfo)
{
if (pHelpInfo->iContextType == HELPINFO_WINDOW &&
pHelpInfo->iCtrlId != IDC_STATIC_MSG &&
pHelpInfo->iCtrlId != IDC_STATIC_BYTES)
{
::WinHelp ((HWND)pHelpInfo->hItemHandle,
AfxGetApp()->m_pszHelpFilePath,
HELP_WM_HELP,
(ULONG_PTR)g_aHelpIDs_IDD_SETTINGSDLG);
}
return TRUE;
}
void CTrapSettingsDlg::OnContextMenu(CWnd* pWnd, CPoint point)
{
if (this == pWnd)
return;
::WinHelp (pWnd->m_hWnd,
AfxGetApp()->m_pszHelpFilePath,
HELP_CONTEXTMENU,
(ULONG_PTR)g_aHelpIDs_IDD_SETTINGSDLG);
}
void CTrapSettingsDlg::OnClose()
{
TerminateBackgroundThread();
CDialog::OnClose();
}
void CTrapSettingsDlg::OnCancel()
{
TerminateBackgroundThread();
CDialog::OnCancel();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -