//================================================================================================ //------------------------//------------------------+++--> free memories associated with combo box: void OnDestroy(HWND hDlg) //--------------------------------------------------------------+++--> { HWND timer_cb = GetDlgItem(hDlg, IDC_TIMERNAME); int idx; int count = ComboBox_GetCount(timer_cb); StopFile(); for(idx=0; idx<count; ++idx) { free((void*)ComboBox_GetItemData(timer_cb,idx)); } g_hDlgTimer = NULL; }
/*------------------------------------------------ clear up --------------------------------------------------*/ void OnDestroy(HWND hDlg) { g_hDlg = NULL; clear_list(m_pTimer); m_pTimer = NULL; m_nCurrent = -1; StopFile(); m_bPlaying = FALSE; }
//================================================================================================ //---------------------------------//--------------------+++--> Test -> Play/Stop Alarm Sound File: void OnTest(HWND hDlg, WORD id) //--------------------------------------------------------+++--> { char fname[MAX_PATH]; GetDlgItemText(hDlg, id - 2, fname, MAX_PATH); if(!*fname) return; if((HICON)SendDlgItemMessage(hDlg, id, BM_GETIMAGE, IMAGE_ICON, 0) == g_hIconPlay) { if(PlayFile(hDlg, fname, 0)) { SendDlgItemMessage(hDlg, id, BM_SETIMAGE, IMAGE_ICON, (LPARAM)g_hIconStop); InvalidateRect(GetDlgItem(hDlg, id), NULL, FALSE); } } else StopFile(); }
//=================================================* // ----------------------------- Loop Play as Needed //===================================================* int OnMCINotify(HWND hwnd) { if(m_bMCIPlaying) { if(m_countPlay) { mciSendString("seek myfile to start wait", NULL, 0, NULL); if(PlayMCI(hwnd, m_nTrack) == 0) { --m_countPlay; return 1; } } StopFile(); } return 0; }
LRESULT CALLBACK MsgOnlyProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { (void)wParam; (void)lParam; switch(message) { case MM_MCINOTIFY: // stop playing or repeat mci file (all but .wav, .pcb) OnMCINotify(hwnd); return 0; case MM_WOM_DONE: // stop playing wave case MAINM_STOPSOUND: StopFile(); return 0; } return 0; }
/*------------------------------------------------ test sound --------------------------------------------------*/ void OnTest(HWND hDlg) { char fname[MAX_PATH]; GetDlgItemText(hDlg, IDC_TIMERFILE, fname, MAX_PATH); if(fname[0] == 0) return; if((HICON)SendDlgItemMessage(hDlg, IDC_TIMERTEST, BM_GETIMAGE, IMAGE_ICON, 0) == g_hIconPlay) { if(PlayFile(hDlg, fname, 0)) { SendDlgItemMessage(hDlg, IDC_TIMERTEST, BM_SETIMAGE, IMAGE_ICON, (LPARAM)g_hIconStop); InvalidateRect(GetDlgItem(hDlg, IDC_TIMERTEST), NULL, FALSE); m_bPlaying = TRUE; } } else { StopFile(); m_bPlaying = FALSE; } }
//================================================================================================ //--------------------------------------------------+++--> The Main Application "Window" Procedure: LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) //--------+++--> { switch(message) { case WM_CREATE: InitAlarm(); // initialize alarms SetTimer(hwnd, IDTIMER_MAIN, 1000, NULL); InjectClockHook(hwnd); return 0; case WM_TIMER: if(wParam == IDTIMER_MAIN) OnTimerMain(hwnd); else if(wParam == IDTIMER_MOUSE) OnTimerMouse(hwnd); return 0; case WM_ENDSESSION: if(!wParam) break; /* fall through */ case WM_DESTROY: KillTimer(hwnd, IDTIMER_MAIN); if(g_hwndSheet && IsWindow(g_hwndSheet)) SendMessage(g_hwndSheet, WM_CLOSE, 0, 0); if(g_hDlgTimer && IsWindow(g_hDlgTimer)) SendMessage(g_hDlgTimer, WM_CLOSE, 0, 0); if(g_hDlgStopWatch && IsWindow(g_hDlgStopWatch)) SendMessage(g_hDlgStopWatch, WM_CLOSE, 0, 0); g_hwndSheet = g_hDlgTimer = g_hDlgStopWatch = NULL; EndAlarm(); EndAllTimers(); api.Exit(); // exit clock, remove injection if(message!=WM_ENDSESSION) PostQuitMessage(0); return 0; case WM_PAINT: { // HDC hdc; // PAINTSTRUCT ps; // hdc = BeginPaint(hwnd, &ps); // EndPaint(hwnd, &ps); return 0;} case WM_HOTKEY: // Feature Requested From eweoma at DonationCoder.com switch(wParam) { // And a Damn Fine Request it Was... :-) case HOT_WATCH: PostMessage(hwnd, WM_COMMAND, IDM_TIMEWATCH, 0); return 0; case HOT_TIMER: PostMessage(hwnd, WM_COMMAND, IDM_TIMER, 0); return 0; case HOT_STOPW: PostMessage(hwnd, WM_COMMAND, IDM_STOPWATCH, 0); return 0; case HOT_PROPR: PostMessage(hwnd, WM_COMMAND, IDM_SHOWPROP, 0); return 0; case HOT_CALEN: PostMessage(hwnd, WM_COMMAND, IDM_SHOWCALENDER, 0); return 0; case HOT_TSYNC: SyncTimeNow(); return 0; } return 0; //================================================== case MAINM_CLOCKINIT: // Messages sent/posted from TCDLL.dll g_hwndClock = (HWND)lParam; api.InjectFinalize(); // injected, now remove hook return 0; case MAINM_ERROR: // error InitError((int)lParam); SendMessage(hwnd, WM_CLOSE, 0, 0); return 0; case MAINM_EXIT: // exit SendMessage(hwnd, WM_CLOSE, 0, 0); return 0; case MAINM_BLINKOFF: // clock no longer blinks if(!g_bPlayingNonstop) StopFile(); return 0; case MM_MCINOTIFY: // stop playing or repeat mci file (all but .wav, .pcb) OnMCINotify(hwnd); return 0; case MM_WOM_DONE: // stop playing wave case MAINM_STOPSOUND: StopFile(); return 0; case WM_WININICHANGE: RefreshUs(); return 0; // inform clock about DWM color change case WM_DWMCOLORIZATIONCOLORCHANGED: api.On_DWMCOLORIZATIONCOLORCHANGED((unsigned)wParam, (BOOL)lParam); PostMessage(g_hwndClock, WM_DWMCOLORIZATIONCOLORCHANGED, wParam, lParam); return 0; // context menu case WM_COMMAND: OnTClockCommand(hwnd, LOWORD(wParam)); // menu.c return 0; case WM_LBUTTONDOWN: case WM_RBUTTONDOWN: case WM_MBUTTONDOWN: case WM_XBUTTONDOWN: if(!g_bPlayingNonstop) PostMessage(hwnd, MAINM_STOPSOUND, 0, 0); /* fall through */ case WM_LBUTTONUP: case WM_RBUTTONUP: case WM_MBUTTONUP: case WM_XBUTTONUP: OnMouseMsg(hwnd, message, wParam, lParam); // mouse.c return 0; case WM_WTSSESSION_CHANGE: switch(wParam) { case WTS_SESSION_LOCK: Sleep(500); // Eliminate user's interaction for 500 ms SendMessage(HWND_BROADCAST_nowarn, WM_SYSCOMMAND,SC_MONITORPOWER, 2); return 0; } break; default: if(message == g_WM_TaskbarCreated){ InjectClockHook(hwnd); } } return DefWindowProc(hwnd, message, wParam, lParam); }
//==============================================================================* // ---------------------------------- Dialog Procedure for Add/Edit Timers Dialog //================================================================================* INT_PTR CALLBACK DlgProcTimer(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { switch(message) { case WM_INITDIALOG: OnInit(hDlg); return TRUE; case WM_DESTROY: OnDestroy(hDlg); break; case WM_COMMAND: { WORD id = LOWORD(wParam); WORD code = HIWORD(wParam); switch(id) { case IDC_TIMERDEL: OnDel(hDlg); break; case IDOK: OnOK(hDlg); /* fall through */ case IDCANCEL: DestroyWindow(hDlg); break; case IDC_TIMERNAME: if(code==CBN_EDITCHANGE) OnTimerName(hDlg); else if(code==CBN_SELCHANGE) PostMessage(hDlg, WM_COMMAND, MAKEWPARAM(id, CBN_EDITCHANGE), lParam); break; case IDCB_STOPTIMER: OnStopTimer(hDlg); break; case IDC_TIMERSANSHO: OnSanshoAlarm(hDlg, id); break; case IDC_TIMERTEST: OnTest(hDlg, id); break; } return TRUE; } //--------------------------------------------------------------------------+++--> case WM_NOTIFY: { //========================================== BEGIN WM_NOTIFY: //----------------------------------------------------------------------------+++--> if(((NMHDR*)lParam)->code == UDN_DELTAPOS) { NMUPDOWN* lpnmud; int i; lpnmud = (NMUPDOWN*)lParam; if(lpnmud->iDelta > 0) { // User Selected the Up Arrow switch(LOWORD(wParam)) { //--+++--> on One of the Timer Controls. case IDC_TIMERSECSPIN: i = GetDlgItemInt(hDlg, IDC_TIMERSECOND, NULL, TRUE); if(i == 59) UpdateNextCtrl(hDlg, IDC_TIMERMINSPIN, IDC_TIMERMINUTE, TRUE); break; case IDC_TIMERMINSPIN: i = GetDlgItemInt(hDlg, IDC_TIMERMINUTE, NULL, TRUE); if(lpnmud->iDelta == 4) { if(i < 59) SetDlgItemInt(hDlg, IDC_TIMERMINUTE, i+1, TRUE); } if(i == 59) UpdateNextCtrl(hDlg, IDC_TIMERHORSPIN, IDC_TIMERHOUR, TRUE); break; case IDC_TIMERHORSPIN: i = GetDlgItemInt(hDlg, IDC_TIMERHOUR, NULL, TRUE); if(lpnmud->iDelta == 4) { if(i < 23) SetDlgItemInt(hDlg, IDC_TIMERHOUR, i+1, TRUE); } if(i == 23) UpdateNextCtrl(hDlg, IDC_TIMERDAYSPIN, IDC_TIMERDAYS, TRUE); break; case IDC_TIMERDAYSPIN: if(lpnmud->iDelta == 4) { i = GetDlgItemInt(hDlg, IDC_TIMERDAYS, NULL, TRUE); if(i < 7) SetDlgItemInt(hDlg, IDC_TIMERDAYS, i+1, TRUE); } break; } } else { //--+++--> User Selected the Down Arrow switch(LOWORD(wParam)) { // on One of the Timer Controls. case IDC_TIMERSECSPIN: if(lpnmud->iDelta == -4) { i = GetDlgItemInt(hDlg, IDC_TIMERSECOND, NULL, TRUE); if(i > 0) SetDlgItemInt(hDlg, IDC_TIMERSECOND, i -1, TRUE); } break; case IDC_TIMERMINSPIN: i = GetDlgItemInt(hDlg, IDC_TIMERMINUTE, NULL, TRUE); if(lpnmud->iDelta == -4) { if(i > 0) SetDlgItemInt(hDlg, IDC_TIMERMINUTE, i -1, TRUE); } if(i == 0) UpdateNextCtrl(hDlg, IDC_TIMERSECSPIN, IDC_TIMERSECOND, FALSE); break; case IDC_TIMERHORSPIN: i = GetDlgItemInt(hDlg, IDC_TIMERHOUR, NULL, TRUE); if(lpnmud->iDelta == -4) { if(i > 0) SetDlgItemInt(hDlg, IDC_TIMERHOUR, i -1, TRUE); } if(i == 0) UpdateNextCtrl(hDlg, IDC_TIMERMINSPIN, IDC_TIMERMINUTE, FALSE); break; case IDC_TIMERDAYSPIN: i = GetDlgItemInt(hDlg, IDC_TIMERDAYS, NULL, TRUE); if(i == 0) UpdateNextCtrl(hDlg, IDC_TIMERHORSPIN, IDC_TIMERHOUR, FALSE); break; } } } //----------------------------------------------------------------------------+++--> return TRUE; //=============================================== END WM_NOTIFY: } //----------------------------------------------------------------------+++--> case MM_MCINOTIFY: case MM_WOM_DONE: StopFile(); SendDlgItemMessage(hDlg, IDC_TIMERTEST, BM_SETIMAGE, IMAGE_ICON, (LPARAM)g_hIconPlay); return TRUE; } return FALSE; }
/*------------------------------------------- dialog procedure ---------------------------------------------*/ INT_PTR CALLBACK DlgProcTimer(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { switch(message) { case WM_INITDIALOG: OnInit(hDlg); return TRUE; case WM_COMMAND: { int id, code; id = LOWORD(wParam); code = HIWORD(wParam); switch(id) { case IDC_TIMERNAME: if(code == CBN_SELCHANGE) OnName(hDlg); else if(code == CBN_DROPDOWN) OnNameDropDown(hDlg); break; case IDC_TIMERADD: OnAdd(hDlg); break; case IDC_TIMERDEL: OnDelete(hDlg); break; case IDC_TIMERSANSHO: OnBrowse(hDlg); break; case IDC_TIMERTEST: OnTest(hDlg); break; case IDC_SHOWTIME: OnShowTime(hDlg); break; case IDC_SHOWWHOLE: case IDC_SHOWADD: case IDC_SHOWUSTR: OnUserStr(hDlg); break; case IDOK: OnOK(hDlg); break; case IDCANCEL: OnCancel(hDlg); break; case IDC_TIMERHELP: OnHelp(hDlg); break; } return TRUE; } // playing sound ended case MM_MCINOTIFY: case MM_WOM_DONE: if(message == MM_MCINOTIFY) OnMCINotify(hDlg, wParam, (LONG)lParam); else StopFile(); m_bPlaying = FALSE; SendDlgItemMessage(hDlg, IDC_TIMERTEST, BM_SETIMAGE, IMAGE_ICON, (LPARAM)g_hIconPlay); return TRUE; case WM_DESTROY: OnDestroy(hDlg); break; } return FALSE; }
/*------------------------------------------------ Dialog procedure --------------------------------------------------*/ BOOL CALLBACK PageAutoExecProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { switch(message) { case WM_INITDIALOG: OnInit(hDlg); return TRUE; case WM_COMMAND: { WORD id, code; id = LOWORD(wParam); code = HIWORD(wParam); switch(id) { // a combo-box to select alarm name case IDC_COMBOAUTOEXEC: if(code == CBN_SELCHANGE) OnChangeAutoExec(hDlg); else if(code == CBN_DROPDOWN) OnDropDownAutoExec(hDlg); break; // Day... case IDC_AUTOEXECHOUR: OnHour(hDlg); break; case IDC_AUTOEXECMIN: OnMin(hDlg); break; case IDC_AUTOEXECDAY: OnDay(hDlg); break; case IDC_AUTOEXEC: OnAutoExec(hDlg, id); break; // file name changed case IDC_FILEAUTOEXEC: if(code == EN_CHANGE) { OnFileChange(hDlg, id); SendPSChanged(hDlg); } break; // browse file case IDC_SANSHOAUTOEXEC: OnSanshoAutoExec(hDlg, id); OnFileChange(hDlg, (WORD)(id - 1)); SendPSChanged(hDlg); break; // checked other checkboxes case IDC_ONBOOTEXEC: SendPSChanged(hDlg); break; // delete an alarm case IDC_DELAUTOEXEC: OnDelAutoExec(hDlg); break; // test sound case IDC_TESTAUTOEXEC: OnTest(hDlg, id); break; } return TRUE; } case WM_NOTIFY: switch(((NMHDR *)lParam)->code) { case PSN_APPLY: OnApply(hDlg); break; case PSN_HELP: My2chHelp(GetParent(hDlg), 14); break; } return TRUE; case WM_DESTROY: OnDestroy(hDlg); if(bPlaying) StopFile(); bPlaying = FALSE; break; // playing sound ended case MM_MCINOTIFY: case MM_WOM_DONE: StopFile(); bPlaying = FALSE; SendDlgItemMessage(hDlg, IDC_TESTAUTOEXEC, BM_SETIMAGE, IMAGE_ICON, (LPARAM)g_hIconPlay); return TRUE; } return FALSE; }
//================================================================================================ //---------------------//--------------------------------------+++--> Shut Off the God Damn Siren!: void EndAlarm(void) //--------------------------------------------------------------------+++--> { StopFile(); TimetableClean(); }