コード例 #1
0
ファイル: PageMisc.c プロジェクト: White-Tiger/T-Clock
//================================================================================================
//-------------------------//-----------------------------+++--> Save Current Settings to Registry:
void OnApply(HWND hDlg)   //----------------------------------------------------------------+++-->
{
	wchar_t str[2];
	char bRefresh = ((unsigned)api.GetInt(L"Desktop",L"Multimon",1) != IsDlgButtonChecked(hDlg,IDCB_MULTIMON));
	
	api.SetInt(L"Calendar", L"bCustom", IsDlgButtonChecked(hDlg,IDCB_USECALENDAR));
	api.SetInt(L"Calendar", L"CloseCalendar", IsDlgButtonChecked(hDlg,IDCB_CLOSECAL));
	api.SetInt(L"Calendar", L"ShowWeekNums", IsDlgButtonChecked(hDlg,IDCB_SHOWWEEKNUMS));
	api.SetInt(L"Calendar", L"ShowDayOfYear", IsDlgButtonChecked(hDlg,IDCB_SHOW_DOY));
	api.SetInt(L"Calendar", L"CalendarTopMost", IsDlgButtonChecked(hDlg,IDCB_CALTOPMOST));
	api.SetInt(L"Calendar", L"ViewMonths", (int)SendDlgItemMessage(hDlg,IDC_CALMONTHSPIN,UDM_GETPOS32,0,0));
	api.SetInt(L"Calendar", L"ViewMonthsPast", (int)SendDlgItemMessage(hDlg,IDC_CALMONTHPASTSPIN,UDM_GETPOS32,0,0));
#	ifdef WIN2K_COMPAT
	if(api.OS == TOS_2000) {
		int value = IsDlgButtonChecked(hDlg,IDCB_TRANS2KICONS);
		SetDesktopIconTextBk(value);
		api.SetInt(L"Desktop", L"Transparent2kIconText", value);
		if(value)
			TimetableAdd(SCHEDID_WIN2K, 30, 30);
		else
			TimetableRemove(SCHEDID_WIN2K);
	}
#	endif // WIN2K_COMPAT
	api.SetInt(L"Desktop", L"MonOffOnLock", IsDlgButtonChecked(hDlg, IDCB_MONOFF_ONLOCK));
	api.SetInt(L"Desktop", L"Multimon", IsDlgButtonChecked(hDlg,IDCB_MULTIMON));
	
	str[1] = '\0';
	str[0] = '0' + (char)ComboBox_GetCurSel(GetDlgItem(hDlg,IDC_FIRSTWEEK));
	SetInternational(L"iFirstWeekOfYear", str);
	str[0] = '0' + (char)ComboBox_GetCurSel(GetDlgItem(hDlg,IDC_FIRSTDAY));
	SetInternational(L"iFirstDayOfWeek", str);
	
	if(api.OS >= TOS_XP) { // This feature requires XP+
		BOOL enabled=IsDlgButtonChecked(hDlg, IDCB_MONOFF_ONLOCK);
		if(enabled){
			RegisterSession(g_hwndTClockMain);
		} else {
			UnregisterSession(g_hwndTClockMain);
		}
	}
	if(api.OS >= TOS_WIN10){
		int old_calendar = api.GetSystemInt(HKEY_LOCAL_MACHINE, kSectionImmersiveShell, kKeyWin32Tray, 0);
		if((int)IsDlgButtonChecked(hDlg, IDC_OLDCALENDAR) != old_calendar){
			wchar_t param[5] = L"/Wc0";
			wchar_t exe[MAX_PATH];
			if(!old_calendar)
				param[3] = '1';
			if(api.ExecElevated(GetClockExe(exe), param, NULL) == 1)
				CheckDlgButton(hDlg, IDC_OLDCALENDAR, old_calendar);
		}
	}
	if(bRefresh){
		SendMessage(g_hwndClock,CLOCKM_REFRESHCLOCK,0,0);
	}
}
コード例 #2
0
ファイル: main.c プロジェクト: andrejtm/T-Clock
//========================================================================================
//	/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;
	}
}
コード例 #3
0
//================================================================================================
//-----------------------------------------------------+++--> T-Clock Menu Command Message Handler:
LRESULT OnTClockCommand(HWND hwnd, WPARAM wParam)   //----------------------------------+++-->
{
	WORD wID = LOWORD(wParam);
	switch(wID) {
	case IDM_REFRESHTCLOCK:
		RefreshUs();
		break;
		
	case IDM_SHOWPROP:
		MyPropertySheet(-1);
		break;
	case IDM_PROP_ALARM:
		MyPropertySheet(1);
		break;
		
	case IDM_EXIT:
		SendMessage(hwnd,WM_CLOSE,0,0);
		break;
		
	case IDM_SHOWCALENDER:
		ToggleCalendar(1); // 1=own calendar
		break;
		
	case IDM_DISPLAYPROP:
		if(api.OS >= TOS_VISTA)
			api.Exec(L"::{26EE0668-A00A-44D7-9371-BEB064C98683}\\1\\::{C555438B-3C23-4769-A71F-B6D3D9B6053A}", NULL, NULL);
		else
			api.Exec(L"control", L"desk.cpl, display,1", NULL);
		break;
	case IDM_VOLUMECONTROL: //-------------------------------+++--> Volume Controls
		#ifndef _WIN64
		#	define OPEN_VOLUME L"SndVol32"
		#else
		#	define OPEN_VOLUME L"SndVol"
		#endif // _WIN64
		api.Exec(OPEN_VOLUME, NULL, NULL);
		break;
		
	case IDM_AUDIOPROP: //----------------------------------+++--> Audio settings / devices
		api.Exec(L"control", L"mmsys.cpl", NULL);
		break;
		
	case IDM_RECYCLEBIN:
		api.Exec(L"::{645FF040-5081-101B-9F08-00AA002F954E}", NULL, NULL);
		break;
		
	case IDM_RECYCLEBIN_PURGE:{
		SHQUERYRBINFO info = {sizeof(info)}; // Windows seriously asks :
		SHQueryRecycleBin(NULL, &info); // "are you sure to delete all items"
		if(info.i64NumItems > 0 || api.OS == TOS_2000) // when the recycle bin is actually empty...
			SHEmptyRecycleBin(g_hwndTClockMain, NULL, 0);
		break;}
		
	case IDM_MAPDRIVE: //----------------------------------+++--> Map Network Drive
		WNetConnectionDialog(hwnd, RESOURCETYPE_DISK);
		break;
		
	case IDM_DISCONNECT: //-------------------------+++--> Disconnect Network Drive
		WNetDisconnectDialog(hwnd, RESOURCETYPE_DISK);
		break;
		
	case IDM_TOGGLE_DT: //---------------------------+++--> Show / Hide the Desktop
		ToggleDesk();
		break;
		
	case IDM_QUICKY_WINEXP: { //-----------------//--+++--> Windows Explorer Opened
		api.Exec(L"Explorer", L"/e, ::{20D04FE0-3AEA-1069-A2D8-08002B30309D}", hwnd);
		break;}
		
	case IDM_QUICKY_DOS: { // Command Prompt
		api.Exec(L"cmd", L"/f:on /t:0a", hwnd);
		break;}
		
	case IDM_QUICKY_EMPTYRB:
		SHEmptyRecycleBin(0, NULL, SHERB_NOCONFIRMATION);
		break;
		
	case IDM_SHUTDOWN:
		if(!ShutDown())
			MessageBox(0, L"Shutdown Request Failed!", L"ERROR", MB_OK|MB_ICONERROR|MB_SETFOREGROUND);
		break;
		
	case IDM_REBOOT:
		if(!ReBoot())
			MessageBox(0, L"Reboot Request Failed!", L"ERROR", MB_OK|MB_ICONERROR|MB_SETFOREGROUND);
		break;
		
	case IDM_LOGOFF:
		if(!LogOff())
			MessageBox(0, L"Logoff Request Failed!", L"ERROR", MB_OK|MB_ICONERROR|MB_SETFOREGROUND);
		break;
		
	case IDM_FWD_CASCADE: case IDM_FWD_SIDEBYSIDE: case IDM_FWD_STACKED: case IDM_FWD_SHOWDESKTOP: case IDM_FWD_MINALL: case IDM_FWD_UNDO:
		g_undo=(wID!=IDM_FWD_UNDO);
		/* fall through */
	case IDM_FWD_DATETIME: case IDM_FWD_CUSTOMNOTIFYICONS:
	case IDM_FWD_TASKMAN:
	case IDM_FWD_LOCKTASKBAR: case IDM_FWD_LOCKALLTASKBAR:
	case IDM_FWD_TASKBARPROP: case IDM_FWD_RUNAPP: case IDM_FWD_EXITEXPLORER:{
		HWND hwndTray = FindWindowA("Shell_TrayWnd", NULL);
		if(hwndTray) PostMessage(hwndTray, WM_COMMAND, wID, 0);
		break;}
	case IDM_DATETIME_EX:{
		HWND hwnd1, hwnd2;
		int wait = 40;
		api.Exec(L"timedate.cpl", L"", 0);
		while((hwnd2=FindWindowA((char*)(uintptr_t)32770,"Date and Time"))==0 && wait--) Sleep(50);
		if(hwnd2){
			SetActiveWindow(hwnd2);
			wait = 10;
			while((hwnd1=FindWindowExA(hwnd2,NULL,(char*)(uintptr_t)32770,"Date and Time"))==0 && wait--) Sleep(50);
			if(hwnd1){
				hwnd2 = GetDlgItem(hwnd1,116);
				if(hwnd2) PostMessage(hwnd2,BM_CLICK,0,0);
			}
		}
		break;}
		
	case IDM_CHIME: /// Alarms
		AlarmChimeEnable(-1);
		break;
		
	case IDM_STOPWATCH: /// Timers
		DialogStopWatch();
		break;
	case IDM_STOPWATCH_START:
	case IDM_STOPWATCH_RESUME:
		if(!IsWindow(g_hDlgStopWatch))
			DialogStopWatch();
		StopWatch_Resume(g_hDlgStopWatch);
		break;
	case IDM_STOPWATCH_STOP:
	case IDM_STOPWATCH_PAUSE:
		if(IsWindow(g_hDlgStopWatch))
			StopWatch_Pause(g_hDlgStopWatch);
		break;
	case IDM_STOPWATCH_RESET:
		if(IsWindow(g_hDlgStopWatch))
			StopWatch_Reset(g_hDlgStopWatch);
		break;
	case IDM_STOPWATCH_LAP:
		if(IsWindow(g_hDlgStopWatch))
			StopWatch_Lap(g_hDlgStopWatch,0);
		break;
	case IDM_TIMER:
		DialogTimer(0);
		break;
	case IDM_TIMEWATCH:
		WatchTimer(0); // Shelter All the Homeless Timers.
		break;
	case IDM_TIMEWATCHRESET:
		WatchTimer(1); // Shelter All the Homeless Timers.
		break;
	case IDM_SNTP:{
		short just_elevated = HIWORD(wParam);
		if(!just_elevated || HaveSetTimePermissions()) {
			ReplyMessage(1);
			NetTimeConfigDialog(0);
			return 1; // handled
		} else {
			if(IsWindow(g_hDlgSNTP))
				SendMessage(g_hDlgSNTP, WM_CLOSE, 1, 0); // close window but safe changes
		}
		return 0;}
	case IDM_SYNCTIME:
	case IDM_SNTP_SYNC:{
		short just_elevated = HIWORD(wParam);
		int can_sync = HaveSetTimePermissions();
		if(!just_elevated || can_sync) {
			ReplyMessage(1);
			if(can_sync) {
				SyncTimeNow();
			} else {
				if(api.ExecElevated(GetClockExe(),L"/UAC /Sync",NULL) != 0) {
					MessageBox(0, L"T-Clock must be elevated to set your system time,\nbut elevation was canceled", L"Time Sync Failed", MB_OK|MB_ICONERROR|MB_SETFOREGROUND);
				}
			}
			return 1; // handled
		}
		return 0;}
	default:
		#ifdef _DEBUG
		DBGOUT("%s: unknown ID: %.5i(0x%.4x) (hwnd:%p)", __FUNCTION__, wID, wID, hwnd);
		#endif // _DEBUG
		break;
	}
	return 0;
}