diff options
author | George Hazan <george.hazan@gmail.com> | 2015-08-13 22:13:41 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2015-08-13 22:13:41 +0000 |
commit | 3ec93b6744328421a82b9fd39d711eeea0d9749a (patch) | |
tree | a9c454c592bcbe60090c39320811892d14ce9b87 /plugins/AutoShutdown/src/settingsdlg.cpp | |
parent | fb24858c747011487663c030ed45635bf057bd88 (diff) |
- 64-bit compatibility;
- code cleaning
git-svn-id: http://svn.miranda-ng.org/main/trunk@14950 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/AutoShutdown/src/settingsdlg.cpp')
-rw-r--r-- | plugins/AutoShutdown/src/settingsdlg.cpp | 397 |
1 files changed, 203 insertions, 194 deletions
diff --git a/plugins/AutoShutdown/src/settingsdlg.cpp b/plugins/AutoShutdown/src/settingsdlg.cpp index fa22315402..f947eedfcd 100644 --- a/plugins/AutoShutdown/src/settingsdlg.cpp +++ b/plugins/AutoShutdown/src/settingsdlg.cpp @@ -23,30 +23,33 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. /* Menu Item */
static HANDLE hServiceMenuCommand;
+
/* Services */
static HANDLE hServiceShowDlg;
static HWND hwndSettingsDlg;
extern HINSTANCE hInst;
-const DWORD unitValues[]={1,60,60*60,60*60*24,60*60*24*7,60*60*24*31};
-const TCHAR *unitNames[]={LPGENT("Second(s)"), LPGENT("Minute(s)"), LPGENT("Hour(s)"), LPGENT("Day(s)"), LPGENT("Week(s)"), LPGENT("Month(s)")};
+const DWORD unitValues[] = { 1,60,60 * 60,60 * 60 * 24,60 * 60 * 24 * 7,60 * 60 * 24 * 31 };
+const TCHAR *unitNames[] = { LPGENT("Second(s)"), LPGENT("Minute(s)"), LPGENT("Hour(s)"), LPGENT("Day(s)"), LPGENT("Week(s)"), LPGENT("Month(s)") };
/************************* Dialog *************************************/
-static void EnableDlgItem(HWND hwndDlg,int idCtrl,BOOL fEnable)
+static void EnableDlgItem(HWND hwndDlg, int idCtrl, BOOL fEnable)
{
- hwndDlg=GetDlgItem(hwndDlg,idCtrl);
+ hwndDlg = GetDlgItem(hwndDlg, idCtrl);
if (hwndDlg != NULL && IsWindowEnabled(hwndDlg) != fEnable)
- EnableWindow(hwndDlg,fEnable);
+ EnableWindow(hwndDlg, fEnable);
}
-static BOOL CALLBACK DisplayCpuUsageProc(BYTE nCpuUsage,LPARAM lParam)
+static BOOL CALLBACK DisplayCpuUsageProc(BYTE nCpuUsage, LPARAM lParam)
{
/* dialog closed? */
- if (!IsWindow((HWND)lParam)) return FALSE; /* stop poll thread */
+ if (!IsWindow((HWND)lParam))
+ return FALSE; /* stop poll thread */
+
TCHAR str[64];
- mir_sntprintf(str,_countof(str),TranslateT("(current: %u%%)"),nCpuUsage);
- SetWindowText((HWND)lParam,str);
+ mir_sntprintf(str, _countof(str), TranslateT("(current: %u%%)"), nCpuUsage);
+ SetWindowText((HWND)lParam, str);
return TRUE;
}
@@ -56,8 +59,8 @@ static bool AnyProtoHasCaps(DWORD caps1) PROTOACCOUNT **protos;
Proto_EnumAccounts(&nProtoCount, &protos);
- for(int i=0;i<nProtoCount;++i)
- if (CallProtoService(protos[i]->szModuleName,PS_GETCAPS,(WPARAM)PFLAGNUM_1,0)&caps1)
+ for (int i = 0; i < nProtoCount; ++i)
+ if (CallProtoService(protos[i]->szModuleName, PS_GETCAPS, (WPARAM)PFLAGNUM_1, 0)&caps1)
return true; /* CALLSERVICE_NOTFOUND also handled gracefully */
return false;
}
@@ -65,230 +68,236 @@ static bool AnyProtoHasCaps(DWORD caps1) #define M_ENABLE_SUBCTLS (WM_APP+111)
#define M_UPDATE_SHUTDOWNDESC (WM_APP+112)
#define M_CHECK_DATETIME (WM_APP+113)
-static INT_PTR CALLBACK SettingsDlgProc(HWND hwndDlg,UINT msg,WPARAM wParam,LPARAM lParam)
+static INT_PTR CALLBACK SettingsDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
- switch(msg) {
+ switch (msg) {
case WM_INITDIALOG:
+ TranslateDialogDefault(hwndDlg);
{
- LCID locale;
- hwndSettingsDlg=hwndDlg;
- TranslateDialogDefault(hwndDlg);
- locale = Langpack_GetDefaultLocale();
- SendDlgItemMessage(hwndDlg,IDC_ICON_HEADER,STM_SETIMAGE,IMAGE_ICON,(LPARAM)IcoLib_GetIcon("AutoShutdown_Header"));
+ hwndSettingsDlg = hwndDlg;
+ LCID locale = Langpack_GetDefaultLocale();
+ SendDlgItemMessage(hwndDlg, IDC_ICON_HEADER, STM_SETIMAGE, IMAGE_ICON, (LPARAM)IcoLib_GetIcon("AutoShutdown_Header"));
{
HFONT hBoldFont;
LOGFONT lf;
- if (GetObject((HFONT)SendDlgItemMessage(hwndDlg,IDC_TEXT_HEADER,WM_GETFONT,0,0),sizeof(lf),&lf)) {
- lf.lfWeight=FW_BOLD;
- hBoldFont=CreateFontIndirect(&lf);
- } else hBoldFont=NULL;
- SendDlgItemMessage(hwndDlg,IDC_TEXT_HEADER,WM_SETFONT,(WPARAM)hBoldFont,FALSE);
+ if (GetObject((HFONT)SendDlgItemMessage(hwndDlg, IDC_TEXT_HEADER, WM_GETFONT, 0, 0), sizeof(lf), &lf)) {
+ lf.lfWeight = FW_BOLD;
+ hBoldFont = CreateFontIndirect(&lf);
+ }
+ else hBoldFont = NULL;
+ SendDlgItemMessage(hwndDlg, IDC_TEXT_HEADER, WM_SETFONT, (WPARAM)hBoldFont, FALSE);
}
/* read-in watcher flags */
{
- WORD watcherType=db_get_w(NULL,"AutoShutdown","WatcherFlags",SETTING_WATCHERFLAGS_DEFAULT);
- CheckRadioButton(hwndDlg,IDC_RADIO_STTIME,IDC_RADIO_STCOUNTDOWN,(watcherType&SDWTF_ST_TIME)?IDC_RADIO_STTIME:IDC_RADIO_STCOUNTDOWN);
- CheckDlgButton(hwndDlg,IDC_CHECK_SPECIFICTIME,(watcherType&SDWTF_SPECIFICTIME) != 0 ? BST_CHECKED : BST_UNCHECKED);
- CheckDlgButton(hwndDlg,IDC_CHECK_MESSAGE,(watcherType&SDWTF_MESSAGE) != 0 ? BST_CHECKED : BST_UNCHECKED);
- CheckDlgButton(hwndDlg,IDC_CHECK_FILETRANSFER,(watcherType&SDWTF_FILETRANSFER) != 0 ? BST_CHECKED : BST_UNCHECKED);
- CheckDlgButton(hwndDlg,IDC_CHECK_IDLE,(watcherType&SDWTF_IDLE) != 0 ? BST_CHECKED : BST_UNCHECKED);
- CheckDlgButton(hwndDlg,IDC_CHECK_STATUS,(watcherType&SDWTF_STATUS) != 0 ? BST_CHECKED : BST_UNCHECKED);
- CheckDlgButton(hwndDlg,IDC_CHECK_CPUUSAGE,(watcherType&SDWTF_CPUUSAGE) != 0 ? BST_CHECKED : BST_UNCHECKED);
+ WORD watcherType = db_get_w(NULL, "AutoShutdown", "WatcherFlags", SETTING_WATCHERFLAGS_DEFAULT);
+ CheckRadioButton(hwndDlg, IDC_RADIO_STTIME, IDC_RADIO_STCOUNTDOWN, (watcherType&SDWTF_ST_TIME) ? IDC_RADIO_STTIME : IDC_RADIO_STCOUNTDOWN);
+ CheckDlgButton(hwndDlg, IDC_CHECK_SPECIFICTIME, (watcherType&SDWTF_SPECIFICTIME) != 0 ? BST_CHECKED : BST_UNCHECKED);
+ CheckDlgButton(hwndDlg, IDC_CHECK_MESSAGE, (watcherType&SDWTF_MESSAGE) != 0 ? BST_CHECKED : BST_UNCHECKED);
+ CheckDlgButton(hwndDlg, IDC_CHECK_FILETRANSFER, (watcherType&SDWTF_FILETRANSFER) != 0 ? BST_CHECKED : BST_UNCHECKED);
+ CheckDlgButton(hwndDlg, IDC_CHECK_IDLE, (watcherType&SDWTF_IDLE) != 0 ? BST_CHECKED : BST_UNCHECKED);
+ CheckDlgButton(hwndDlg, IDC_CHECK_STATUS, (watcherType&SDWTF_STATUS) != 0 ? BST_CHECKED : BST_UNCHECKED);
+ CheckDlgButton(hwndDlg, IDC_CHECK_CPUUSAGE, (watcherType&SDWTF_CPUUSAGE) != 0 ? BST_CHECKED : BST_UNCHECKED);
}
/* read-in countdown val */
{
SYSTEMTIME st;
- if (!TimeStampToSystemTime((time_t)db_get_dw(NULL,"AutoShutdown","TimeStamp",SETTING_TIMESTAMP_DEFAULT),&st))
+ if (!TimeStampToSystemTime((time_t)db_get_dw(NULL, "AutoShutdown", "TimeStamp", SETTING_TIMESTAMP_DEFAULT), &st))
GetLocalTime(&st);
- DateTime_SetSystemtime(GetDlgItem(hwndDlg,IDC_TIME_TIMESTAMP),GDT_VALID,&st);
- DateTime_SetSystemtime(GetDlgItem(hwndDlg,IDC_DATE_TIMESTAMP),GDT_VALID,&st);
- SendMessage(hwndDlg,M_CHECK_DATETIME,0,0);
+ DateTime_SetSystemtime(GetDlgItem(hwndDlg, IDC_TIME_TIMESTAMP), GDT_VALID, &st);
+ DateTime_SetSystemtime(GetDlgItem(hwndDlg, IDC_DATE_TIMESTAMP), GDT_VALID, &st);
+ SendMessage(hwndDlg, M_CHECK_DATETIME, 0, 0);
}
{
- DWORD setting=db_get_dw(NULL,"AutoShutdown","Countdown",SETTING_COUNTDOWN_DEFAULT);
- if (setting<1) setting=SETTING_COUNTDOWN_DEFAULT;
- SendDlgItemMessage(hwndDlg,IDC_SPIN_COUNTDOWN,UDM_SETRANGE,0,MAKELPARAM(UD_MAXVAL,1));
- SendDlgItemMessage(hwndDlg,IDC_EDIT_COUNTDOWN,EM_SETLIMITTEXT,(WPARAM)10,0);
- SendDlgItemMessage(hwndDlg,IDC_SPIN_COUNTDOWN,UDM_SETPOS,0,MAKELPARAM(setting,0));
- SetDlgItemInt(hwndDlg,IDC_EDIT_COUNTDOWN,setting,FALSE);
+ DWORD setting = db_get_dw(NULL, "AutoShutdown", "Countdown", SETTING_COUNTDOWN_DEFAULT);
+ if (setting < 1) setting = SETTING_COUNTDOWN_DEFAULT;
+ SendDlgItemMessage(hwndDlg, IDC_SPIN_COUNTDOWN, UDM_SETRANGE, 0, MAKELPARAM(UD_MAXVAL, 1));
+ SendDlgItemMessage(hwndDlg, IDC_EDIT_COUNTDOWN, EM_SETLIMITTEXT, (WPARAM)10, 0);
+ SendDlgItemMessage(hwndDlg, IDC_SPIN_COUNTDOWN, UDM_SETPOS, 0, MAKELPARAM(setting, 0));
+ SetDlgItemInt(hwndDlg, IDC_EDIT_COUNTDOWN, setting, FALSE);
}
{
- HWND hwndCombo=GetDlgItem(hwndDlg,IDC_COMBO_COUNTDOWNUNIT);
- DWORD lastUnit=db_get_dw(NULL,"AutoShutdown","CountdownUnit",SETTING_COUNTDOWNUNIT_DEFAULT);
- SendMessage(hwndCombo,CB_SETLOCALE,(WPARAM)locale,0); /* sort order */
- SendMessage(hwndCombo,CB_INITSTORAGE,_countof(unitNames),_countof(unitNames)*16); /* approx. */
- for(int i=0;i<_countof(unitNames);++i) {
- int index=SendMessage(hwndCombo,CB_ADDSTRING,0,(LPARAM)TranslateTS(unitNames[i]));
+ HWND hwndCombo = GetDlgItem(hwndDlg, IDC_COMBO_COUNTDOWNUNIT);
+ DWORD lastUnit = db_get_dw(NULL, "AutoShutdown", "CountdownUnit", SETTING_COUNTDOWNUNIT_DEFAULT);
+ SendMessage(hwndCombo, CB_SETLOCALE, (WPARAM)locale, 0); /* sort order */
+ SendMessage(hwndCombo, CB_INITSTORAGE, _countof(unitNames), _countof(unitNames) * 16); /* approx. */
+ for (int i = 0; i < _countof(unitNames); ++i) {
+ int index = SendMessage(hwndCombo, CB_ADDSTRING, 0, (LPARAM)TranslateTS(unitNames[i]));
if (index != LB_ERR) {
- SendMessage(hwndCombo,CB_SETITEMDATA,index,(LPARAM)unitValues[i]);
- if (i==0 || unitValues[i]==lastUnit) SendMessage(hwndCombo,CB_SETCURSEL,index,0);
+ SendMessage(hwndCombo, CB_SETITEMDATA, index, (LPARAM)unitValues[i]);
+ if (i == 0 || unitValues[i] == lastUnit) SendMessage(hwndCombo, CB_SETCURSEL, index, 0);
}
}
}
{
DBVARIANT dbv;
- if (!db_get_ts(NULL,"AutoShutdown","Message",&dbv)) {
- SetDlgItemText(hwndDlg,IDC_EDIT_MESSAGE,dbv.ptszVal);
+ if (!db_get_ts(NULL, "AutoShutdown", "Message", &dbv)) {
+ SetDlgItemText(hwndDlg, IDC_EDIT_MESSAGE, dbv.ptszVal);
mir_free(dbv.ptszVal);
}
}
/* cpuusage threshold */
{
- BYTE setting=DBGetContactSettingRangedByte(NULL,"AutoShutdown","CpuUsageThreshold",SETTING_CPUUSAGETHRESHOLD_DEFAULT,1,100);
- SendDlgItemMessage(hwndDlg,IDC_SPIN_CPUUSAGE,UDM_SETRANGE,0,MAKELPARAM(100,1));
- SendDlgItemMessage(hwndDlg,IDC_EDIT_CPUUSAGE,EM_SETLIMITTEXT,(WPARAM)3,0);
- SendDlgItemMessage(hwndDlg,IDC_SPIN_CPUUSAGE,UDM_SETPOS,0,MAKELPARAM(setting,0));
- SetDlgItemInt(hwndDlg,IDC_EDIT_CPUUSAGE,setting,FALSE);
+ BYTE setting = DBGetContactSettingRangedByte(NULL, "AutoShutdown", "CpuUsageThreshold", SETTING_CPUUSAGETHRESHOLD_DEFAULT, 1, 100);
+ SendDlgItemMessage(hwndDlg, IDC_SPIN_CPUUSAGE, UDM_SETRANGE, 0, MAKELPARAM(100, 1));
+ SendDlgItemMessage(hwndDlg, IDC_EDIT_CPUUSAGE, EM_SETLIMITTEXT, (WPARAM)3, 0);
+ SendDlgItemMessage(hwndDlg, IDC_SPIN_CPUUSAGE, UDM_SETPOS, 0, MAKELPARAM(setting, 0));
+ SetDlgItemInt(hwndDlg, IDC_EDIT_CPUUSAGE, setting, FALSE);
}
/* shutdown types */
{
- HWND hwndCombo=GetDlgItem(hwndDlg,IDC_COMBO_SHUTDOWNTYPE);
- BYTE lastShutdownType=db_get_b(NULL,"AutoShutdown","ShutdownType",SETTING_SHUTDOWNTYPE_DEFAULT);
- SendMessage(hwndCombo,CB_SETLOCALE,(WPARAM)locale,0); /* sort order */
- SendMessage(hwndCombo,CB_SETEXTENDEDUI,TRUE,0);
- SendMessage(hwndCombo,CB_INITSTORAGE,SDSDT_MAX,SDSDT_MAX*32);
- for(BYTE shutdownType=1;shutdownType<=SDSDT_MAX;++shutdownType)
- if (ServiceIsTypeEnabled(shutdownType,0)) {
- TCHAR *pszText=(TCHAR*)ServiceGetTypeDescription(shutdownType,GSTDF_TCHAR); /* never fails */
- int index=SendMessage(hwndCombo,CB_ADDSTRING,0,(LPARAM)pszText);
+ HWND hwndCombo = GetDlgItem(hwndDlg, IDC_COMBO_SHUTDOWNTYPE);
+ BYTE lastShutdownType = db_get_b(NULL, "AutoShutdown", "ShutdownType", SETTING_SHUTDOWNTYPE_DEFAULT);
+ SendMessage(hwndCombo, CB_SETLOCALE, (WPARAM)locale, 0); /* sort order */
+ SendMessage(hwndCombo, CB_SETEXTENDEDUI, TRUE, 0);
+ SendMessage(hwndCombo, CB_INITSTORAGE, SDSDT_MAX, SDSDT_MAX * 32);
+ for (BYTE shutdownType = 1; shutdownType <= SDSDT_MAX; ++shutdownType)
+ if (ServiceIsTypeEnabled(shutdownType, 0)) {
+ TCHAR *pszText = (TCHAR*)ServiceGetTypeDescription(shutdownType, GSTDF_TCHAR); /* never fails */
+ int index = SendMessage(hwndCombo, CB_ADDSTRING, 0, (LPARAM)pszText);
if (index != LB_ERR) {
- SendMessage(hwndCombo,CB_SETITEMDATA,index,(LPARAM)shutdownType);
- if (shutdownType==1 || shutdownType==lastShutdownType) SendMessage(hwndCombo,CB_SETCURSEL,(WPARAM)index,0);
+ SendMessage(hwndCombo, CB_SETITEMDATA, index, (LPARAM)shutdownType);
+ if (shutdownType == 1 || shutdownType == lastShutdownType) SendMessage(hwndCombo, CB_SETCURSEL, (WPARAM)index, 0);
}
}
- SendMessage(hwndDlg,M_UPDATE_SHUTDOWNDESC,0,(LPARAM)hwndCombo);
+ SendMessage(hwndDlg, M_UPDATE_SHUTDOWNDESC, 0, (LPARAM)hwndCombo);
}
/* check if proto is installed that supports instant messages and check if a message dialog plugin is installed */
if (!AnyProtoHasCaps(PF1_IMRECV) || !ServiceExists(MS_MSG_SENDMESSAGE)) { /* no srmessage present? */
CheckDlgButton(hwndDlg, IDC_CHECK_MESSAGE, BST_UNCHECKED);
- EnableWindow(GetDlgItem(hwndDlg,IDC_CHECK_MESSAGE),FALSE);
- EnableWindow(GetDlgItem(hwndDlg,IDC_EDIT_MESSAGE),FALSE);
+ EnableWindow(GetDlgItem(hwndDlg, IDC_CHECK_MESSAGE), FALSE);
+ EnableWindow(GetDlgItem(hwndDlg, IDC_EDIT_MESSAGE), FALSE);
}
/* check if proto is installed that supports file transfers and check if a file transfer dialog is available */
if (!AnyProtoHasCaps(PF1_FILESEND) && !AnyProtoHasCaps(PF1_FILERECV)) { /* no srfile present? */
CheckDlgButton(hwndDlg, IDC_CHECK_FILETRANSFER, BST_UNCHECKED);
- EnableWindow(GetDlgItem(hwndDlg,IDC_CHECK_FILETRANSFER),FALSE);
+ EnableWindow(GetDlgItem(hwndDlg, IDC_CHECK_FILETRANSFER), FALSE);
}
/* check if cpu usage can be detected */
- if (!PollCpuUsage(DisplayCpuUsageProc,(LPARAM)GetDlgItem(hwndDlg,IDC_TEXT_CURRENTCPU),1800)) {
+ if (!PollCpuUsage(DisplayCpuUsageProc, (LPARAM)GetDlgItem(hwndDlg, IDC_TEXT_CURRENTCPU), 1800)) {
CheckDlgButton(hwndDlg, IDC_CHECK_CPUUSAGE, BST_UNCHECKED);
- EnableWindow(GetDlgItem(hwndDlg,IDC_CHECK_CPUUSAGE),FALSE);
+ EnableWindow(GetDlgItem(hwndDlg, IDC_CHECK_CPUUSAGE), FALSE);
}
- SendMessage(hwndDlg,M_ENABLE_SUBCTLS,0,0);
- Utils_RestoreWindowPositionNoSize(hwndDlg,NULL,"AutoShutdown","SettingsDlg_");
- return TRUE; /* default focus */
}
+ SendMessage(hwndDlg, M_ENABLE_SUBCTLS, 0, 0);
+ Utils_RestoreWindowPositionNoSize(hwndDlg, NULL, "AutoShutdown", "SettingsDlg_");
+ return TRUE; /* default focus */
+
case WM_DESTROY:
+ Utils_SaveWindowPosition(hwndDlg, NULL, "AutoShutdown", "SettingsDlg_");
{
- Utils_SaveWindowPosition(hwndDlg,NULL,"AutoShutdown","SettingsDlg_");
- HFONT hFont=(HFONT)SendDlgItemMessage(hwndDlg,IDC_TEXT_HEADER,WM_GETFONT,0,0);
- SendDlgItemMessage(hwndDlg,IDC_TEXT_HEADER,WM_SETFONT,0,FALSE); /* no return value */
- if (hFont != NULL) DeleteObject(hFont);
- hwndSettingsDlg=NULL;
+ HFONT hFont = (HFONT)SendDlgItemMessage(hwndDlg, IDC_TEXT_HEADER, WM_GETFONT, 0, 0);
+ SendDlgItemMessage(hwndDlg, IDC_TEXT_HEADER, WM_SETFONT, 0, FALSE); /* no return value */
+ if (hFont != NULL)
+ DeleteObject(hFont);
+ hwndSettingsDlg = NULL;
}
return TRUE;
case WM_CTLCOLORSTATIC:
- switch(GetDlgCtrlID((HWND)lParam)) {
+ switch (GetDlgCtrlID((HWND)lParam)) {
case IDC_ICON_HEADER:
- SetBkMode((HDC)wParam,TRANSPARENT);
+ SetBkMode((HDC)wParam, TRANSPARENT);
+
case IDC_RECT_HEADER:
/* need to set COLOR_WINDOW manually for Win9x */
- SetBkColor((HDC)wParam,GetSysColor(COLOR_WINDOW));
- return (BOOL)GetSysColorBrush(COLOR_WINDOW);
+ SetBkColor((HDC)wParam, GetSysColor(COLOR_WINDOW));
+ return (INT_PTR)GetSysColorBrush(COLOR_WINDOW);
+
case IDC_TEXT_HEADER:
case IDC_TEXT_HEADERDESC:
- SetBkMode((HDC)wParam,TRANSPARENT);
- return (BOOL)GetStockObject(NULL_BRUSH);
+ SetBkMode((HDC)wParam, TRANSPARENT);
+ return (INT_PTR)GetStockObject(NULL_BRUSH);
}
break;
case M_ENABLE_SUBCTLS:
{
- BOOL checked=IsDlgButtonChecked(hwndDlg,IDC_CHECK_MESSAGE) != 0;
- EnableDlgItem(hwndDlg,IDC_EDIT_MESSAGE,checked);
- checked=IsDlgButtonChecked(hwndDlg,IDC_CHECK_SPECIFICTIME) != 0;
- EnableDlgItem(hwndDlg,IDC_RADIO_STTIME,checked);
- EnableDlgItem(hwndDlg,IDC_RADIO_STCOUNTDOWN,checked);
- checked=(IsDlgButtonChecked(hwndDlg,IDC_CHECK_SPECIFICTIME) && IsDlgButtonChecked(hwndDlg,IDC_RADIO_STTIME));
- EnableDlgItem(hwndDlg,IDC_TIME_TIMESTAMP,checked);
- EnableDlgItem(hwndDlg,IDC_DATE_TIMESTAMP,checked);
- checked=(IsDlgButtonChecked(hwndDlg,IDC_CHECK_SPECIFICTIME) && IsDlgButtonChecked(hwndDlg,IDC_RADIO_STCOUNTDOWN));
- EnableDlgItem(hwndDlg,IDC_EDIT_COUNTDOWN,checked);
- EnableDlgItem(hwndDlg,IDC_SPIN_COUNTDOWN,checked);
- EnableDlgItem(hwndDlg,IDC_COMBO_COUNTDOWNUNIT,checked);
- checked=IsDlgButtonChecked(hwndDlg,IDC_CHECK_IDLE) != 0;
- EnableDlgItem(hwndDlg,IDC_URL_IDLE,checked);
- checked=IsDlgButtonChecked(hwndDlg,IDC_CHECK_CPUUSAGE) != 0;
- EnableDlgItem(hwndDlg,IDC_EDIT_CPUUSAGE,checked);
- EnableDlgItem(hwndDlg,IDC_SPIN_CPUUSAGE,checked);
- EnableDlgItem(hwndDlg,IDC_TEXT_PERCENT,checked);
- EnableDlgItem(hwndDlg,IDC_TEXT_CURRENTCPU,checked);
- checked=(IsDlgButtonChecked(hwndDlg,IDC_CHECK_SPECIFICTIME) || IsDlgButtonChecked(hwndDlg,IDC_CHECK_MESSAGE) ||
- IsDlgButtonChecked(hwndDlg,IDC_CHECK_IDLE) || IsDlgButtonChecked(hwndDlg,IDC_CHECK_STATUS) ||
- IsDlgButtonChecked(hwndDlg,IDC_CHECK_FILETRANSFER) || IsDlgButtonChecked(hwndDlg,IDC_CHECK_CPUUSAGE));
- EnableDlgItem(hwndDlg,IDOK,checked);
+ BOOL checked = IsDlgButtonChecked(hwndDlg, IDC_CHECK_MESSAGE) != 0;
+ EnableDlgItem(hwndDlg, IDC_EDIT_MESSAGE, checked);
+ checked = IsDlgButtonChecked(hwndDlg, IDC_CHECK_SPECIFICTIME) != 0;
+ EnableDlgItem(hwndDlg, IDC_RADIO_STTIME, checked);
+ EnableDlgItem(hwndDlg, IDC_RADIO_STCOUNTDOWN, checked);
+ checked = (IsDlgButtonChecked(hwndDlg, IDC_CHECK_SPECIFICTIME) && IsDlgButtonChecked(hwndDlg, IDC_RADIO_STTIME));
+ EnableDlgItem(hwndDlg, IDC_TIME_TIMESTAMP, checked);
+ EnableDlgItem(hwndDlg, IDC_DATE_TIMESTAMP, checked);
+ checked = (IsDlgButtonChecked(hwndDlg, IDC_CHECK_SPECIFICTIME) && IsDlgButtonChecked(hwndDlg, IDC_RADIO_STCOUNTDOWN));
+ EnableDlgItem(hwndDlg, IDC_EDIT_COUNTDOWN, checked);
+ EnableDlgItem(hwndDlg, IDC_SPIN_COUNTDOWN, checked);
+ EnableDlgItem(hwndDlg, IDC_COMBO_COUNTDOWNUNIT, checked);
+ checked = IsDlgButtonChecked(hwndDlg, IDC_CHECK_IDLE) != 0;
+ EnableDlgItem(hwndDlg, IDC_URL_IDLE, checked);
+ checked = IsDlgButtonChecked(hwndDlg, IDC_CHECK_CPUUSAGE) != 0;
+ EnableDlgItem(hwndDlg, IDC_EDIT_CPUUSAGE, checked);
+ EnableDlgItem(hwndDlg, IDC_SPIN_CPUUSAGE, checked);
+ EnableDlgItem(hwndDlg, IDC_TEXT_PERCENT, checked);
+ EnableDlgItem(hwndDlg, IDC_TEXT_CURRENTCPU, checked);
+ checked = (IsDlgButtonChecked(hwndDlg, IDC_CHECK_SPECIFICTIME) || IsDlgButtonChecked(hwndDlg, IDC_CHECK_MESSAGE) ||
+ IsDlgButtonChecked(hwndDlg, IDC_CHECK_IDLE) || IsDlgButtonChecked(hwndDlg, IDC_CHECK_STATUS) ||
+ IsDlgButtonChecked(hwndDlg, IDC_CHECK_FILETRANSFER) || IsDlgButtonChecked(hwndDlg, IDC_CHECK_CPUUSAGE));
+ EnableDlgItem(hwndDlg, IDOK, checked);
}
return TRUE;
+
case M_UPDATE_SHUTDOWNDESC: /* lParam=(LPARAM)(HWND)hwndCombo */
{
- BYTE shutdownType = (BYTE)SendMessage((HWND)lParam,CB_GETITEMDATA,SendMessage((HWND)lParam,CB_GETCURSEL,0,0),0);
- SetDlgItemText(hwndDlg,IDC_TEXT_SHUTDOWNTYPE,(TCHAR*)ServiceGetTypeDescription(shutdownType,GSTDF_LONGDESC|GSTDF_TCHAR));
+ BYTE shutdownType = (BYTE)SendMessage((HWND)lParam, CB_GETITEMDATA, SendMessage((HWND)lParam, CB_GETCURSEL, 0, 0), 0);
+ SetDlgItemText(hwndDlg, IDC_TEXT_SHUTDOWNTYPE, (TCHAR*)ServiceGetTypeDescription(shutdownType, GSTDF_LONGDESC | GSTDF_TCHAR));
}
return TRUE;
case WM_TIMECHANGE: /* system time changed */
- SendMessage(hwndDlg,M_CHECK_DATETIME,0,0);
+ SendMessage(hwndDlg, M_CHECK_DATETIME, 0, 0);
return TRUE;
case M_CHECK_DATETIME:
{
- SYSTEMTIME st,stBuf;
+ SYSTEMTIME st, stBuf;
time_t timestamp;
- DateTime_GetSystemtime(GetDlgItem(hwndDlg,IDC_DATE_TIMESTAMP),&stBuf);
- DateTime_GetSystemtime(GetDlgItem(hwndDlg,IDC_TIME_TIMESTAMP),&st);
- st.wDay=stBuf.wDay;
- st.wDayOfWeek=stBuf.wDayOfWeek;
- st.wMonth=stBuf.wMonth;
- st.wYear=stBuf.wYear;
+ DateTime_GetSystemtime(GetDlgItem(hwndDlg, IDC_DATE_TIMESTAMP), &stBuf);
+ DateTime_GetSystemtime(GetDlgItem(hwndDlg, IDC_TIME_TIMESTAMP), &st);
+ st.wDay = stBuf.wDay;
+ st.wDayOfWeek = stBuf.wDayOfWeek;
+ st.wMonth = stBuf.wMonth;
+ st.wYear = stBuf.wYear;
GetLocalTime(&stBuf);
- if (SystemTimeToTimeStamp(&st,×tamp)) {
+ if (SystemTimeToTimeStamp(&st, ×tamp)) {
/* set to current date if earlier */
- if (timestamp<time(NULL)) {
- st.wDay=stBuf.wDay;
- st.wDayOfWeek=stBuf.wDayOfWeek;
- st.wMonth=stBuf.wMonth;
- st.wYear=stBuf.wYear;
- if (SystemTimeToTimeStamp(&st,×tamp)) {
+ if (timestamp < time(NULL)) {
+ st.wDay = stBuf.wDay;
+ st.wDayOfWeek = stBuf.wDayOfWeek;
+ st.wMonth = stBuf.wMonth;
+ st.wYear = stBuf.wYear;
+ if (SystemTimeToTimeStamp(&st, ×tamp)) {
/* step one day up if still earlier */
- if (timestamp<time(NULL)) {
- timestamp+=24*60*60;
- TimeStampToSystemTime(timestamp,&st);
+ if (timestamp < time(NULL)) {
+ timestamp += 24 * 60 * 60;
+ TimeStampToSystemTime(timestamp, &st);
}
}
}
}
- DateTime_SetRange(GetDlgItem(hwndDlg,IDC_DATE_TIMESTAMP),GDTR_MIN,&stBuf);
- DateTime_SetRange(GetDlgItem(hwndDlg,IDC_TIME_TIMESTAMP),GDTR_MIN,&stBuf);
- DateTime_SetSystemtime(GetDlgItem(hwndDlg,IDC_DATE_TIMESTAMP),GDT_VALID,&st);
- DateTime_SetSystemtime(GetDlgItem(hwndDlg,IDC_TIME_TIMESTAMP),GDT_VALID,&st);
- return TRUE;
+ DateTime_SetRange(GetDlgItem(hwndDlg, IDC_DATE_TIMESTAMP), GDTR_MIN, &stBuf);
+ DateTime_SetRange(GetDlgItem(hwndDlg, IDC_TIME_TIMESTAMP), GDTR_MIN, &stBuf);
+ DateTime_SetSystemtime(GetDlgItem(hwndDlg, IDC_DATE_TIMESTAMP), GDT_VALID, &st);
+ DateTime_SetSystemtime(GetDlgItem(hwndDlg, IDC_TIME_TIMESTAMP), GDT_VALID, &st);
}
+ return TRUE;
+
case WM_NOTIFY:
- switch(((NMHDR*)lParam)->idFrom) {
+ switch (((NMHDR*)lParam)->idFrom) {
case IDC_TIME_TIMESTAMP:
case IDC_DATE_TIMESTAMP:
- switch(((NMHDR*)lParam)->code) {
+ switch (((NMHDR*)lParam)->code) {
case DTN_CLOSEUP:
case NM_KILLFOCUS:
- PostMessage(hwndDlg,M_CHECK_DATETIME,0,0);
+ PostMessage(hwndDlg, M_CHECK_DATETIME, 0, 0);
return TRUE;
}
}
break;
case WM_COMMAND:
- switch(LOWORD(wParam)) {
+ switch (LOWORD(wParam)) {
case IDC_CHECK_MESSAGE:
case IDC_CHECK_FILETRANSFER:
case IDC_CHECK_IDLE:
@@ -297,32 +306,32 @@ static INT_PTR CALLBACK SettingsDlgProc(HWND hwndDlg,UINT msg,WPARAM wParam,LPAR case IDC_CHECK_SPECIFICTIME:
case IDC_RADIO_STTIME:
case IDC_RADIO_STCOUNTDOWN:
- SendMessage(hwndDlg,M_ENABLE_SUBCTLS,0,0);
+ SendMessage(hwndDlg, M_ENABLE_SUBCTLS, 0, 0);
return TRUE;
case IDC_EDIT_COUNTDOWN:
- if (HIWORD(wParam)==EN_KILLFOCUS) {
- if ((int)GetDlgItemInt(hwndDlg,IDC_EDIT_COUNTDOWN,NULL,TRUE)<1) {
- SendDlgItemMessage(hwndDlg,IDC_SPIN_COUNTDOWN,UDM_SETPOS,0,MAKELPARAM(1,0));
- SetDlgItemInt(hwndDlg,IDC_EDIT_COUNTDOWN,1,FALSE);
+ if (HIWORD(wParam) == EN_KILLFOCUS) {
+ if ((int)GetDlgItemInt(hwndDlg, IDC_EDIT_COUNTDOWN, NULL, TRUE) < 1) {
+ SendDlgItemMessage(hwndDlg, IDC_SPIN_COUNTDOWN, UDM_SETPOS, 0, MAKELPARAM(1, 0));
+ SetDlgItemInt(hwndDlg, IDC_EDIT_COUNTDOWN, 1, FALSE);
}
return TRUE;
}
break;
case IDC_EDIT_CPUUSAGE:
- if (HIWORD(wParam)==EN_KILLFOCUS) {
- WORD val=(WORD)GetDlgItemInt(hwndDlg,IDC_EDIT_CPUUSAGE,NULL,FALSE);
- if (val<1) val=1;
- else if (val>100) val=100;
- SendDlgItemMessage(hwndDlg,IDC_SPIN_CPUUSAGE,UDM_SETPOS,0,MAKELPARAM(val,0));
- SetDlgItemInt(hwndDlg,IDC_EDIT_CPUUSAGE,val,FALSE);
+ if (HIWORD(wParam) == EN_KILLFOCUS) {
+ WORD val = (WORD)GetDlgItemInt(hwndDlg, IDC_EDIT_CPUUSAGE, NULL, FALSE);
+ if (val < 1) val = 1;
+ else if (val>100) val = 100;
+ SendDlgItemMessage(hwndDlg, IDC_SPIN_CPUUSAGE, UDM_SETPOS, 0, MAKELPARAM(val, 0));
+ SetDlgItemInt(hwndDlg, IDC_EDIT_CPUUSAGE, val, FALSE);
return TRUE;
}
break;
case IDC_URL_IDLE:
- {
+ {
OPENOPTIONSDIALOG ood;
ood.cbSize = sizeof(ood);
ood.pszGroup = "Status"; /* autotranslated */
@@ -333,20 +342,20 @@ static INT_PTR CALLBACK SettingsDlgProc(HWND hwndDlg,UINT msg,WPARAM wParam,LPAR }
case IDC_COMBO_SHUTDOWNTYPE:
- if (HIWORD(wParam)==CBN_SELCHANGE)
- SendMessage(hwndDlg,M_UPDATE_SHUTDOWNDESC,0,lParam);
+ if (HIWORD(wParam) == CBN_SELCHANGE)
+ SendMessage(hwndDlg, M_UPDATE_SHUTDOWNDESC, 0, lParam);
return TRUE;
case IDOK: /* save settings and start watcher */
- ShowWindow(hwndDlg,SW_HIDE);
+ ShowWindow(hwndDlg, SW_HIDE);
/* message text */
{
- HWND hwndEdit=GetDlgItem(hwndDlg,IDC_EDIT_MESSAGE);
- int len=GetWindowTextLength(hwndEdit)+1;
- TCHAR *pszText=(TCHAR*)mir_alloc(len*sizeof(TCHAR));
- if (pszText != NULL && GetWindowText(hwndEdit,pszText,len+1)) {
+ HWND hwndEdit = GetDlgItem(hwndDlg, IDC_EDIT_MESSAGE);
+ int len = GetWindowTextLength(hwndEdit) + 1;
+ TCHAR *pszText = (TCHAR*)mir_alloc(len*sizeof(TCHAR));
+ if (pszText != NULL && GetWindowText(hwndEdit, pszText, len + 1)) {
TrimString(pszText);
- db_set_ts(NULL,"AutoShutdown","Message",pszText);
+ db_set_ts(NULL, "AutoShutdown", "Message", pszText);
}
mir_free(pszText); /* does NULL check */
}
@@ -354,35 +363,38 @@ static INT_PTR CALLBACK SettingsDlgProc(HWND hwndDlg,UINT msg,WPARAM wParam,LPAR {
SYSTEMTIME st;
time_t timestamp;
- DateTime_GetSystemtime(GetDlgItem(hwndDlg,IDC_TIME_TIMESTAMP),&st); /* time gets synchronized */
- if (!SystemTimeToTimeStamp(&st,×tamp))
- timestamp=time(NULL);
- db_set_dw(NULL,"AutoShutdown","TimeStamp",(DWORD)timestamp);
+ DateTime_GetSystemtime(GetDlgItem(hwndDlg, IDC_TIME_TIMESTAMP), &st); /* time gets synchronized */
+ if (!SystemTimeToTimeStamp(&st, ×tamp))
+ timestamp = time(NULL);
+ db_set_dw(NULL, "AutoShutdown", "TimeStamp", (DWORD)timestamp);
}
/* shutdown type */
{
- int index = SendDlgItemMessage(hwndDlg,IDC_COMBO_SHUTDOWNTYPE,CB_GETCURSEL,0,0);
- if (index != LB_ERR) db_set_b(NULL,"AutoShutdown","ShutdownType",(BYTE)SendDlgItemMessage(hwndDlg,IDC_COMBO_SHUTDOWNTYPE,CB_GETITEMDATA,(WPARAM)index,0));
- index=SendDlgItemMessage(hwndDlg,IDC_COMBO_COUNTDOWNUNIT,CB_GETCURSEL,0,0);
- if (index != LB_ERR) db_set_dw(NULL,"AutoShutdown","CountdownUnit",(DWORD)SendDlgItemMessage(hwndDlg,IDC_COMBO_COUNTDOWNUNIT,CB_GETITEMDATA,(WPARAM)index,0));
- db_set_dw(NULL,"AutoShutdown","Countdown",(DWORD)GetDlgItemInt(hwndDlg,IDC_EDIT_COUNTDOWN,NULL,FALSE));
- db_set_b(NULL,"AutoShutdown","CpuUsageThreshold",(BYTE)GetDlgItemInt(hwndDlg,IDC_EDIT_CPUUSAGE,NULL,FALSE));
+ int index = SendDlgItemMessage(hwndDlg, IDC_COMBO_SHUTDOWNTYPE, CB_GETCURSEL, 0, 0);
+ if (index != LB_ERR)
+ db_set_b(NULL, "AutoShutdown", "ShutdownType", (BYTE)SendDlgItemMessage(hwndDlg, IDC_COMBO_SHUTDOWNTYPE, CB_GETITEMDATA, (WPARAM)index, 0));
+ index = SendDlgItemMessage(hwndDlg, IDC_COMBO_COUNTDOWNUNIT, CB_GETCURSEL, 0, 0);
+ if (index != LB_ERR)
+ db_set_dw(NULL, "AutoShutdown", "CountdownUnit", (DWORD)SendDlgItemMessage(hwndDlg, IDC_COMBO_COUNTDOWNUNIT, CB_GETITEMDATA, (WPARAM)index, 0));
+ db_set_dw(NULL, "AutoShutdown", "Countdown", (DWORD)GetDlgItemInt(hwndDlg, IDC_EDIT_COUNTDOWN, NULL, FALSE));
+ db_set_b(NULL, "AutoShutdown", "CpuUsageThreshold", (BYTE)GetDlgItemInt(hwndDlg, IDC_EDIT_CPUUSAGE, NULL, FALSE));
}
/* watcher type */
{
- WORD watcherType = (WORD)(IsDlgButtonChecked(hwndDlg,IDC_RADIO_STTIME)?SDWTF_ST_TIME:SDWTF_ST_COUNTDOWN);
- if (IsDlgButtonChecked(hwndDlg,IDC_CHECK_SPECIFICTIME)) watcherType|=SDWTF_SPECIFICTIME;
- if (IsDlgButtonChecked(hwndDlg,IDC_CHECK_MESSAGE)) watcherType|=SDWTF_MESSAGE;
- if (IsDlgButtonChecked(hwndDlg,IDC_CHECK_FILETRANSFER)) watcherType|=SDWTF_FILETRANSFER;
- if (IsDlgButtonChecked(hwndDlg,IDC_CHECK_IDLE)) watcherType|=SDWTF_IDLE;
- if (IsDlgButtonChecked(hwndDlg,IDC_CHECK_STATUS)) watcherType|=SDWTF_STATUS;
- if (IsDlgButtonChecked(hwndDlg,IDC_CHECK_CPUUSAGE)) watcherType|=SDWTF_CPUUSAGE;
- db_set_w(NULL,"AutoShutdown","WatcherFlags",watcherType);
- ServiceStartWatcher(0,watcherType);
+ WORD watcherType = (WORD)(IsDlgButtonChecked(hwndDlg, IDC_RADIO_STTIME) ? SDWTF_ST_TIME : SDWTF_ST_COUNTDOWN);
+ if (IsDlgButtonChecked(hwndDlg, IDC_CHECK_SPECIFICTIME)) watcherType |= SDWTF_SPECIFICTIME;
+ if (IsDlgButtonChecked(hwndDlg, IDC_CHECK_MESSAGE)) watcherType |= SDWTF_MESSAGE;
+ if (IsDlgButtonChecked(hwndDlg, IDC_CHECK_FILETRANSFER)) watcherType |= SDWTF_FILETRANSFER;
+ if (IsDlgButtonChecked(hwndDlg, IDC_CHECK_IDLE)) watcherType |= SDWTF_IDLE;
+ if (IsDlgButtonChecked(hwndDlg, IDC_CHECK_STATUS)) watcherType |= SDWTF_STATUS;
+ if (IsDlgButtonChecked(hwndDlg, IDC_CHECK_CPUUSAGE)) watcherType |= SDWTF_CPUUSAGE;
+ db_set_w(NULL, "AutoShutdown", "WatcherFlags", watcherType);
+ ServiceStartWatcher(0, watcherType);
}
DestroyWindow(hwndDlg);
return TRUE;
- /* fall through */
+ // fall through
+
case IDCANCEL: /* WM_CLOSE */
DestroyWindow(hwndDlg);
SetShutdownToolbarButton(false);
@@ -402,14 +414,14 @@ static INT_PTR ServiceShowSettingsDialog(WPARAM, LPARAM) SetForegroundWindow(hwndSettingsDlg);
return 0;
}
- return (CreateDialog(hInst, MAKEINTRESOURCE(IDD_SETTINGS), NULL, SettingsDlgProc) == NULL);
+ return CreateDialog(hInst, MAKEINTRESOURCE(IDD_SETTINGS), NULL, SettingsDlgProc) == NULL;
}
/************************* Toolbar ************************************/
static HANDLE hToolbarButton;
-int ToolbarLoaded(WPARAM,LPARAM)
+int ToolbarLoaded(WPARAM, LPARAM)
{
TTBButton ttb = { 0 };
ttb.hIconHandleUp = iconList[2].hIcolib;
@@ -426,25 +438,23 @@ int ToolbarLoaded(WPARAM,LPARAM) void SetShutdownToolbarButton(bool fActive)
{
if (hToolbarButton)
- CallService(MS_TTB_SETBUTTONSTATE, (WPARAM)hToolbarButton,fActive?TTBST_PUSHED:0);
+ CallService(MS_TTB_SETBUTTONSTATE, (WPARAM)hToolbarButton, fActive ? TTBST_PUSHED : 0);
}
/************************* Menu Item **********************************/
-static HGENMENU hMainMenuItem,hTrayMenuItem;
+static HGENMENU hMainMenuItem, hTrayMenuItem;
void SetShutdownMenuItem(bool fActive)
{
/* main menu */
CMenuItem mi;
mi.position = 2001090000;
- if (fActive)
- {
+ if (fActive) {
mi.hIcolibItem = iconList[1].hIcolib;
mi.name.t = LPGENT("Stop automatic &shutdown");
}
- else
- {
+ else {
mi.hIcolibItem = iconList[2].hIcolib;
mi.name.t = LPGENT("Automatic &shutdown...");
}
@@ -463,13 +473,13 @@ void SetShutdownMenuItem(bool fActive) hTrayMenuItem = Menu_AddTrayMenuItem(&mi);
}
-static INT_PTR MenuItemCommand(WPARAM,LPARAM)
+static INT_PTR MenuItemCommand(WPARAM, LPARAM)
{
/* toggle between StopWatcher and ShowSettingsDdialog */
- if (ServiceIsWatcherEnabled(0,0))
- ServiceStopWatcher(0,0);
+ if (ServiceIsWatcherEnabled(0, 0))
+ ServiceStopWatcher(0, 0);
else
- ServiceShowSettingsDialog(0,0);
+ ServiceShowSettingsDialog(0, 0);
return 0;
}
@@ -479,12 +489,12 @@ void InitSettingsDlg(void) {
/* Menu Item */
hServiceMenuCommand = CreateServiceFunction("AutoShutdown/MenuCommand", MenuItemCommand);
- hMainMenuItem=hTrayMenuItem=NULL;
+ hMainMenuItem = hTrayMenuItem = NULL;
SetShutdownMenuItem(false);
/* Hotkey */
AddHotkey();
/* Services */
- hwndSettingsDlg=NULL;
+ hwndSettingsDlg = NULL;
hServiceShowDlg = CreateServiceFunction(MS_AUTOSHUTDOWN_SHOWSETTINGSDIALOG, ServiceShowSettingsDialog);
}
@@ -495,4 +505,3 @@ void UninitSettingsDlg(void) /* Services */
DestroyServiceFunction(hServiceShowDlg);
}
-
|