ConfigSysChating.cpp
上传用户:maryhy001
上传日期:2007-05-02
资源大小:2317k
文件大小:8k
- // ConfigSysChating.cpp : implementation file
- //
- #include "stdafx.h"
- #include "xShell.h"
- #include "trfAgent.h"
- #include "ConfigSysChating.h"
- // CConfigSysChating property page
- IMPLEMENT_DYNCREATE(CConfigSysChating, CPropertyPage)
- CConfigSysChating::CConfigSysChating() : CPropertyPage(CConfigSysChating::IDD)
- {
- //{{AFX_DATA_INIT(CConfigSysChating)
- m_dwChatPort = 0;
- m_nSoundNotify = -1;
- m_nTipWndNotify = -1;
- m_strChatLogfile = _T("");
- //}}AFX_DATA_INIT
- }
- CConfigSysChating::~CConfigSysChating(){}
- void CConfigSysChating::DoDataExchange(CDataExchange* pDX)
- {
- CPropertyPage::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CConfigSysChating)
- DDX_Control(pDX, IDC_PICPREVAREA, m_wndHeadPrev);
- DDX_Text(pDX, IDC_EDTCHATPORT, m_dwChatPort);
- DDV_MinMaxUInt(pDX, m_dwChatPort, 1000, 65535);
- DDX_Radio(pDX, IDC_RDOSOUNDNOTIFY, m_nSoundNotify);
- DDX_Radio(pDX, IDC_RDOTIPWNDNOTIFY, m_nTipWndNotify);
- DDX_Text(pDX, IDC_EDTAUTOGREETINGTXT, m_strChatLogfile);
- DDV_MaxChars(pDX, m_strChatLogfile, 256);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CConfigSysChating, CPropertyPage)
- //{{AFX_MSG_MAP(CConfigSysChating)
- ON_BN_CLICKED(IDC_RDOSOUNDNOTIFY, OnRdosoundnotify)
- ON_BN_CLICKED(IDC_RDOTIPWNDNOTIFY, OnRdotipwndnotify)
- ON_BN_CLICKED(IDC_BTNSELHEADPIC, OnSelHeadpict)
- ON_MESSAGE(UWM_PICTSVIEWERCLICKED, OnHeadPortraitClicked)
- ON_BN_CLICKED(IDC_BTNSELCHATLOGFILE, OnSelChatLogfile)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- // CConfigSysChating message handlers
- BOOL CConfigSysChating::Refresh(void)
- {
- //Load setting from registry
- CRegister regKey;
-
- if(!regKey.Open(HKEY_CURRENT_USER, REG_SSYSSETTINGKEY))
- {
- TRACE0("Failed to open the registry keyn");
- return FALSE;
- }
- //Integer
- DWORD dwValue = regKey.Read_DWord_Value(REG_NCHATUDPPORT);
- this->m_dwChatPort = dwValue ? dwValue : 5558;
- dwValue = regKey.Read_DWord_Value(REG_NHEADBMPINDEX);
- this->m_nHeadportrait = dwValue;
-
- dwValue = regKey.Read_DWord_Value(REG_NMSGNOTIFYTYPE);
- switch(dwValue) {
- case 1:
- default:
- {
- this->m_nSoundNotify = 1;
- this->m_nTipWndNotify= 0;
- }
- break;
- case 2:
- {
- this->m_nSoundNotify = 0;
- this->m_nTipWndNotify= 1;
- }
- break;
- }
- //String
- CString strTxt = regKey.Read_String_Value(REG_STRCHATLOGFILE);
- this->m_strChatLogfile = strTxt;
-
- this->RefreshHeadportrait();
- this->UpdateData(FALSE);
-
- return TRUE;
- }
- BOOL CConfigSysChating::OnSetActive()
- {
- return CPropertyPage::OnSetActive();
- }
- void CConfigSysChating::OnOK()
- {
- this->UpdateData(TRUE);
- //Load setting from registry
- CRegister regKey;
-
- if(!regKey.Open(HKEY_CURRENT_USER, REG_SSYSSETTINGKEY))
- {
- TRACE0("Failed to open the registry keyn");
- return ;
- }
- //Integer
-
- BOOL l = regKey.Write_DWord_Value(REG_NCHATUDPPORT, this->m_dwChatPort);
- if(!l)
- {
- TRACE0("Failed to write dword key valuen");
- return ;
- }
- l = regKey.Write_DWord_Value(REG_NHEADBMPINDEX, this->m_nHeadportrait);
- if(!l)
- {
- TRACE0("Failed to write dword key valuen");
- return ;
- }
-
- DWORD dwValue = 0x0000;
- if(this->m_nSoundNotify)
- dwValue = 1;
- else if(this->m_nTipWndNotify)
- dwValue = 2;
- l = regKey.Write_DWord_Value(REG_NMSGNOTIFYTYPE, dwValue);
- if(!l)
- {
- TRACE0("Failed to write dword key valuen");
- return ;
- }
- //String
- l = regKey.Write_String_Value(REG_STRCHATLOGFILE, this->m_strChatLogfile);
- if(!l)
- {
- TRACE0("Failed to write string key valuen");
- return ;
- }
- CPropertyPage::OnOK();
- }
- void CConfigSysChating::OnRdosoundnotify()
- {
- CButton *pbutton = (CButton*)this->GetDlgItem(IDC_RDOSOUNDNOTIFY);
- pbutton->SetCheck(1);
- pbutton = (CButton*)this->GetDlgItem(IDC_RDOTIPWNDNOTIFY);
- pbutton->SetCheck(0);
- this->UpdateData(TRUE);
- }
- void CConfigSysChating::OnRdotipwndnotify()
- {
- CButton *pbutton = (CButton*)this->GetDlgItem(IDC_RDOSOUNDNOTIFY);
- pbutton->SetCheck(0);
-
- pbutton = (CButton*)this->GetDlgItem(IDC_RDOTIPWNDNOTIFY);
- pbutton->SetCheck(1);
-
- this->UpdateData(TRUE);
- }
- BOOL CConfigSysChating::OnInitDialog()
- {
- CPropertyPage::OnInitDialog();
-
- CBitmap imglstbmp;
-
- //1
- imglstbmp.LoadBitmap(IDB_MAN32_HOT);
-
- m_imglist_man.Create(32, 32, ILC_COLORDDB | ILC_MASK, 40, 1);
- m_imglist_man.Add(&imglstbmp, RGB(255, 255, 255));
-
- imglstbmp.Detach();
-
- //2
- imglstbmp.LoadBitmap(IDB_WOMAN32_HOT);
-
- m_imglist_woman.Create(32, 32, ILC_COLORDDB | ILC_MASK, 40, 1);
- m_imglist_woman.Add(&imglstbmp, RGB(255, 255, 255));
-
- imglstbmp.Detach();
- //3
- if(!this->Refresh())
- {
- return FALSE;
- }
- return TRUE; // return TRUE unless you set the focus to a control
- // EXCEPTION: OCX Property Pages should return FALSE
- }
- BOOL CConfigSysChating::DestroyWindow()
- {
- m_imglist_man.Detach();
- m_imglist_woman.Detach();
- if(dlgPictViewer.GetSafeHwnd())
- {
- dlgPictViewer.DestroyWindow();
- }
- return CPropertyPage::DestroyWindow();
- }
- void CConfigSysChating::GetImageFromList(CImageList *lstImages,
- int nImage, CBitmap* destBitmap)
- {
- //First we want to create a temporary image list we can manipulate
- CImageList tmpList;
- tmpList.Create(lstImages);
-
- //Then swap the requested image to the first spot in the list
- tmpList.Copy( 0, nImage, ILCF_SWAP );
-
- //Now we need to get som information about the image
- IMAGEINFO lastImage;
- tmpList.GetImageInfo(0,&lastImage);
-
- //Heres where it gets fun
- //Create a Compatible Device Context using
- //the valid DC of your calling window
- CDC dcMem;
- dcMem.CreateCompatibleDC (GetWindowDC());
-
- //This rect simply stored the size of the image we need
- CRect rect (lastImage.rcImage);
-
- //Using the bitmap passed in, Create a bitmap
- //compatible with the window DC
- //We also know that the bitmap needs to be a certain size.
- destBitmap->CreateCompatibleBitmap (this->GetWindowDC(),
- rect.Width (), rect.Height ());
-
- //Select the new destination bitmap into the DC we created above
- CBitmap* pBmpOld = dcMem.SelectObject (destBitmap);
-
- //This call apparently "draws" the bitmap from the list,
- //onto the new destination bitmap
- tmpList.DrawIndirect (&dcMem, 0, CPoint (0, 0),
- CSize (rect.Width (), rect.Height ()), CPoint (0, 0));
-
-
- //cleanup by reselecting the old bitmap object into the DC
- dcMem.SelectObject (pBmpOld);
- }
- void CConfigSysChating::RefreshHeadportrait(void)
- {
- //Load the head portrait.
-
- m_imghead.DeleteObject();
- m_imghead.Detach();
-
- switch(HIBYTE(m_nHeadportrait)) {
- case 0:
- CConfigSysChating::GetImageFromList(&m_imglist_man, LOBYTE(m_nHeadportrait), &m_imghead);
- break;
-
- case 1:
- CConfigSysChating::GetImageFromList(&m_imglist_woman, LOBYTE(m_nHeadportrait), &m_imghead);
- break;
- }
- if(m_imghead.GetSafeHandle())
- {
- this->m_wndHeadPrev.SetBitmap(m_imghead);
- }
- }
- void CConfigSysChating::OnSelHeadpict()
- {
- if(dlgPictViewer.Create(this))
- {
- CPictsGroup pgPictsGroup;
-
- CWnd *pOrgiWnd = this->GetDlgItem(IDC_BTNSELHEADPIC);
- ASSERT(NULL != pOrgiWnd && pOrgiWnd->GetSafeHwnd());
- dlgPictViewer.SetOrgWindow(pOrgiWnd->GetSafeHwnd());
-
- pgPictsGroup.SetOwnerWnd(&dlgPictViewer);
-
- pgPictsGroup.SetCaption(_LoadString(IDS_CHATMANHEADPORTRAIT));
- pgPictsGroup.SetImageList(m_imglist_man);
- dlgPictViewer.InsertPictsGroup(pgPictsGroup);
- pgPictsGroup.SetOnlyShowCaption(TRUE);
-
- pgPictsGroup.SetCaption(_LoadString(IDS_CHARWOMANHEADPORTRAIT));
- pgPictsGroup.SetImageList(m_imglist_woman);
- dlgPictViewer.InsertPictsGroup(pgPictsGroup);
- pgPictsGroup.SetOnlyShowCaption(TRUE);
-
- dlgPictViewer.ShowWindow(SW_SHOW);
- }
- }
- void CConfigSysChating::OnHeadPortraitClicked(WPARAM wp, LPARAM lp)
- {
- this->m_nHeadportrait = wp;
- this->dlgPictViewer.DestroyWindow();
- this->RefreshHeadportrait();
- }
- void CConfigSysChating::OnSelChatLogfile()
- {
- CXShell shell;
- CString sPath;
- if(shell.GetFolder(&sPath, "Select Destination Directory", this->GetSafeHwnd(), NULL, NULL))
- {
- char szlocalhostname[MAX_PATH];
- DWORD dwSize = sizeof(szlocalhostname);
-
- memset(szlocalhostname, 0x0, dwSize);
- GetComputerName(szlocalhostname, &dwSize);
- this->m_strChatLogfile.Format("%s\%s.txt", sPath, szlocalhostname);
- this->UpdateData(FALSE);
- }
- else
- {
- //MSGBOX_ERROR(_LoadString(IDS_OPENSHELLFLODERFAILED).GetBuffer(0));
- return ;
- }
- }