//================================================================================================ //--------------------------------------------------+++--> 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); }
/*----------------------------------------------------------------- ---------------- when the clock is right-clicked show pop-up menu -----------------------------------------------------------------*/ void OnContextMenu(HWND hWnd, int xPos, int yPos) { BOOL g_bQMAudio; BOOL g_bQMNet; BOOL g_bQMLaunch; BOOL g_bQMExitWin; BOOL g_bQMDisplay; HMENU hPopupMenu; HMENU hMenu; int item; HBITMAP shield_bmp = NULL; g_bQMAudio = api.GetInt(L"QuickyMenu", L"AudioProperties", TRUE); g_bQMNet = api.GetInt(L"QuickyMenu", L"NetworkDrives", TRUE); g_bQMLaunch = api.GetInt(L"QuickyMenu", L"QuickyMenu", TRUE); g_bQMExitWin = api.GetInt(L"QuickyMenu", L"ExitWindows", TRUE); g_bQMDisplay = api.GetInt(L"QuickyMenu", L"DisplayProperties", TRUE); hMenu = LoadMenu(g_instance, MAKEINTRESOURCE(IDR_MENU)); hPopupMenu = GetSubMenu(hMenu, 0); if(!g_bQMAudio) DeleteMenu(hPopupMenu, IDC_SOUNDAUDIO, MF_BYCOMMAND); if(!g_bQMNet) DeleteMenu(hPopupMenu, IDC_NETWORK, MF_BYCOMMAND); if(!g_bQMLaunch) DeleteMenu(hPopupMenu, IDC_QUICKYS, MF_BYCOMMAND); if(!g_bQMExitWin) DeleteMenu(hPopupMenu, IDC_EXITWIN, MF_BYCOMMAND); if(!g_bQMDisplay) DeleteMenu(hPopupMenu, IDM_DISPLAYPROP, MF_BYCOMMAND); /// simple implementation of "Undo ..." (eg. Undo Cascade windows) if(!g_undo) DeleteMenu(hPopupMenu, IDM_FWD_UNDO, MF_BYCOMMAND); /// special menu items, only shown if SHIFT or CTRL was pressed if(!((GetAsyncKeyState(VK_SHIFT)|GetAsyncKeyState(VK_CONTROL))&0x8000)){ DeleteMenu(hPopupMenu, IDS_NONE, MF_BYCOMMAND); // seperator DeleteMenu(hPopupMenu, IDM_FWD_RUNAPP, MF_BYCOMMAND); DeleteMenu(hPopupMenu, IDM_FWD_EXITEXPLORER, MF_BYCOMMAND); } /// AlarmsTimer Menu Item y/n Goes HERE!!! UpdateAlarmMenu(hPopupMenu); UpdateTimerMenu(hPopupMenu); // Get the List of Active Timers. if(g_bQMLaunch) { wchar_t key[TNY_BUFF]; int offset = 9; wchar_t name[TNY_BUFF]; int idx; MENUITEMINFO mii = { sizeof(MENUITEMINFO) }; mii.fMask = MIIM_STRING | MIIM_ID; mii.dwTypeData=name; memcpy(key, L"MenuItem-", offset*sizeof(wchar_t)); for(idx=0; idx<12; ++idx) { offset = 9 + wsprintf(key+9, FMT("%i"), idx); if(api.GetInt(L"QuickyMenu\\MenuItems",key,0)){ memcpy(key+offset, L"-Text", 6*sizeof(wchar_t)); api.GetStr(L"QuickyMenu\\MenuItems", key, name, _countof(name), L""); mii.wID = IDM_I_MENU+idx; InsertMenuItem(hPopupMenu, IDM_SHOWCALENDER, FALSE, &mii); } } if(!HaveSetTimePermissions()) { HICON shield = GetStockIcon(SIID_SHIELD, SHGSI_SMALLICON); shield_bmp = GetBitmapFromIcon(shield, -2); DestroyIcon(shield); SetMenuItemBitmaps(hPopupMenu, IDM_SNTP_SYNC, MF_BYCOMMAND, shield_bmp, NULL); } } /// http://support.microsoft.com/kb/135788 SetForegroundWindow(hWnd); item = TrackPopupMenu(hPopupMenu, (TPM_LEFTBUTTON|TPM_NONOTIFY|TPM_RETURNCMD), xPos, yPos, 0, hWnd, NULL); if(item) { if(item >= IDM_I_BEGIN_) { if(item >= IDM_I_TIMER && item < (IDM_I_TIMER+1000)){ TimerMenuItemClick(hMenu, item); }else if(item >= IDM_I_ALARM && item < (IDM_I_ALARM+1000)){ AlarmEnable(item - IDM_I_ALARM, -1); }else if(item >= IDM_I_MENU && item < (IDM_I_MENU+1000)){ wchar_t key[MAX_PATH]; int offset = 9; wchar_t szQM_Target[MAX_PATH]; wchar_t szQM_Switch[MAX_PATH]; wcscpy(key, L"MenuItem-"); offset += wsprintf(key+offset, FMT("%i"), (item-IDM_I_MENU)); wcscpy(key+offset, L"-Target"); api.GetStr(L"QuickyMenu\\MenuItems", key, szQM_Target, _countof(szQM_Target), L""); wcscpy(key+offset, L"-Switches"); api.GetStr(L"QuickyMenu\\MenuItems", key, szQM_Switch, _countof(szQM_Switch), L""); api.Exec(szQM_Target, szQM_Switch, hWnd); } } else OnTClockCommand(hWnd, item); } PostMessage(hWnd, WM_NULL, 0, 0); DestroyMenu(hMenu); // Starting Over is Simpler & Recommended if(shield_bmp) DeleteBitmap(shield_bmp); }