ConfigSysView.cpp
上传用户:maryhy001
上传日期:2007-05-02
资源大小:2317k
文件大小:6k
- // ConfigSysView.cpp : implementation file
- //
- #include "stdafx.h"
- #include "trfAgent.h"
- #include "ConfigSysView.h"
- #include "xshell.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CConfigSysView property page
- IMPLEMENT_DYNCREATE(CConfigSysView, CPropertyPage)
- CConfigSysView::CConfigSysView() : CPropertyPage(CConfigSysView::IDD)
- {
- CString str = ENV_SYSROOTDIR;
- str += ENV_DEFAULT_RECVFLEDIR;
- //{{AFX_DATA_INIT(CConfigSysView)
- m_bAutoDelSndedFiles = TRUE;
- m_bMinToHide = TRUE;
- m_sRecvDestDir = str;
- m_bStartToHide = TRUE;
- m_bAutoRun = FALSE;
- //}}AFX_DATA_INIT
- }
- CConfigSysView::~CConfigSysView()
- {
- }
- void CConfigSysView::DoDataExchange(CDataExchange* pDX)
- {
- CPropertyPage::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CConfigSysView)
- DDX_Control(pDX, IDC_BTNSELSOUND, m_oSelSound);
- DDX_Control(pDX, IDC_BTNSELDESTDIR, m_oSelDestdir);
- DDX_Control(pDX, IDC_ALARMSOUND, m_oAlarmsound);
- DDX_Check(pDX, IDC_AUTODELSNDEDFILE, m_bAutoDelSndedFiles);
- DDX_Check(pDX, IDC_MINTOHIDE, m_bMinToHide);
- DDX_Text(pDX, IDC_RECVDESTDIR, m_sRecvDestDir);
- DDX_Check(pDX, IDC_STARTTOHIDE, m_bStartToHide);
- DDX_Check(pDX, IDC_AUTORENAME, m_bAutoRun);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CConfigSysView, CPropertyPage)
- //{{AFX_MSG_MAP(CConfigSysView)
- ON_COMMAND(IDC_BTNSELDESTDIR, OnSelectDestDir)
- ON_COMMAND(IDC_BTNSELSOUND, OnSelectSoundFile)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- BOOL CConfigSysView::Refresh()
- {
- //Load setting from registry
- CRegister regKey;
-
- if(!regKey.Open(HKEY_CURRENT_USER, REG_SSYSSETTINGKEY))
- {
- TRACE0("Failed to open the registry keyn");
- return FALSE;
- }
-
- //@1---SysView
-
- //BOOL
- BOOL l = regKey.Read_Bool_Value(REG_BAUTODELSNDEDFILE);
- this->m_bAutoDelSndedFiles = l;
-
- l = regKey.Read_Bool_Value(REG_BAUTORUNWINSTART);
- this->m_bAutoRun = l;
-
- l = regKey.Read_Bool_Value(REG_BAUTODELSNDEDFILE);
- this->m_bAutoDelSndedFiles = l;
-
- l = regKey.Read_Bool_Value(REG_BSTARTTOHIDE);
- this->m_bStartToHide = l;
-
- l = regKey.Read_Bool_Value(REG_BMINITOHIDE);
- this->m_bMinToHide = l;
-
- //String
- CString strValue;
-
- strValue = regKey.Read_String_Value(REG_SRECVFLESDIR);
- if(strValue.IsEmpty())
- {
- strValue = ENV_SYSROOTDIR;
- strValue += ENV_DEFAULT_RECVFLEDIR;
- }
- this->m_sRecvDestDir = strValue;
-
- //
- for (int i = this->m_oAlarmsound.GetCount()-1; i > -1; --i)
- {
- this->m_oAlarmsound.DeleteString(i);
- }
- this->m_oAlarmsound.AddString(ENV_DEFAULT_ALARMSOUND);
- strValue = regKey.Read_String_Value(REG_SALARMSOUND);
- if(!strValue.IsEmpty() && strValue.CompareNoCase(ENV_DEFAULT_ALARMSOUND))
- {
- this->m_oAlarmsound.InsertString(
- this->m_oAlarmsound.GetCount(), strValue);
- }
- else if(strValue.IsEmpty())
- {
- regKey.Write_String_Value(REG_SALARMSOUND, ENV_DEFAULT_ALARMSOUND);
- }
-
- //Controls
- int index = this->m_oAlarmsound.GetCount();
- this->m_oAlarmsound.SetCurSel(index-1);
- this->UpdateData(FALSE);
- return TRUE;
- }
- BOOL CConfigSysView::OnSetActive()
- {
- return CPropertyPage::OnSetActive();
- }
- void CConfigSysView::OnOK()
- {
- //Load setting from registry
- CRegister regKey;
-
- if(!regKey.Open(HKEY_CURRENT_USER, REG_SSYSSETTINGKEY))
- {
- TRACE0("Failed to open the registry keyn");
- return ;
- }
-
- //@1---SysView
-
- //BOOL
- BOOL l = regKey.Write_Bool_Value(REG_BAUTODELSNDEDFILE, m_bAutoDelSndedFiles);
- if(!l)
- {
- TRACE0("Failed to write bool key valuen");
- return ;
- }
-
- l = regKey.Write_Bool_Value(REG_BAUTORUNWINSTART, m_bAutoRun);
- if(!l)
- {
- TRACE0("Failed to write bool key valuen");
- return ;
- }
-
- l = regKey.Write_Bool_Value(REG_BAUTODELSNDEDFILE, m_bAutoDelSndedFiles);
- if(!l)
- {
- TRACE0("Failed to write bool key valuen");
- return ;
- }
-
- l = regKey.Write_Bool_Value(REG_BSTARTTOHIDE, m_bStartToHide);
- if(!l)
- {
- TRACE0("Failed to write bool key valuen");
- return ;
- }
-
- l = regKey.Write_Bool_Value(REG_BMINITOHIDE, m_bMinToHide);
- if(!l)
- {
- TRACE0("Failed to write bool key valuen");
- return ;
- }
-
- //String
- CString strValue = m_sRecvDestDir;
- l = regKey.Write_String_Value(REG_SRECVFLESDIR, strValue);
- if(!l)
- {
- TRACE0("Failed to write string key valuen");
- return ;
- }
-
- m_oAlarmsound.GetWindowText(strValue);
- l = regKey.Write_String_Value(REG_SALARMSOUND, strValue);
- if(!l)
- {
- TRACE0("Failed to write string key valuen");
- return ;
- }
- //////////////////////////////////////////////////////////////////////////
- //if auto run then write "HKEY_CURRENT_USERSoftwareMicrosoftWindowsCurrentVersionRun" key.
-
- regKey.Close();
- if(!regKey.Open(HKEY_CURRENT_USER, REG_SSYSAUTORUN))
- {
- TRACE0("Failed to open the registry keyn");
- return ;
- }
-
- char lpKeyName[64], lpKeyVal[MAX_PATH];
-
- _snprintf(lpKeyName, sizeof(lpKeyName), "%s %s", SYS_APPANEM, SYS_VERSION_NO);
- if(m_bAutoRun)
- {
- ::GetModuleFileName(NULL, lpKeyVal, sizeof(lpKeyVal));
- regKey.Write_String_Value(lpKeyName, lpKeyVal);
- }
- else
- {
- regKey.DeleteValue(lpKeyName);
- }
- //////////////////////////////////////////////////////////////////////////
- CPropertyPage::OnOK();
- }
- void CConfigSysView::OnSelectDestDir()
- {
- CXShell shell;
- CString sPath;
- if(shell.GetFolder(&sPath, "Select Destination Directory",
- this->GetSafeHwnd(), NULL, NULL))
- {
- this->m_sRecvDestDir = sPath;
- this->UpdateData(FALSE);
- }
- else
- {
- //MSGBOX_ERROR(_LoadString(IDS_OPENSHELLFLODERFAILED).GetBuffer(0));
- return ;
- }
- }
- void CConfigSysView::OnSelectSoundFile()
- {
- LPCTSTR lpszDefExt = _T(""),
- lpszFilter = _T("All Wav Files(*.wav)|*.wav||");
-
- CFileDialog dlg(TRUE, lpszDefExt, NULL, OFN_HIDEREADONLY | OFN_READONLY, lpszFilter);
-
- if(dlg.DoModal() == IDOK)
- {
- for (int i = this->m_oAlarmsound.GetCount()-1; i > -1; --i)
- {
- this->m_oAlarmsound.DeleteString(i);
- }
- this->m_oAlarmsound.AddString(ENV_DEFAULT_ALARMSOUND);
- CString sFileName = dlg.GetPathName();
- this->m_oAlarmsound.InsertString(
- this->m_oAlarmsound.GetCount(), sFileName);
- this->m_oAlarmsound.SetCurSel(this->m_oAlarmsound.GetCount()-1);
- }
- }
- BOOL CConfigSysView::OnInitDialog()
- {
- CPropertyPage::OnInitDialog();
-
- if(!this->Refresh())
- {
- return FALSE;
- }
- return TRUE; // return TRUE unless you set the focus to a control
- // EXCEPTION: OCX Property Pages should return FALSE
- }