ConfigSysChating.cpp
上传用户:maryhy001
上传日期:2007-05-02
资源大小:2317k
文件大小:8k
源码类别:

网格计算

开发平台:

Visual C++

  1. // ConfigSysChating.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "xShell.h"
  5. #include "trfAgent.h"
  6. #include "ConfigSysChating.h"
  7. // CConfigSysChating property page
  8. IMPLEMENT_DYNCREATE(CConfigSysChating, CPropertyPage)
  9. CConfigSysChating::CConfigSysChating() : CPropertyPage(CConfigSysChating::IDD)
  10. {
  11. //{{AFX_DATA_INIT(CConfigSysChating)
  12. m_dwChatPort = 0;
  13. m_nSoundNotify = -1;
  14. m_nTipWndNotify = -1;
  15. m_strChatLogfile = _T("");
  16. //}}AFX_DATA_INIT
  17. }
  18. CConfigSysChating::~CConfigSysChating(){}
  19. void CConfigSysChating::DoDataExchange(CDataExchange* pDX)
  20. {
  21. CPropertyPage::DoDataExchange(pDX);
  22. //{{AFX_DATA_MAP(CConfigSysChating)
  23. DDX_Control(pDX, IDC_PICPREVAREA, m_wndHeadPrev);
  24. DDX_Text(pDX, IDC_EDTCHATPORT, m_dwChatPort);
  25. DDV_MinMaxUInt(pDX, m_dwChatPort, 1000, 65535);
  26. DDX_Radio(pDX, IDC_RDOSOUNDNOTIFY, m_nSoundNotify);
  27. DDX_Radio(pDX, IDC_RDOTIPWNDNOTIFY, m_nTipWndNotify);
  28. DDX_Text(pDX, IDC_EDTAUTOGREETINGTXT, m_strChatLogfile);
  29. DDV_MaxChars(pDX, m_strChatLogfile, 256);
  30. //}}AFX_DATA_MAP
  31. }
  32. BEGIN_MESSAGE_MAP(CConfigSysChating, CPropertyPage)
  33. //{{AFX_MSG_MAP(CConfigSysChating)
  34. ON_BN_CLICKED(IDC_RDOSOUNDNOTIFY, OnRdosoundnotify)
  35. ON_BN_CLICKED(IDC_RDOTIPWNDNOTIFY, OnRdotipwndnotify)
  36. ON_BN_CLICKED(IDC_BTNSELHEADPIC, OnSelHeadpict)
  37. ON_MESSAGE(UWM_PICTSVIEWERCLICKED, OnHeadPortraitClicked)
  38. ON_BN_CLICKED(IDC_BTNSELCHATLOGFILE, OnSelChatLogfile)
  39. //}}AFX_MSG_MAP
  40. END_MESSAGE_MAP()
  41. // CConfigSysChating message handlers
  42. BOOL CConfigSysChating::Refresh(void)
  43. {
  44. //Load setting from registry
  45. CRegister regKey;
  46. if(!regKey.Open(HKEY_CURRENT_USER, REG_SSYSSETTINGKEY))
  47. {
  48. TRACE0("Failed to open the registry keyn");
  49. return FALSE;
  50. }
  51. //Integer
  52. DWORD dwValue = regKey.Read_DWord_Value(REG_NCHATUDPPORT);
  53. this->m_dwChatPort = dwValue ? dwValue : 5558;
  54. dwValue = regKey.Read_DWord_Value(REG_NHEADBMPINDEX);
  55. this->m_nHeadportrait = dwValue;
  56. dwValue = regKey.Read_DWord_Value(REG_NMSGNOTIFYTYPE);
  57. switch(dwValue) {
  58. case 1:
  59. default:
  60. {
  61. this->m_nSoundNotify = 1;
  62. this->m_nTipWndNotify= 0;
  63. }
  64. break;
  65. case 2:
  66. {
  67. this->m_nSoundNotify = 0;
  68. this->m_nTipWndNotify= 1;
  69. }
  70. break;
  71. }
  72. //String
  73. CString strTxt = regKey.Read_String_Value(REG_STRCHATLOGFILE);
  74. this->m_strChatLogfile = strTxt;
  75. this->RefreshHeadportrait();
  76. this->UpdateData(FALSE);
  77. return TRUE;
  78. }
  79. BOOL CConfigSysChating::OnSetActive() 
  80. {
  81. return CPropertyPage::OnSetActive();
  82. }
  83. void CConfigSysChating::OnOK() 
  84. {
  85. this->UpdateData(TRUE);
  86. //Load setting from registry
  87. CRegister regKey;
  88. if(!regKey.Open(HKEY_CURRENT_USER, REG_SSYSSETTINGKEY))
  89. {
  90. TRACE0("Failed to open the registry keyn");
  91. return ;
  92. }
  93. //Integer
  94. BOOL l = regKey.Write_DWord_Value(REG_NCHATUDPPORT, this->m_dwChatPort);
  95. if(!l)
  96. {
  97. TRACE0("Failed to write dword key valuen");
  98. return ;
  99. }
  100. l = regKey.Write_DWord_Value(REG_NHEADBMPINDEX, this->m_nHeadportrait);
  101. if(!l)
  102. {
  103. TRACE0("Failed to write dword key valuen");
  104. return ;
  105. }
  106. DWORD dwValue = 0x0000;
  107. if(this->m_nSoundNotify)
  108. dwValue = 1;
  109. else if(this->m_nTipWndNotify)
  110. dwValue = 2;
  111. l = regKey.Write_DWord_Value(REG_NMSGNOTIFYTYPE, dwValue);
  112. if(!l)
  113. {
  114. TRACE0("Failed to write dword key valuen");
  115. return ;
  116. }
  117. //String
  118. l = regKey.Write_String_Value(REG_STRCHATLOGFILE, this->m_strChatLogfile);
  119. if(!l)
  120. {
  121. TRACE0("Failed to write string key valuen");
  122. return ;
  123. }
  124. CPropertyPage::OnOK();
  125. }
  126. void CConfigSysChating::OnRdosoundnotify() 
  127. {
  128. CButton *pbutton = (CButton*)this->GetDlgItem(IDC_RDOSOUNDNOTIFY);
  129. pbutton->SetCheck(1);
  130. pbutton = (CButton*)this->GetDlgItem(IDC_RDOTIPWNDNOTIFY);
  131. pbutton->SetCheck(0);
  132. this->UpdateData(TRUE);
  133. }
  134. void CConfigSysChating::OnRdotipwndnotify() 
  135. {
  136. CButton *pbutton = (CButton*)this->GetDlgItem(IDC_RDOSOUNDNOTIFY);
  137. pbutton->SetCheck(0);
  138. pbutton = (CButton*)this->GetDlgItem(IDC_RDOTIPWNDNOTIFY);
  139. pbutton->SetCheck(1);
  140. this->UpdateData(TRUE);
  141. }
  142. BOOL CConfigSysChating::OnInitDialog() 
  143. {
  144. CPropertyPage::OnInitDialog();
  145. CBitmap imglstbmp;
  146. //1
  147. imglstbmp.LoadBitmap(IDB_MAN32_HOT);
  148. m_imglist_man.Create(32, 32, ILC_COLORDDB | ILC_MASK, 40, 1);
  149. m_imglist_man.Add(&imglstbmp, RGB(255, 255, 255));
  150. imglstbmp.Detach();
  151. //2
  152. imglstbmp.LoadBitmap(IDB_WOMAN32_HOT);
  153. m_imglist_woman.Create(32, 32, ILC_COLORDDB | ILC_MASK, 40, 1);
  154. m_imglist_woman.Add(&imglstbmp, RGB(255, 255, 255));
  155. imglstbmp.Detach();
  156. //3
  157. if(!this->Refresh())
  158. {
  159. return FALSE;
  160. }
  161. return TRUE;  // return TRUE unless you set the focus to a control
  162.               // EXCEPTION: OCX Property Pages should return FALSE
  163. }
  164. BOOL CConfigSysChating::DestroyWindow() 
  165. {
  166. m_imglist_man.Detach();
  167. m_imglist_woman.Detach();
  168. if(dlgPictViewer.GetSafeHwnd())
  169. {
  170. dlgPictViewer.DestroyWindow();
  171. }
  172. return CPropertyPage::DestroyWindow();
  173. }
  174. void CConfigSysChating::GetImageFromList(CImageList *lstImages, 
  175. int nImage, CBitmap* destBitmap)
  176. {    
  177. //First we want to create a temporary image list we can manipulate
  178. CImageList tmpList;
  179. tmpList.Create(lstImages);
  180.     //Then swap the requested image to the first spot in the list 
  181.     tmpList.Copy( 0, nImage, ILCF_SWAP );
  182.     
  183.     //Now we need to get som information about the image 
  184.     IMAGEINFO lastImage;
  185.     tmpList.GetImageInfo(0,&lastImage);
  186.     
  187.     //Heres where it gets fun
  188.     //Create a Compatible Device Context using 
  189.     //the valid DC of your calling window
  190.     CDC dcMem; 
  191. dcMem.CreateCompatibleDC (GetWindowDC()); 
  192.     
  193.     //This rect simply stored the size of the image we need
  194.     CRect rect (lastImage.rcImage);
  195.     
  196.     //Using the bitmap passed in, Create a bitmap 
  197.     //compatible with the window DC
  198.     //We also know that the bitmap needs to be a certain size.
  199.     destBitmap->CreateCompatibleBitmap (this->GetWindowDC(), 
  200. rect.Width (), rect.Height ());
  201.     
  202.     //Select the new destination bitmap into the DC we created above
  203.     CBitmap* pBmpOld = dcMem.SelectObject (destBitmap);
  204.     
  205.     //This call apparently "draws" the bitmap from the list, 
  206.     //onto the new destination bitmap
  207.     tmpList.DrawIndirect (&dcMem, 0, CPoint (0, 0), 
  208. CSize (rect.Width (), rect.Height ()), CPoint (0, 0));
  209.     
  210.     
  211.     //cleanup by reselecting the old bitmap object into the DC
  212.     dcMem.SelectObject (pBmpOld);
  213. }
  214. void CConfigSysChating::RefreshHeadportrait(void)
  215. {
  216. //Load the head portrait.
  217. m_imghead.DeleteObject();
  218. m_imghead.Detach();
  219. switch(HIBYTE(m_nHeadportrait)) {
  220. case 0:
  221. CConfigSysChating::GetImageFromList(&m_imglist_man, LOBYTE(m_nHeadportrait), &m_imghead);
  222. break;
  223. case 1:
  224. CConfigSysChating::GetImageFromList(&m_imglist_woman, LOBYTE(m_nHeadportrait), &m_imghead);
  225. break;
  226. }
  227. if(m_imghead.GetSafeHandle())
  228. {
  229. this->m_wndHeadPrev.SetBitmap(m_imghead);
  230. }
  231. }
  232. void CConfigSysChating::OnSelHeadpict() 
  233. {
  234. if(dlgPictViewer.Create(this))
  235. {
  236. CPictsGroup pgPictsGroup;
  237. CWnd *pOrgiWnd = this->GetDlgItem(IDC_BTNSELHEADPIC);
  238. ASSERT(NULL != pOrgiWnd && pOrgiWnd->GetSafeHwnd());
  239. dlgPictViewer.SetOrgWindow(pOrgiWnd->GetSafeHwnd());
  240. pgPictsGroup.SetOwnerWnd(&dlgPictViewer);
  241. pgPictsGroup.SetCaption(_LoadString(IDS_CHATMANHEADPORTRAIT));
  242. pgPictsGroup.SetImageList(m_imglist_man);
  243. dlgPictViewer.InsertPictsGroup(pgPictsGroup);
  244. pgPictsGroup.SetOnlyShowCaption(TRUE);
  245. pgPictsGroup.SetCaption(_LoadString(IDS_CHARWOMANHEADPORTRAIT));
  246. pgPictsGroup.SetImageList(m_imglist_woman);
  247. dlgPictViewer.InsertPictsGroup(pgPictsGroup);
  248. pgPictsGroup.SetOnlyShowCaption(TRUE);
  249. dlgPictViewer.ShowWindow(SW_SHOW);
  250. }
  251. }
  252. void CConfigSysChating::OnHeadPortraitClicked(WPARAM wp, LPARAM lp)
  253. {
  254. this->m_nHeadportrait = wp;
  255. this->dlgPictViewer.DestroyWindow();
  256. this->RefreshHeadportrait();
  257. }
  258. void CConfigSysChating::OnSelChatLogfile() 
  259. {
  260. CXShell shell;
  261. CString sPath;
  262. if(shell.GetFolder(&sPath, "Select Destination Directory", this->GetSafeHwnd(), NULL, NULL))
  263. {
  264. char szlocalhostname[MAX_PATH];
  265. DWORD dwSize = sizeof(szlocalhostname);
  266. memset(szlocalhostname, 0x0, dwSize);
  267. GetComputerName(szlocalhostname, &dwSize);
  268. this->m_strChatLogfile.Format("%s\%s.txt", sPath, szlocalhostname);
  269. this->UpdateData(FALSE);
  270. }
  271. else
  272. {
  273. //MSGBOX_ERROR(_LoadString(IDS_OPENSHELLFLODERFAILED).GetBuffer(0));
  274. return ;
  275. }
  276. }