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

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. // OptionSoundDlg.cpp : implementation file
  12. //
  13. #include "stdafx.h"
  14. #include "myicq.h"
  15. #include "OptionSoundDlg.h"
  16. #include "icqlink.h"
  17. #include <mmsystem.h>
  18. #ifdef _DEBUG
  19. #define new DEBUG_NEW
  20. #undef THIS_FILE
  21. static char THIS_FILE[] = __FILE__;
  22. #endif
  23. /////////////////////////////////////////////////////////////////////////////
  24. // COptionSoundDlg property page
  25. IMPLEMENT_DYNCREATE(COptionSoundDlg, CPropertyPage)
  26. COptionSoundDlg::COptionSoundDlg() : CPropertyPage(COptionSoundDlg::IDD)
  27. {
  28. //{{AFX_DATA_INIT(COptionSoundDlg)
  29. //}}AFX_DATA_INIT
  30. curSel = 0;
  31. bitset<NR_USER_FLAGS> &f = icqLink->options.flags;
  32. m_soundOn = (f.test(UF_SOUND_ON) ? 0 : 1);
  33. }
  34. COptionSoundDlg::~COptionSoundDlg()
  35. {
  36. }
  37. void COptionSoundDlg::enableControls(BOOL enable)
  38. {
  39. GetDlgItem(IDC_SOUND_EVENT)->EnableWindow(enable);
  40. GetDlgItem(IDC_SOUND_FILE)->EnableWindow(enable);
  41. GetDlgItem(IDC_PLAY)->EnableWindow(enable);
  42. GetDlgItem(IDC_BROWSE)->EnableWindow(enable);
  43. }
  44. void COptionSoundDlg::DoDataExchange(CDataExchange* pDX)
  45. {
  46. CPropertyPage::DoDataExchange(pDX);
  47. //{{AFX_DATA_MAP(COptionSoundDlg)
  48. DDX_Control(pDX, IDC_SOUND_EVENT, m_cmbSoundEvent);
  49. DDX_Radio(pDX, IDC_SOUND_ON, m_soundOn);
  50. //}}AFX_DATA_MAP
  51. }
  52. BEGIN_MESSAGE_MAP(COptionSoundDlg, CPropertyPage)
  53. //{{AFX_MSG_MAP(COptionSoundDlg)
  54. ON_BN_CLICKED(IDC_BROWSE, OnBrowse)
  55. ON_BN_CLICKED(IDC_PLAY, OnPlay)
  56. ON_CBN_SELCHANGE(IDC_SOUND_EVENT, OnSelchangeSoundEvent)
  57. ON_BN_CLICKED(IDC_SOUND_ON, OnSoundOn)
  58. ON_BN_CLICKED(IDC_SOUND_OFF, OnSoundOff)
  59. //}}AFX_MSG_MAP
  60. END_MESSAGE_MAP()
  61. /////////////////////////////////////////////////////////////////////////////
  62. // COptionSoundDlg message handlers
  63. void COptionSoundDlg::OnBrowse() 
  64. {
  65. CFileDialog dlg(TRUE, "wav", NULL, OFN_HIDEREADONLY, "*.wav|*.wav||", this);
  66. if (dlg.DoModal() == IDOK)
  67. SetDlgItemText(IDC_SOUND_FILE, dlg.GetPathName());
  68. }
  69. void COptionSoundDlg::OnPlay() 
  70. {
  71. CString file;
  72. GetDlgItemText(IDC_SOUND_FILE, file);
  73. PlaySound(file, NULL, SND_ASYNC);
  74. }
  75. void COptionSoundDlg::OnSelchangeSoundEvent() 
  76. {
  77. GetDlgItemText(IDC_SOUND_FILE, soundFiles[curSel]);
  78. curSel = m_cmbSoundEvent.GetCurSel();
  79. SetDlgItemText(IDC_SOUND_FILE, soundFiles[curSel]);
  80. }
  81. BOOL COptionSoundDlg::OnInitDialog() 
  82. {
  83. CPropertyPage::OnInitDialog();
  84. IcqOption &options = icqLink->options;
  85. for (int i = 0; i < NR_SOUNDS; i++)
  86. soundFiles[i] = options.soundFiles[i].c_str();
  87. m_cmbSoundEvent.SetCurSel(curSel);
  88. SetDlgItemText(IDC_SOUND_FILE, soundFiles[curSel]);
  89. enableControls(m_soundOn == 0);
  90. return TRUE;  // return TRUE unless you set the focus to a control
  91.               // EXCEPTION: OCX Property Pages should return FALSE
  92. }
  93. void COptionSoundDlg::OnOK() 
  94. {
  95. icqLink->options.flags.set(UF_SOUND_ON, m_soundOn == 0);
  96. GetDlgItemText(IDC_SOUND_FILE, soundFiles[curSel]);
  97. for (int i = 0; i < NR_SOUNDS; i++)
  98. icqLink->options.soundFiles[i] = soundFiles[i];
  99. CPropertyPage::OnOK();
  100. }
  101. void COptionSoundDlg::OnSoundOn() 
  102. {
  103. enableControls();
  104. }
  105. void COptionSoundDlg::OnSoundOff() 
  106. {
  107. enableControls(FALSE);
  108. }