// SetSoundDlg.cpp : implementation file // #include "stdafx.h" #include "gpsmain.h" #include "SetSoundDlg.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CSetSoundDlg dialog CSetSoundDlg::CSetSoundDlg(CWnd* pParent /*=NULL*/) : CDialog(CSetSoundDlg::IDD, pParent) { //{{AFX_DATA_INIT(CSetSoundDlg) //}}AFX_DATA_INIT // 初始化背景画刷 CBitmap tmpBmp; // 从资源中加载背景图片 tmpBmp.LoadBitmap(IDB_SETVOLUME_WND); // 建立背景画刷 m_BgDC.CreateCompatibleDC(NULL); m_BgDC.SelectObject(&tmpBmp); tmpBmp.DeleteObject(); // 18x18 粗体 m_titleFont.CreateFont(18,0,0,0,FW_BOLD,0,0,0,GB2312_CHARSET,OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,DEFAULT_PITCH|FF_SWISS,_T("Arial")); m_txtFont.CreateFont(16,0,0,0,FW_NORMAL,0,0,0,GB2312_CHARSET,OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,DEFAULT_PITCH|FF_SWISS,_T("Arial")); m_Volume = 0; // 初始化DC m_MemBeepDisDC.CreateCompatibleDC(NULL); // 装载位图 tmpBmp.LoadBitmap(IDB_SETVOLUME_BEEP); // 获取数据 m_MemBeepDisDC.SelectObject(&tmpBmp); // 清理资源 tmpBmp.DeleteObject(); // 初始化DC m_MemBeepEnDC.CreateCompatibleDC(NULL); // 装载位图 tmpBmp.LoadBitmap(IDB_SETVOLUME_BEEPD); // 获取数据 m_MemBeepEnDC.SelectObject(&tmpBmp); // 清理资源 tmpBmp.DeleteObject(); } CSetSoundDlg::~CSetSoundDlg() { m_BgDC.DeleteDC(); m_txtFont.DeleteObject(); m_titleFont.DeleteObject(); } void CSetSoundDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CSetSoundDlg) DDX_Control(pDX, IDC_PROGRESS_SOUND, m_prgVolume); DDX_Control(pDX, IDC_BUTTON_SETSOUND_DEC, m_butDec); DDX_Control(pDX, IDC_BUTTON_SETSOUND_CLOSE, m_butClose); DDX_Control(pDX, IDC_BUTTON_SETSOUND_ADD, m_butAdd); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CSetSoundDlg, CDialog) //{{AFX_MSG_MAP(CSetSoundDlg) ON_BN_CLICKED(IDC_BUTTON_SETSOUND_ADD, OnButtonSetsoundAdd) ON_BN_CLICKED(IDC_BUTTON_SETSOUND_CLOSE, OnButtonSetsoundClose) ON_BN_CLICKED(IDC_BUTTON_SETSOUND_DEC, OnButtonSetsoundDec) ON_WM_PAINT() ON_WM_LBUTTONDOWN() ON_WM_LBUTTONUP() ON_WM_ERASEBKGND() //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CSetSoundDlg message handlers BOOL CSetSoundDlg::OnInitDialog() { CDialog::OnInitDialog(); CenterWindow(this); // center to the hpc screen // TODO: Add extra initialization here // 设置窗口大小 MoveWindow(0,0,320,240); m_butDec.MoveWindow(12,75,48,48); m_butDec.LoadBitmaps(IDB_SETVOLUME_DECVOLUME,IDB_SETVOLUME_DECVOLUMED); m_butAdd.MoveWindow(260,75,48,48); m_butAdd.LoadBitmaps(IDB_SETVOLUME_ADDVOLUME,IDB_SETVOLUME_ADDVOLUMED); // WCHAR strRes[MAX_PATH]; // CString(LoadString(theApp.GetResourceLib(),IDS_SET_VOLUME_BEEP,strRes,MAX_PATH)); // m_butBeep.SetButtonTitle(strRes); m_butClose.MoveWindow(282,6,25,25); m_butClose.LoadBitmaps(IDB_SETVOLUME_CLOSE,IDB_SETVOLUME_CLOSED); m_prgVolume.MoveWindow(61,82,199,34); m_prgVolume.LoadBitmap(IDB_PROGRESS_VOLUME,IDB_PROGRESS_VOLUMED); m_prgVolume.SetRange(0,100); int left = GetSystemVolume(); left &= 0xFFFF; m_Volume = left / 0x28F; m_prgVolume.SetPos(100*left/0xFFFF); return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE } void CSetSoundDlg::OnButtonSetsoundAdd() { // TODO: Add your control notification handler code here m_Volume += 10; if (m_Volume > 100) { m_Volume = 100; } DWORD volume = ((0x28F * m_Volume) << 16); volume &= 0xFFFF0000; volume |= 0x28F * m_Volume; waveOutSetVolume(0,volume); m_prgVolume.SetPos(m_Volume); } void CSetSoundDlg::OnButtonSetsoundClose() { // TODO: Add your control notification handler code here EndDialog(IDOK); } void CSetSoundDlg::OnButtonSetsoundDec() { // TODO: Add your control notification handler code here m_Volume -= 10; if (m_Volume < 0) { m_Volume = 0; } DWORD volume = ((0x28F * m_Volume) << 16); volume &= 0xFFFF0000; volume |= 0x28F * m_Volume; waveOutSetVolume(0,volume); m_prgVolume.SetPos(m_Volume); } void CSetSoundDlg::OnPaint() { CPaintDC dc(this); // device context for painting // TODO: Add your message handler code here dc.BitBlt(0,0,320,240,&m_BgDC,0,0,SRCCOPY); dc.SelectObject(&m_titleFont); dc.SetBkMode(TRANSPARENT); dc.SetTextColor(RGB(255,255,255)); WCHAR strRes[MAX_PATH]; // CString(LoadString(theApp.GetResourceLib(),IDS_SET_VOLUME_TITLE,strRes,MAX_PATH)); dc.DrawText(strRes,CRect(45,4,220,32),DT_LEFT|DT_VCENTER); dc.SelectObject(&m_txtFont); dc.SetTextColor(RGB(0,0,0)); CString(LoadString(theApp.GetResourceLib(),IDS_SET_VOLUME_VOLUME,strRes,MAX_PATH)); dc.DrawText(strRes,CRect(0,115,320,133),DT_CENTER|DT_VCENTER); if (theApp.GetBeep()) { dc.BitBlt(123,146,70,50,&m_MemBeepEnDC,0,0,SRCCOPY); } else { dc.BitBlt(123,146,70,50,&m_MemBeepDisDC,0,0,SRCCOPY); } CString(LoadString(theApp.GetResourceLib(),IDS_SET_VOLUME_BEEP,strRes,MAX_PATH)); dc.DrawText(strRes,CRect(0,196,320,220),DT_CENTER|DT_VCENTER); // Do not call CDialog::OnPaint() for painting messages } void CSetSoundDlg::OnLButtonDown(UINT nFlags, CPoint point) { // TODO: Add your message handler code here and/or call default if (point.x >= 123 && point.x <= 193 && point.y >= 146 && point.y <= 216) { if (theApp.GetBeep()) { theApp.PlayMsgSound(); } CClientDC dc(this); // 设置按钮音 theApp.SetBeep(!theApp.GetBeep()); if (theApp.GetBeep()) { dc.BitBlt(123,146,70,50,&m_MemBeepEnDC,0,0,SRCCOPY); } else { dc.BitBlt(123,146,70,50,&m_MemBeepDisDC,0,0,SRCCOPY); } } CDialog::OnLButtonDown(nFlags, point); } void CSetSoundDlg::OnLButtonUp(UINT nFlags, CPoint point) { // TODO: Add your message handler code here and/or call default InvalidateRect(CRect(CPoint(123,146),CSize(70,50))); CDialog::OnLButtonUp(nFlags, point); } DWORD CSetSoundDlg::GetSystemVolume() { DWORD lVolume; if (waveOutGetVolume(0,&lVolume) == MMSYSERR_NOERROR) { return lVolume; } else { return 0; } } BOOL CSetSoundDlg::OnEraseBkgnd(CDC* pDC) { // TODO: Add your message handler code here and/or call default return FALSE; //return CDialog::OnEraseBkgnd(pDC); }