//======================================================================================== // /exit exit T-Clock 2010 // /prop show T-Clock 2010 properties // /SyncOpt SNTP options // /Sync synchronize the system clock with an NTP server // /start start the Stopwatch (open as needed) // /stop stop (pause really) the Stopwatch // /reset reset Stopwatch to 0 (stop as needed) // /lap record a (the current) lap time //================================================================================================ //---------------------------------------------//---------------+++--> T-Clock Command Line Option: void ProcessCommandLine(HWND hwndMain,const char* cmdline) //-----------------------------+++--> { int justElevated = 0; const char* p = cmdline; if(g_hwndTClockMain != hwndMain){ g_hwndTClockMain = CreateWindow("STATIC",NULL,0,0,0,0,0,HWND_MESSAGE_nowarn,0,0,0); SubclassWindow(g_hwndTClockMain, MsgOnlyProc); } while(*p != '\0') { if(*p == '/') { ++p; if(strncasecmp(p, "prop", 4) == 0) { SendMessage(hwndMain, WM_COMMAND, IDM_SHOWPROP, 0); p += 4; } else if(strncasecmp(p, "exit", 4) == 0) { SendMessage(hwndMain, MAINM_EXIT, 0, 0); p += 4; } else if(strncasecmp(p, "start", 5) == 0) { SendMessage(hwndMain, WM_COMMAND, IDM_STOPWATCH_START, 0); p += 5; } else if(strncasecmp(p, "stop", 4) == 0) { SendMessage(hwndMain, WM_COMMAND, IDM_STOPWATCH_STOP, 0); p += 4; } else if(strncasecmp(p, "reset", 5) == 0) { SendMessage(hwndMain, WM_COMMAND, IDM_STOPWATCH_RESET, 0); p += 5; } else if(strncasecmp(p, "pause", 5) == 0) { SendMessage(hwndMain, WM_COMMAND, IDM_STOPWATCH_PAUSE, 0); p += 5; } else if(strncasecmp(p, "resume", 6) == 0) { SendMessage(hwndMain, WM_COMMAND, IDM_STOPWATCH_RESUME, 0); p += 6; } else if(strncasecmp(p, "lap", 3) == 0) { SendMessage(hwndMain, WM_COMMAND, IDM_STOPWATCH_LAP, 0); p += 3; } else if(strncasecmp(p, "SyncOpt", 7) == 0) { NetTimeConfigDialog(justElevated); p += 7; } else if(strncasecmp(p, "Sync", 4) == 0) { p += 4; if(HaveSetTimePermissions()){ SyncTimeNow(); } else if(!justElevated){ if(api.ExecElevated(GetClockExe(),"/UAC /Sync",NULL) != 0){ MessageBox(0,"T-Clock must be elevated to set your system time,\nbut elevation was cancled", "Time Sync Failed", MB_OK|MB_ICONERROR); } } if(g_hwndTClockMain == hwndMain) SendMessage(hwndMain, MAINM_EXIT, 0, 0); } else if(strncmp(p, "Wc", 2) == 0) { // Win10 calendar "restore" if(p[2] == '1') // restore to previous api.SetSystemInt(HKEY_LOCAL_MACHINE, kSectionImmersiveShell, kKeyWin32Tray, 1); else // use the slow (new) one api.DelSystemValue(HKEY_LOCAL_MACHINE, kSectionImmersiveShell, kKeyWin32Tray); p += 2; } else if(strncmp(p, "UAC", 3) == 0) { justElevated = 1; p += 3; } continue; } ++p; } if(g_hwndTClockMain != hwndMain){ int timeout = 100; /**< timeout in 1/10th seconds to allow sounds up to 10 seconds before terminating */ MSG msg; msg.message = 0; while(IsPlaying() && --timeout){ while(PeekMessage(&msg,NULL,0,0,PM_REMOVE)){ if(msg.message==WM_QUIT) break; TranslateMessage(&msg); DispatchMessage(&msg); } if(msg.message==WM_QUIT) break; Sleep(100); } DestroyWindow(g_hwndTClockMain); g_hwndTClockMain = NULL; } }
//======================================================================================== // /exit exit T-Clock 2010 // /prop show T-Clock 2010 properties // /SyncOpt SNTP options // /Sync synchronize the system clock with an NTP server // /start start the Stopwatch (open as needed) // /stop stop (pause really) the Stopwatch // /reset reset Stopwatch to 0 (stop as needed) // /lap record a (the current) lap time //================================================================================================ //---------------------------------------------//---------------+++--> T-Clock Command Line Option: void ProcessCommandLine(HWND hwndMain,const char* cmdline) //-----------------------------+++--> { int justElevated = 0; const char* p = cmdline; if(g_hwndTClockMain != hwndMain){ g_hwndTClockMain = CreateWindow("STATIC",NULL,0,0,0,0,0,HWND_MESSAGE_nowarn,0,0,0); SubclassWindow(g_hwndTClockMain, MsgOnlyProc); } while(*p != '\0') { if(*p == '/') { ++p; if(strncasecmp(p, "prop", 4) == 0) { SendMessage(hwndMain, WM_COMMAND, IDM_SHOWPROP, 0); p += 4; } else if(strncasecmp(p, "exit", 4) == 0) { SendMessage(hwndMain, MAINM_EXIT, 0, 0); p += 4; } else if(strncasecmp(p, "start", 5) == 0) { SendMessage(hwndMain, WM_COMMAND, IDM_STOPWATCH_START, 0); p += 5; } else if(strncasecmp(p, "stop", 4) == 0) { SendMessage(hwndMain, WM_COMMAND, IDM_STOPWATCH_STOP, 0); p += 4; } else if(strncasecmp(p, "reset", 5) == 0) { SendMessage(hwndMain, WM_COMMAND, IDM_STOPWATCH_RESET, 0); p += 5; } else if(strncasecmp(p, "pause", 5) == 0) { SendMessage(hwndMain, WM_COMMAND, IDM_STOPWATCH_PAUSE, 0); p += 5; } else if(strncasecmp(p, "resume", 6) == 0) { SendMessage(hwndMain, WM_COMMAND, IDM_STOPWATCH_RESUME, 0); p += 6; } else if(strncasecmp(p, "lap", 3) == 0) { SendMessage(hwndMain, WM_COMMAND, IDM_STOPWATCH_LAP, 0); p += 3; } else if(strncasecmp(p, "SyncOpt", 7) == 0) { if(HaveSetTimePermissions()){ if(!SendMessage(hwndMain, WM_COMMAND, MAKEWPARAM(IDM_SNTP,1), 0)){ NetTimeConfigDialog(justElevated); } }else{ SendMessage(hwndMain, WM_COMMAND, IDM_SNTP, 0); } p += 7; } else if(strncasecmp(p, "Sync", 4) == 0) { p += 4; SendMessage(hwndMain, WM_COMMAND, MAKEWPARAM(IDM_SNTP_SYNC,justElevated), 0); if(g_hwndTClockMain == hwndMain) SendMessage(hwndMain, MAINM_EXIT, 0, 0); } else if(strncmp(p, "Wc", 2) == 0) { // Win10 calendar "restore" if(p[2] == '1') // restore to previous api.SetSystemInt(HKEY_LOCAL_MACHINE, kSectionImmersiveShell, kKeyWin32Tray, 1); else // use the slow (new) one api.DelSystemValue(HKEY_LOCAL_MACHINE, kSectionImmersiveShell, kKeyWin32Tray); p += 2; } else if(strncmp(p, "UAC", 3) == 0) { justElevated = 1; p += 3; } continue; } ++p; } if(g_hwndTClockMain != hwndMain){ const DWORD kTimeout = 10000; const DWORD kStartTicks = GetTickCount(); DWORD timeout; MSG msg; msg.message = 0; for(;;){ int have_ui = IsWindow(g_hwndSheet) || IsWindow(g_hDlgTimer) || IsWindow(g_hDlgTimerWatch) || IsWindow(g_hDlgSNTP) || IsWindow(g_hDlgStopWatch); if(have_ui) timeout = INFINITE; else if(IsPlaying()) timeout = 200; else break; MsgWaitForMultipleObjectsEx(0, NULL, timeout, QS_ALLEVENTS, MWMO_INPUTAVAILABLE); while(PeekMessage(&msg,NULL,0,0,PM_REMOVE)){ if(msg.message == WM_QUIT) break; if(!(g_hwndSheet && IsWindow(g_hwndSheet) && PropSheet_IsDialogMessage(g_hwndSheet,&msg)) && !(g_hDlgTimer && IsWindow(g_hDlgTimer) && IsDialogMessage(g_hDlgTimer,&msg)) && !(g_hDlgTimerWatch && IsWindow(g_hDlgTimerWatch) && IsDialogMessage(g_hDlgTimerWatch,&msg)) && !(g_hDlgSNTP && IsWindow(g_hDlgSNTP) && IsDialogMessage(g_hDlgSNTP,&msg)) && !(g_hDlgStopWatch && IsWindow(g_hDlgStopWatch) && IsDialogStopWatchMessage(g_hDlgStopWatch,&msg))){ TranslateMessage(&msg); DispatchMessage(&msg); } } if(msg.message == WM_QUIT) break; if(!have_ui) { DWORD elapsed = GetTickCount() - kStartTicks; if(elapsed >= kTimeout) break; } } DestroyWindow(g_hwndTClockMain); g_hwndTClockMain = NULL; } }