|
Projects > PC Alarm Project > Alarm31Dlg.cpp |
||||
|
Download PCAlarm Setup (1.12 MB) Download VC++ 7.0 Project (2.01 MB RAR Archive) PC Alarm Help
// alarm3Dlg.cpp : implementation file //
#include "stdafx.h" #include "alarm31.h" #include "alarm31Dlg.h"
#ifdef _DEBUG #define new DEBUG_NEW #endif
// Calarm31Dlg dialog
Calarm31Dlg::Calarm31Dlg(CWnd* pParent /*=NULL*/) : CDialog(Calarm31Dlg::IDD, pParent), outstrm(outstrg,200) // <- INITIALIZES THE STRING { m_hIcon = AfxGetApp()->LoadIcon(IDI_MAINICON); }
void Calarm31Dlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); }
BEGIN_MESSAGE_MAP(Calarm31Dlg, CDialog)
ON_WM_PAINT() ON_WM_QUERYDRAGICON()
//=================================================================
ON_WM_CLOSE() ON_WM_TIMER() ON_WM_KEYDOWN() ON_COMMAND(IDC_SET_BUTTON, SetAlarmTime) ON_COMMAND(IDC_CHANGE_BUTTON, ChangeAlarmTime) ON_COMMAND(IDC_SNOOZE_BUTTON, Snooze) ON_COMMAND(IDC_TESTSOUND_BUTTON, TestSound) ON_COMMAND(IDC_STOP_BUTTON, StopRing)
ON_CBN_SELCHANGE(IDC_COMBO_SOUND_SELECTION, ChangeSoundSelection)
//=================================================================
END_MESSAGE_MAP()
///////////////////////////////////////////////////////////////////////////// // Sound helpers
static void PlaySound(LPCTSTR lpszSound) { HRSRC hRes; // resource handle to wave file HGLOBAL hData; BOOL bOk = FALSE; if ((hRes = ::FindResource(AfxGetResourceHandle(), lpszSound, _T("sound"))) != NULL && (hData = ::LoadResource(AfxGetResourceHandle(), hRes)) != NULL) { // found the resource, play it bOk = sndPlaySound((LPCTSTR)::LockResource(hData), SND_MEMORY|SND_SYNC|SND_NODEFAULT); FreeResource(hData); } if (!bOk) { static BOOL bReported = FALSE; if (!bReported) { //AfxMessageBox(IDS_CANNOT_PLAY_SOUND); bReported = TRUE; // once please } } }
inline static void PlaySound(UINT nIDS) { PlaySound(MAKEINTRESOURCE(nIDS)); }
// Calarm3Dlg message handlers
BOOL Calarm31Dlg::OnInitDialog() { CDialog::OnInitDialog();
SetIcon(m_hIcon, TRUE); // Set big icon SetIcon(m_hIcon, FALSE); // Set small icon
//================================================================= // Dialog initialization:
//---------------------------------- AlarmSetBitmap.LoadBitmap(IDB_ALARMSET_BITMAP); AlarmNotSetBitmap.LoadBitmap(IDB_ALARMNOTSET_BITMAP);
BtmPct = GetDlgItem(IDC_SET_PB); CWindowDC bpwDC(BtmPct); membpDC.CreateCompatibleDC(& bpwDC); //----------------------------------
this->SetWindowText("Welcome to PCAlarm 3.1!");
pSt_Curr_Time=(CStatic *)GetDlgItem(IDC_CURR_TIME); pSt_Status=(CStatic *)GetDlgItem(IDC_STATUS_STATIC);
pRHEdit=(CEdit *)GetDlgItem(IDC_R_H_EDIT); pRMEdit=(CEdit *)GetDlgItem(IDC_R_M_EDIT);
pRHSpin=(CSpinButtonCtrl *)GetDlgItem(IDC_R_H_SPIN); pRMSpin=(CSpinButtonCtrl *)GetDlgItem(IDC_R_M_SPIN);
pRHSpin->SetRange(0,23); pRMSpin->SetRange(0,59);
pBSet=(CButton *)GetDlgItem(IDC_SET_BUTTON); pBChange=(CButton *)GetDlgItem(IDC_CHANGE_BUTTON); pBChange->EnableWindow(FALSE); pBSNOOZE=(CButton *)GetDlgItem(IDC_SNOOZE_BUTTON); pBSNOOZE->EnableWindow(FALSE); pBSTOP=(CButton *)GetDlgItem(IDC_STOP_BUTTON); pBSTOP->EnableWindow(FALSE); pBTestSound=(CButton *)GetDlgItem(IDC_TESTSOUND_BUTTON);
pCBSoundSelection=(CComboBox *)GetDlgItem(IDC_COMBO_SOUND_SELECTION);
pCBSoundSelection->AddString("Alarm Clock"); pCBSoundSelection->AddString("Chicken"); pCBSoundSelection->AddString("Cow"); pCBSoundSelection->AddString("Crow"); pCBSoundSelection->AddString("Drip"); pCBSoundSelection->AddString("Ghost"); pCBSoundSelection->AddString("Gun"); pCBSoundSelection->AddString("Laughter"); pCBSoundSelection->AddString("Mosquito"); pCBSoundSelection->AddString("Scream1"); pCBSoundSelection->AddString("Scream2"); pCBSoundSelection->AddString("Snore");
pCBSoundSelection->SetCurSel(0); sound_selection=pCBSoundSelection->GetCurSel()+101;
_SysTimer=_AlarmTimer=_RingTimer=_TestTimer=_SnoozeTimer=0;
_SysTimer=SetTimer(1,1000,NULL);
membpDC.SelectObject(& AlarmNotSetBitmap); SendMessage(WM_PAINT);
sound_selection=IDSOUND_ALARMCLOCK; total_ring_time=0;
//================================================================= return TRUE; // return TRUE unless you set the focus to a control } //================================================================= BOOL Calarm31Dlg::PreTranslateMessage(MSG * pMsg){
if(pMsg->message==WM_KEYDOWN) { //Snooze if any key is pressed: if(_RingTimer){ if(pMsg->wParam==VK_RETURN) {StopRing(); return 1;} else {Snooze(); return 1;} }
//Stop ringing if 'enter' is pressed: if(_SnoozeTimer){ if(pMsg->wParam==VK_RETURN) {StopRing(); return 1;} else return 1; } } return CDialog::PreTranslateMessage(pMsg);
} //=================================================================
void Calarm31Dlg::OnPaint() { if (IsIconic()) { CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
// Center icon in client rectangle int cxIcon = GetSystemMetrics(SM_CXICON); int cyIcon = GetSystemMetrics(SM_CYICON); CRect rect; GetClientRect(&rect); int x = (rect.Width() - cxIcon + 1) / 2; int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon dc.DrawIcon(x, y, m_hIcon); } else { CDialog::OnPaint(); } //================================================================= //SET PICTURE: CWindowDC bpwDC(BtmPct); bpwDC.BitBlt(0,0,32,32,& membpDC,0,0,SRCCOPY); //================================================================= }
// The system calls this function to obtain the cursor to display while the user drags // the minimized window. HCURSOR Calarm31Dlg::OnQueryDragIcon() { return static_cast<HCURSOR>(m_hIcon); }
//================================================================= void Calarm31Dlg::OnClose(){
if ( AfxMessageBox("If you close PCAlarm, the alarm will not sound.\n Are you sure you want to quit PCAlarm?", MB_YESNO|MB_ICONQUESTION) == IDYES ) CDialog::OnClose();
}
//------------------------------------------------------------------------------------------------------------------- //ALL TIMER EVENTS ARE HANDLED HERE: afx_msg void Calarm31Dlg::OnTimer(UINT_PTR nIDEvent){ //----------SYSTEM TIME UPDATE-------------------- if(nIDEvent==1) { current_time=CTime::GetCurrentTime();
current_hour=current_time.GetHour(); current_minute=current_time.GetMinute(); current_second=current_time.GetSecond();
outstrm.seekp(0); outstrm<<"\t";
if(current_hour<10) outstrm<<"0"<<current_hour<<":"; else outstrm<<current_hour<<":"; if(current_minute<10) outstrm<<"0"<<current_minute<<" "; else outstrm<<current_minute<<" "; if(current_second<10) outstrm<<"0"<<current_second<<ends; else outstrm<<current_second<<ends;
pSt_Curr_Time->SetWindowText(outstrg); } //----------ALARM TIME CHECK---------------------- else if(nIDEvent==2) { if(current_hour==ring_hour && current_minute==ring_minute && current_second==0) Ring(); } //----------TEST SOUND BEEP----------------------- else if(nIDEvent==3) { PlaySound(sound_selection); } //__________RING BEEP----------------------------- else if(nIDEvent==4) { PlaySound(sound_selection); FlashWindow(TRUE); total_ring_time+=200; if(total_ring_time > 3600000) StopRing(); } //----------SNOOZE SWITCH------------------------- else if(nIDEvent==5) {/*RESUME RINGIMG*/ Ring(); }
else {}
CDialog::OnTimer(nIDEvent); }; //-------------------------------------------------------------------------------------------------------------------
#include "num_prcsng.h" //------------------------------------------------------------------------------------------------------------------- afx_msg void Calarm31Dlg::SetAlarmTime(){ _AlarmTimer=SetTimer(2,1000,NULL);
membpDC.SelectObject(& AlarmSetBitmap); SendMessage(WM_PAINT);
pBSet->EnableWindow(FALSE); pBChange->EnableWindow(TRUE); pRHSpin->EnableWindow(FALSE); pRMSpin->EnableWindow(FALSE); pCBSoundSelection->EnableWindow(FALSE);
CString temp;
pRHEdit->GetWindowText(temp); ring_hour=CStringToDouble(temp);
pRMEdit->GetWindowText(temp); ring_minute=CStringToDouble(temp);
outstrm.seekp(0); if(ring_minute<10) outstrm<<" Alarm is set ("<<ring_hour<<":0"<<ring_minute<<")"<<ends; else outstrm<<" Alarm is set ("<<ring_hour<<":"<<ring_minute<<")"<<ends;
pSt_Status->SetWindowText(outstrg); this->SetWindowText(outstrg); } //------------------------------------------------------------------------------------------------------------------- afx_msg void Calarm31Dlg::ChangeAlarmTime(){ KillTimer(_AlarmTimer); _AlarmTimer=0;
membpDC.SelectObject(& AlarmNotSetBitmap); SendMessage(WM_PAINT);
pBSet->EnableWindow(TRUE); pBChange->EnableWindow(FALSE); pRHSpin->EnableWindow(TRUE); pRMSpin->EnableWindow(TRUE); pCBSoundSelection->EnableWindow(TRUE);
outstrm.seekp(0); outstrm<<"Set alarm time in the box above."<<ends;
pSt_Status->SetWindowText(outstrg); this->SetWindowText("Alarm is not set."); } //------------------------------------------------------------------------------------------------------------------- afx_msg void Calarm31Dlg::TestSound(){
if(!KillTimer(_TestTimer)){ pBTestSound->SetWindowText("--> Stop Test"); _TestTimer=SetTimer(3,200,NULL); }
else pBTestSound->SetWindowText("Sound Test -->");
} //------------------------------------------------------------------------------------------------------------------- afx_msg void Calarm31Dlg::Ring(){ this->EnableWindow();
outstrm.seekp(0); outstrm<<"Ringing..."<<ends; pSt_Status->SetWindowText(outstrg); this->SetWindowText("Alarm: Ringing...");
pBChange->EnableWindow(FALSE); pBTestSound->EnableWindow(FALSE);
pBSNOOZE->EnableWindow(TRUE); pBSTOP->EnableWindow(TRUE);
KillTimer(_SnoozeTimer); _SnoozeTimer=0; _RingTimer=SetTimer(4,200,NULL);
pBSNOOZE->SetFocus(); }
//------------------------------------------------------------------------------------------------------------------- afx_msg void Calarm31Dlg::StopRing(){ outstrm.seekp(0); if(ring_minute<10) outstrm<<" Alarm is set ("<<ring_hour<<":0"<<ring_minute<<")."<<ends; else outstrm<<" Alarm is set ("<<ring_hour<<":"<<ring_minute<<")"<<ends; pSt_Status->SetWindowText(outstrg); this->SetWindowText(outstrg);
pBChange->EnableWindow(TRUE); pBTestSound->EnableWindow(TRUE); pBSNOOZE->EnableWindow(FALSE); pBSTOP->EnableWindow(FALSE);
KillTimer(_SnoozeTimer); _SnoozeTimer=0; KillTimer(_RingTimer); _RingTimer=0;
total_ring_time=0; } //------------------------------------------------------------------------------------------------------------------- afx_msg void Calarm31Dlg::Snooze(){ outstrm.seekp(0); outstrm<<"Snoozing for 5 minutes..."<<ends; pSt_Status->SetWindowText(outstrg); this->SetWindowText("Alarm: Snoozing...");
pBTestSound->EnableWindow(TRUE); pBSNOOZE->EnableWindow(FALSE); pBSTOP->EnableWindow(TRUE);
KillTimer(_RingTimer); _RingTimer=0; _SnoozeTimer=SetTimer(5,300000,NULL);
this->pBSTOP->SetFocus(); } //------------------------------------------------------------------------------------------------------------------- afx_msg void Calarm31Dlg::ChangeSoundSelection(){ sound_selection=pCBSoundSelection->GetCurSel() + 101; }
Download PCAlarm Setup (1.12 MB) Download VC++ 7.0 Project (2.01 MB RAR Archive) PC Alarm Help
Copyright © Yuri Bulankov 2003
|
||||
|
Bugs/Comments: code@compilerabuse.com Copyright (C) 2001-2006 Yuri Bulankov. All rights reserved. |
||||