DetailCustomDlg.cpp
上传用户:zslianheng
上传日期:2013-04-03
资源大小:946k
文件大小:5k
源码类别:

Linux/Unix编程

开发平台:

Visual C++

  1. /***************************************************************************
  2.  *                                                                         *
  3.  *   This program is free software; you can redistribute it and/or modify  *
  4.  *   it under the terms of the GNU General Public License as published by  *
  5.  *   the Free Software Foundation; either version 2 of the License, or     *
  6.  *   (at your option) any later version.                                   *
  7.  *                                                                         *
  8.  *   copyright            : (C) 2002 by Zhang Yong                         *
  9.  *   email                : z-yong163@163.com                              *
  10.  ***************************************************************************/
  11. // DetailCustomDlg.cpp : implementation file
  12. //
  13. #include "stdafx.h"
  14. #include "myicq.h"
  15. #include "DetailCustomDlg.h"
  16. #include "ViewDetailDlg.h"
  17. #include <mmsystem.h>
  18. #include "icqdb.h"
  19. #ifdef _DEBUG
  20. #define new DEBUG_NEW
  21. #undef THIS_FILE
  22. static char THIS_FILE[] = __FILE__;
  23. #endif
  24. #define IDS_OPTION_FIRST IDS_OPTION_INVISIBLE
  25. #define IDS_OPTION_LAST IDS_OPTION_IGNORE
  26. /////////////////////////////////////////////////////////////////////////////
  27. // CDetailCustomDlg property page
  28. IMPLEMENT_DYNCREATE(CDetailCustomDlg, CPropertyPage)
  29. CDetailCustomDlg::CDetailCustomDlg() : CPropertyPage(CDetailCustomDlg::IDD)
  30. {
  31. //{{AFX_DATA_INIT(CDetailCustomDlg)
  32. // NOTE: the ClassWizard will add member initialization here
  33. //}}AFX_DATA_INIT
  34. curSel = 0;
  35. }
  36. CDetailCustomDlg::~CDetailCustomDlg()
  37. {
  38. }
  39. void CDetailCustomDlg::enableGreeting()
  40. {
  41. int i = IDS_OPTION_GREETING - IDS_OPTION_FIRST;
  42. GetDlgItem(IDC_GREETING)->EnableWindow(m_lstOptions.GetCheck(i) == 1);
  43. }
  44. void CDetailCustomDlg::DoDataExchange(CDataExchange* pDX)
  45. {
  46. CPropertyPage::DoDataExchange(pDX);
  47. //{{AFX_DATA_MAP(CDetailCustomDlg)
  48. DDX_Control(pDX, IDC_SOUND, m_cmbSound);
  49. DDX_Control(pDX, IDC_OPTIONS, m_lstOptions);
  50. //}}AFX_DATA_MAP
  51. }
  52. BEGIN_MESSAGE_MAP(CDetailCustomDlg, CPropertyPage)
  53. //{{AFX_MSG_MAP(CDetailCustomDlg)
  54. ON_LBN_SELCHANGE(IDC_OPTIONS, OnSelchangeOptions)
  55. ON_BN_CLICKED(IDC_CUSTOM_SOUND, OnCustomSound)
  56. ON_CBN_SELCHANGE(IDC_SOUND, OnSelchangeSound)
  57. ON_BN_CLICKED(IDC_PLAY, OnPlay)
  58. ON_BN_CLICKED(IDC_BROWSE, OnBrowse)
  59. ON_BN_CLICKED(IDC_MODIFY, OnModify)
  60. //}}AFX_MSG_MAP
  61. END_MESSAGE_MAP()
  62. /////////////////////////////////////////////////////////////////////////////
  63. // CDetailCustomDlg message handlers
  64. BOOL CDetailCustomDlg::OnInitDialog() 
  65. {
  66. CPropertyPage::OnInitDialog();
  67. DWORD style = GetClassLong(m_lstOptions, GCL_STYLE);
  68. SetClassLong(m_lstOptions, GCL_STYLE, style & ~CS_DBLCLKS);
  69. IcqContact *contact = ((CViewDetailDlg *) GetParent())->contact;
  70. bitset<NR_CONTACT_FLAGS> &f = contact->flags;
  71. for (int id = IDS_OPTION_FIRST; id <= IDS_OPTION_LAST; id++) {
  72. CString str;
  73. str.LoadString(id);
  74. int i = m_lstOptions.AddString(str);
  75. m_lstOptions.SetCheck(i, f.test(i));
  76. }
  77. CheckDlgButton(IDC_CUSTOM_SOUND, contact->flags.test(CF_CUSTOMSOUND));
  78. enableGreeting();
  79. OnCustomSound();
  80. m_cmbSound.SetCurSel(curSel);
  81. for (int i = 0; i < NR_CUSTOM_SOUNDS; i++)
  82. soundFiles[i] = contact->soundFiles[i].c_str();
  83. SetDlgItemText(IDC_FILE, soundFiles[curSel]);
  84. SetDlgItemText(IDC_GREETING, contact->greeting.c_str());
  85. return TRUE;  // return TRUE unless you set the focus to a control
  86.               // EXCEPTION: OCX Property Pages should return FALSE
  87. }
  88. void CDetailCustomDlg::OnSelchangeOptions() 
  89. {
  90. int i = m_lstOptions.GetCurSel();
  91. if (i == (IDS_OPTION_GREETING - IDS_OPTION_FIRST))
  92. enableGreeting();
  93. }
  94. void CDetailCustomDlg::OnCustomSound() 
  95. {
  96. BOOL enable = IsDlgButtonChecked(IDC_CUSTOM_SOUND);
  97. GetDlgItem(IDC_SOUND)->EnableWindow(enable);
  98. GetDlgItem(IDC_PLAY)->EnableWindow(enable);
  99. GetDlgItem(IDC_FILE)->EnableWindow(enable);
  100. GetDlgItem(IDC_BROWSE)->EnableWindow(enable);
  101. }
  102. void CDetailCustomDlg::OnSelchangeSound() 
  103. {
  104. CString str;
  105. GetDlgItemText(IDC_FILE, str);
  106. soundFiles[curSel] = str;
  107. curSel = m_cmbSound.GetCurSel();
  108. SetDlgItemText(IDC_FILE, soundFiles[curSel]);
  109. }
  110. void CDetailCustomDlg::OnPlay() 
  111. {
  112. CString fileName;
  113. GetDlgItemText(IDC_FILE, fileName);
  114. PlaySound(fileName, NULL, SND_FILENAME);
  115. }
  116. void CDetailCustomDlg::OnBrowse() 
  117. {
  118. CFileDialog dlg(TRUE, "wav", NULL, OFN_HIDEREADONLY, "*.wav|*.wav||", this);
  119. if (dlg.DoModal() == IDOK)
  120. SetDlgItemText(IDC_FILE, dlg.GetPathName());
  121. }
  122. void CDetailCustomDlg::OnModify() 
  123. {
  124. IcqContact *contact = ((CViewDetailDlg *) GetParent())->contact;
  125. bitset<NR_CONTACT_FLAGS> &f = contact->flags;
  126. int count = m_lstOptions.GetCount();
  127. for (int i = 0; i < count; i++)
  128. f.set(i, m_lstOptions.GetCheck(i) == 1);
  129. f.set(CF_CUSTOMSOUND, IsDlgButtonChecked(IDC_CUSTOM_SOUND));
  130. GetDlgItemText(IDC_FILE, soundFiles[curSel]);
  131. for (i = 0; i < NR_CUSTOM_SOUNDS; i++)
  132. contact->soundFiles[i] = soundFiles[i];
  133. CString str;
  134. GetDlgItemText(IDC_GREETING, str);
  135. contact->greeting = str;
  136. IcqDB::saveContact(*contact);
  137. }
  138. void CDetailCustomDlg::OnCancel() 
  139. {
  140. GetParent()->DestroyWindow();
  141. }