summaryrefslogtreecommitdiff
path: root/plugins/AutoShutdown/src
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2015-08-13 22:13:41 +0000
committerGeorge Hazan <george.hazan@gmail.com>2015-08-13 22:13:41 +0000
commit3ec93b6744328421a82b9fd39d711eeea0d9749a (patch)
treea9c454c592bcbe60090c39320811892d14ce9b87 /plugins/AutoShutdown/src
parentfb24858c747011487663c030ed45635bf057bd88 (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')
-rw-r--r--plugins/AutoShutdown/src/cpuusage.cpp181
-rw-r--r--plugins/AutoShutdown/src/frame.cpp804
-rw-r--r--plugins/AutoShutdown/src/main.cpp13
-rw-r--r--plugins/AutoShutdown/src/options.cpp79
-rw-r--r--plugins/AutoShutdown/src/settingsdlg.cpp397
-rw-r--r--plugins/AutoShutdown/src/shutdownsvc.cpp329
-rw-r--r--plugins/AutoShutdown/src/utils.cpp144
-rw-r--r--plugins/AutoShutdown/src/watcher.cpp164
8 files changed, 1055 insertions, 1056 deletions
diff --git a/plugins/AutoShutdown/src/cpuusage.cpp b/plugins/AutoShutdown/src/cpuusage.cpp
index 4e710e4e92..ba4ccd1107 100644
--- a/plugins/AutoShutdown/src/cpuusage.cpp
+++ b/plugins/AutoShutdown/src/cpuusage.cpp
@@ -25,19 +25,19 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#define Li2Double(x) ((double)((x).HighPart)*4.294967296E9+(double)((x).LowPart))
-static BOOL WinNT_PerfStatsSwitch(TCHAR *pszServiceName,BOOL fDisable)
-{
- HKEY hKeyServices,hKeyService,hKeyPerf;
- DWORD dwData,dwDataSize;
- BOOL fSwitched=FALSE;
+static BOOL WinNT_PerfStatsSwitch(TCHAR *pszServiceName, BOOL fDisable)
+{
+ HKEY hKeyServices, hKeyService, hKeyPerf;
+ DWORD dwData, dwDataSize;
+ BOOL fSwitched = FALSE;
/* Win2000+ */
- if (!RegOpenKeyEx(HKEY_LOCAL_MACHINE,_T("System\\CurrentControlSet\\Services"),0,KEY_QUERY_VALUE|KEY_SET_VALUE,&hKeyServices)) {
- if (!RegOpenKeyEx(hKeyServices,pszServiceName,0,KEY_QUERY_VALUE|KEY_SET_VALUE,&hKeyService)) {
- if (!RegOpenKeyEx(hKeyService,_T("Performance"),0,KEY_QUERY_VALUE|KEY_SET_VALUE,&hKeyPerf)) {
- dwDataSize=sizeof(DWORD);
- if (!RegQueryValueEx(hKeyPerf,_T("Disable Performance Counters"),NULL,NULL,(BYTE*)&dwData,&dwDataSize))
+ if (!RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("System\\CurrentControlSet\\Services"), 0, KEY_QUERY_VALUE | KEY_SET_VALUE, &hKeyServices)) {
+ if (!RegOpenKeyEx(hKeyServices, pszServiceName, 0, KEY_QUERY_VALUE | KEY_SET_VALUE, &hKeyService)) {
+ if (!RegOpenKeyEx(hKeyService, _T("Performance"), 0, KEY_QUERY_VALUE | KEY_SET_VALUE, &hKeyPerf)) {
+ dwDataSize = sizeof(DWORD);
+ if (!RegQueryValueEx(hKeyPerf, _T("Disable Performance Counters"), NULL, NULL, (BYTE*)&dwData, &dwDataSize))
if ((dwData != 0) != fDisable)
- fSwitched=!RegSetValueEx(hKeyPerf,_T("Disable Performance Counters"),0,REG_DWORD,(BYTE*)&fDisable,dwDataSize);
+ fSwitched = !RegSetValueEx(hKeyPerf, _T("Disable Performance Counters"), 0, REG_DWORD, (BYTE*)&fDisable, dwDataSize);
RegCloseKey(hKeyPerf);
}
RegCloseKey(hKeyService);
@@ -48,7 +48,8 @@ static BOOL WinNT_PerfStatsSwitch(TCHAR *pszServiceName,BOOL fDisable)
}
/************************* Poll Thread ********************************/
-struct CpuUsageThreadParams {
+struct CpuUsageThreadParams
+{
DWORD dwDelayMillis;
CPUUSAGEAVAILPROC pfnDataAvailProc;
LPARAM lParam;
@@ -56,18 +57,18 @@ struct CpuUsageThreadParams {
DWORD *pidThread;
};
-static BOOL CallBackAndWait(struct CpuUsageThreadParams *param,BYTE nCpuUsage)
+static BOOL CallBackAndWait(struct CpuUsageThreadParams *param, BYTE nCpuUsage)
{
if (param->hFirstEvent != NULL) {
/* return value for PollCpuUsage() */
- *param->pidThread=GetCurrentThreadId();
+ *param->pidThread = GetCurrentThreadId();
SetEvent(param->hFirstEvent);
- param->hFirstEvent=NULL;
+ param->hFirstEvent = NULL;
/* lower priority after first call */
- SetThreadPriority(GetCurrentThread(),THREAD_PRIORITY_IDLE);
+ SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_IDLE);
}
- if (!param->pfnDataAvailProc(nCpuUsage,param->lParam)) return FALSE;
- SleepEx(param->dwDelayMillis,TRUE);
+ if (!param->pfnDataAvailProc(nCpuUsage, param->lParam)) return FALSE;
+ SleepEx(param->dwDelayMillis, TRUE);
return !Miranda_Terminated();
}
@@ -75,128 +76,136 @@ static void WinNT_PollThread(void *vparam)
{
CpuUsageThreadParams *param = (CpuUsageThreadParams*)vparam;
- DWORD dwBufferSize=0,dwCount;
- BYTE *pBuffer=NULL;
- PERF_DATA_BLOCK *pPerfData=NULL;
- LONG res,lCount;
+ DWORD dwBufferSize = 0, dwCount;
+ BYTE *pBuffer = NULL;
+ PERF_DATA_BLOCK *pPerfData = NULL;
+ LONG res, lCount;
PERF_OBJECT_TYPE *pPerfObj;
- PERF_COUNTER_DEFINITION *pPerfCounter;
- PERF_INSTANCE_DEFINITION *pPerfInstance;
+ PERF_COUNTER_DEFINITION *pPerfCounter;
+ PERF_INSTANCE_DEFINITION *pPerfInstance;
PERF_COUNTER_BLOCK *pPerfCounterBlock;
- DWORD dwObjectId,dwCounterId;
- WCHAR wszValueName[11],*pwszInstanceName;
+ DWORD dwObjectId, dwCounterId;
+ WCHAR wszValueName[11], *pwszInstanceName;
BYTE nCpuUsage;
- BOOL fSwitched,fFound,fIsFirst=FALSE;
- LARGE_INTEGER liPrevCounterValue={0},liCurrentCounterValue={0},liPrevPerfTime100nSec={0};
+ BOOL fSwitched, fFound, fIsFirst = FALSE;
+ LARGE_INTEGER liPrevCounterValue = { 0 }, liCurrentCounterValue = { 0 }, liPrevPerfTime100nSec = { 0 };
/* init */
- dwObjectId=238; /*'Processor' object */
- dwCounterId=6; /* '% processor time' counter */
- pwszInstanceName=L"_Total"; /* '_Total' instance */
+ dwObjectId = 238; /*'Processor' object */
+ dwCounterId = 6; /* '% processor time' counter */
+ pwszInstanceName = L"_Total"; /* '_Total' instance */
_itot_s(dwObjectId, wszValueName, 10);
fSwitched = WinNT_PerfStatsSwitch(_T("PerfOS"), FALSE);
/* poll */
- for(;;) {
+ for (;;) {
/* retrieve data for given object */
- res=RegQueryValueExW(HKEY_PERFORMANCE_DATA,wszValueName,NULL,NULL,(BYTE*)pPerfData,&dwBufferSize);
- while(!pBuffer || res==ERROR_MORE_DATA) {
- pBuffer=(BYTE*)mir_realloc(pPerfData,dwBufferSize+=256);
+ res = RegQueryValueExW(HKEY_PERFORMANCE_DATA, wszValueName, NULL, NULL, (BYTE*)pPerfData, &dwBufferSize);
+ while (!pBuffer || res == ERROR_MORE_DATA) {
+ pBuffer = (BYTE*)mir_realloc(pPerfData, dwBufferSize += 256);
if (!pBuffer) break;
- pPerfData=(PERF_DATA_BLOCK*)pBuffer;
- res=RegQueryValueExW(HKEY_PERFORMANCE_DATA,wszValueName,NULL,NULL,pBuffer,&dwBufferSize);
+ pPerfData = (PERF_DATA_BLOCK*)pBuffer;
+ res = RegQueryValueExW(HKEY_PERFORMANCE_DATA, wszValueName, NULL, NULL, pBuffer, &dwBufferSize);
}
if (res != ERROR_SUCCESS) break;
/* find object in data */
- fFound=FALSE;
+ fFound = FALSE;
/* first object */
- pPerfObj=(PERF_OBJECT_TYPE*)((BYTE*)pPerfData+pPerfData->HeaderLength);
- for(dwCount=0;dwCount<pPerfData->NumObjectTypes;++dwCount) {
- if (pPerfObj->ObjectNameTitleIndex==dwObjectId) {
+ pPerfObj = (PERF_OBJECT_TYPE*)((BYTE*)pPerfData + pPerfData->HeaderLength);
+ for (dwCount = 0; dwCount < pPerfData->NumObjectTypes; ++dwCount) {
+ if (pPerfObj->ObjectNameTitleIndex == dwObjectId) {
/* find counter in object data */
/* first counter */
- pPerfCounter=(PERF_COUNTER_DEFINITION*)((BYTE*)pPerfObj+pPerfObj->HeaderLength);
- for(dwCount=0;dwCount<(pPerfObj->NumCounters);++dwCount) {
- if (pPerfCounter->CounterNameTitleIndex==dwCounterId) {
+ pPerfCounter = (PERF_COUNTER_DEFINITION*)((BYTE*)pPerfObj + pPerfObj->HeaderLength);
+ for (dwCount = 0; dwCount < (pPerfObj->NumCounters); ++dwCount) {
+ if (pPerfCounter->CounterNameTitleIndex == dwCounterId) {
/* find instance in counter data */
- if (pPerfObj->NumInstances==PERF_NO_INSTANCES) {
- pPerfCounterBlock=(PERF_COUNTER_BLOCK*)((BYTE*)pPerfObj+pPerfObj->DefinitionLength);
- liCurrentCounterValue=*(LARGE_INTEGER*)((BYTE*)pPerfCounterBlock+pPerfCounter->CounterOffset);
- fFound=TRUE;
+ if (pPerfObj->NumInstances == PERF_NO_INSTANCES) {
+ pPerfCounterBlock = (PERF_COUNTER_BLOCK*)((BYTE*)pPerfObj + pPerfObj->DefinitionLength);
+ liCurrentCounterValue = *(LARGE_INTEGER*)((BYTE*)pPerfCounterBlock + pPerfCounter->CounterOffset);
+ fFound = TRUE;
}
else {
/* first instance */
- pPerfInstance=(PERF_INSTANCE_DEFINITION*)((BYTE*)pPerfObj+pPerfObj->DefinitionLength);
- for(lCount=0;lCount<(pPerfObj->NumInstances);++lCount) {
- pPerfCounterBlock=(PERF_COUNTER_BLOCK*)((BYTE*)pPerfInstance+pPerfInstance->ByteLength);
- if (!mir_wstrcmpi(pwszInstanceName,(WCHAR*)((BYTE*)pPerfInstance+pPerfInstance->NameOffset))) {
- liCurrentCounterValue=*(LARGE_INTEGER*)((BYTE*)pPerfCounterBlock+pPerfCounter->CounterOffset);
- fFound=TRUE;
+ pPerfInstance = (PERF_INSTANCE_DEFINITION*)((BYTE*)pPerfObj + pPerfObj->DefinitionLength);
+ for (lCount = 0; lCount < (pPerfObj->NumInstances); ++lCount) {
+ pPerfCounterBlock = (PERF_COUNTER_BLOCK*)((BYTE*)pPerfInstance + pPerfInstance->ByteLength);
+ if (!mir_wstrcmpi(pwszInstanceName, (WCHAR*)((BYTE*)pPerfInstance + pPerfInstance->NameOffset))) {
+ liCurrentCounterValue = *(LARGE_INTEGER*)((BYTE*)pPerfCounterBlock + pPerfCounter->CounterOffset);
+ fFound = TRUE;
break;
}
/* next instance */
- pPerfInstance=(PPERF_INSTANCE_DEFINITION)((BYTE*)pPerfCounterBlock+pPerfCounterBlock->ByteLength);
- }
- }
+ pPerfInstance = (PPERF_INSTANCE_DEFINITION)((BYTE*)pPerfCounterBlock + pPerfCounterBlock->ByteLength);
+ }
+ }
break;
}
/* next counter */
- pPerfCounter=(PERF_COUNTER_DEFINITION*)((BYTE*)pPerfCounter+pPerfCounter->ByteLength);
+ pPerfCounter = (PERF_COUNTER_DEFINITION*)((BYTE*)pPerfCounter + pPerfCounter->ByteLength);
}
- break;
- }
+ break;
+ }
/* next object */
- pPerfObj=(PERF_OBJECT_TYPE*)((BYTE*)pPerfObj+pPerfObj->TotalByteLength);
+ pPerfObj = (PERF_OBJECT_TYPE*)((BYTE*)pPerfObj + pPerfObj->TotalByteLength);
}
- if (!fFound) break;
+ if (!fFound)
+ break;
/* calc val from data, we need two samplings
* counter type: PERF_100NSEC_TIMER_INV
* calc: time base=100Ns, value=100*(1-(data_diff)/(100NsTime_diff)) */
if (!fIsFirst) {
- nCpuUsage=(BYTE)((1.0-(Li2Double(liCurrentCounterValue)-Li2Double(liPrevCounterValue))/(Li2Double(pPerfData->PerfTime100nSec)-Li2Double(liPrevPerfTime100nSec)))*100.0+0.5);
- if (!CallBackAndWait(param,nCpuUsage)) break;
+ nCpuUsage = (BYTE)((1.0 - (Li2Double(liCurrentCounterValue) - Li2Double(liPrevCounterValue)) / (Li2Double(pPerfData->PerfTime100nSec) - Li2Double(liPrevPerfTime100nSec)))*100.0 + 0.5);
+ if (!CallBackAndWait(param, nCpuUsage))
+ break;
}
- else fIsFirst=FALSE;
+ else fIsFirst = FALSE;
/* store current sampling for next */
- memcpy(&liPrevCounterValue,&liCurrentCounterValue,sizeof(LARGE_INTEGER));
- memcpy(&liPrevPerfTime100nSec,&pPerfData->PerfTime100nSec,sizeof(LARGE_INTEGER));
+ memcpy(&liPrevCounterValue, &liCurrentCounterValue, sizeof(LARGE_INTEGER));
+ memcpy(&liPrevPerfTime100nSec, &pPerfData->PerfTime100nSec, sizeof(LARGE_INTEGER));
}
/* uninit */
- if (pPerfData) mir_free(pPerfData);
- if (fSwitched) WinNT_PerfStatsSwitch(_T("PerfOS"),TRUE);
+ if (pPerfData)
+ mir_free(pPerfData);
+ if (fSwitched)
+ WinNT_PerfStatsSwitch(_T("PerfOS"), TRUE);
/* return error for PollCpuUsage() if never succeeded */
- if (param->hFirstEvent != NULL) SetEvent(param->hFirstEvent);
+ if (param->hFirstEvent != NULL)
+ SetEvent(param->hFirstEvent);
mir_free(param);
-}
+}
/************************* Start Thread *******************************/
// returns poll thread id on success
-DWORD PollCpuUsage(CPUUSAGEAVAILPROC pfnDataAvailProc,LPARAM lParam,DWORD dwDelayMillis)
+DWORD PollCpuUsage(CPUUSAGEAVAILPROC pfnDataAvailProc, LPARAM lParam, DWORD dwDelayMillis)
{
- struct CpuUsageThreadParams *param;
- DWORD idThread=0;
- HANDLE hFirstEvent;
+ DWORD idThread = 0;
/* init params */
- param=(struct CpuUsageThreadParams*)mir_alloc(sizeof(struct CpuUsageThreadParams));
- if (param==NULL) return FALSE;
- param->dwDelayMillis=dwDelayMillis;
- param->pfnDataAvailProc=pfnDataAvailProc;
- param->lParam=lParam;
- param->pidThread=&idThread;
- param->hFirstEvent=hFirstEvent=CreateEvent(NULL,FALSE,FALSE,NULL);
- if (hFirstEvent==NULL) {
+ CpuUsageThreadParams *param = (struct CpuUsageThreadParams*)mir_alloc(sizeof(struct CpuUsageThreadParams));
+ if (param == NULL)
+ return FALSE;
+
+ HANDLE hFirstEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
+ if (hFirstEvent == NULL) {
mir_free(param);
- return 0;
+ return FALSE;
}
+
+ param->dwDelayMillis = dwDelayMillis;
+ param->pfnDataAvailProc = pfnDataAvailProc;
+ param->lParam = lParam;
+ param->pidThread = &idThread;
+ param->hFirstEvent = hFirstEvent;
+
/* start thread */
- if ((int)mir_forkthread(WinNT_PollThread, param) != -1)
- WaitForSingleObject(hFirstEvent,INFINITE); /* wait for first success */
+ if (mir_forkthread(WinNT_PollThread, param) != INVALID_HANDLE_VALUE)
+ WaitForSingleObject(hFirstEvent, INFINITE); /* wait for first success */
else
mir_free(param); /* thread not started */
CloseHandle(hFirstEvent);
diff --git a/plugins/AutoShutdown/src/frame.cpp b/plugins/AutoShutdown/src/frame.cpp
index fb443ccadb..5c00f93395 100644
--- a/plugins/AutoShutdown/src/frame.cpp
+++ b/plugins/AutoShutdown/src/frame.cpp
@@ -33,15 +33,16 @@ static HANDLE hHookModulesLoaded;
#define FRAMEELEMENT_BAR 1
#define FRAMEELEMENT_BKGRND 2
#define FRAMEELEMENT_TEXT 3
+
static COLORREF GetDefaultColor(BYTE id)
{
- switch(id) {
- case FRAMEELEMENT_BAR:
- return RGB(250,0,0); /* same color as used on header icon */
- case FRAMEELEMENT_BKGRND:
- return (COLORREF)db_get_dw(NULL,"CLC","BkColour",CLCDEFAULT_BKCOLOUR);
- case FRAMEELEMENT_TEXT:
- return GetSysColor(COLOR_WINDOWTEXT);
+ switch (id) {
+ case FRAMEELEMENT_BAR:
+ return RGB(250, 0, 0); /* same color as used on header icon */
+ case FRAMEELEMENT_BKGRND:
+ return (COLORREF)db_get_dw(NULL, "CLC", "BkColour", CLCDEFAULT_BKCOLOUR);
+ case FRAMEELEMENT_TEXT:
+ return GetSysColor(COLOR_WINDOWTEXT);
}
return 0; /* never happens */
}
@@ -50,22 +51,22 @@ static LOGFONT* GetDefaultFont(LOGFONT *lf)
{
NONCLIENTMETRICS ncm;
memset(&ncm, 0, sizeof(ncm));
- ncm.cbSize=sizeof(ncm);
- if (SystemParametersInfo(SPI_GETNONCLIENTMETRICS,ncm.cbSize,&ncm,0)) {
- *lf=ncm.lfStatusFont;
+ ncm.cbSize = sizeof(ncm);
+ if (SystemParametersInfo(SPI_GETNONCLIENTMETRICS, ncm.cbSize, &ncm, 0)) {
+ *lf = ncm.lfStatusFont;
return lf;
}
return (LOGFONT*)NULL;
}
-static LRESULT CALLBACK ProgressBarSubclassProc(HWND hwndProgress,UINT msg,WPARAM wParam,LPARAM lParam)
+static LRESULT CALLBACK ProgressBarSubclassProc(HWND hwndProgress, UINT msg, WPARAM wParam, LPARAM lParam)
{
- switch(msg) {
- case WM_ERASEBKGND:
- return TRUE;
- case WM_LBUTTONDOWN:
- case WM_LBUTTONDBLCLK:
- return SendMessage(GetParent(hwndProgress),msg,wParam,lParam);
+ switch (msg) {
+ case WM_ERASEBKGND:
+ return TRUE;
+ case WM_LBUTTONDOWN:
+ case WM_LBUTTONDBLCLK:
+ return SendMessage(GetParent(hwndProgress), msg, wParam, lParam);
}
return mir_callNextSubclass(hwndProgress, ProgressBarSubclassProc, msg, wParam, lParam);
}
@@ -75,12 +76,13 @@ static LRESULT CALLBACK ProgressBarSubclassProc(HWND hwndProgress,UINT msg,WPARA
#define COUNTDOWNFRAME_CLASS _T("AutoShutdownCountdown")
/* Data */
-struct CountdownFrameWndData { /* sizeof=57, max cbClsExtra=40 on Win32 */
- time_t countdown,settingLastTime;
- HANDLE hHookColorsChanged,hHookFontsChanged,hHookIconsChanged;
- HWND hwndIcon,hwndProgress,hwndDesc,hwndTime,hwndToolTip;
+struct CountdownFrameWndData
+{ /* sizeof=57, max cbClsExtra=40 on Win32 */
+ time_t countdown, settingLastTime;
+ HANDLE hHookColorsChanged, hHookFontsChanged, hHookIconsChanged;
+ HWND hwndIcon, hwndProgress, hwndDesc, hwndTime, hwndToolTip;
HBRUSH hbrBackground;
- COLORREF clrBackground,clrText;
+ COLORREF clrBackground, clrText;
HFONT hFont;
WORD fTimeFlags;
BYTE flags;
@@ -106,446 +108,418 @@ struct CountdownFrameWndData { /* sizeof=57, max cbClsExtra=40 on Win32 */
#define M_CLOSE_COUNTDOWN (WM_USER+6)
#define M_PAUSE_COUNTDOWN (WM_USER+7)
-static LRESULT CALLBACK FrameWndProc(HWND hwndFrame,UINT msg,WPARAM wParam,LPARAM lParam)
+static LRESULT CALLBACK FrameWndProc(HWND hwndFrame, UINT msg, WPARAM wParam, LPARAM lParam)
{
- struct CountdownFrameWndData *dat=(struct CountdownFrameWndData*)GetWindowLongPtr(hwndFrame, GWLP_USERDATA);
-
- switch(msg) {
- case WM_NCCREATE: /* init window data */
- dat=(struct CountdownFrameWndData*)mir_calloc(sizeof(*dat));
- SetWindowLongPtr(hwndFrame, GWLP_USERDATA, (LONG_PTR)dat);
- if (dat==NULL) return FALSE; /* creation failed */
- dat->fTimeFlags=*(WORD*)((CREATESTRUCT*)lParam)->lpCreateParams;
- dat->flags=FWPDF_COUNTDOWNINVALID;
- break;
- case WM_CREATE: /* create childs */
- { CREATESTRUCT *params=(CREATESTRUCT*)lParam;
- dat->hwndIcon=CreateWindowEx(WS_EX_NOPARENTNOTIFY,
- _T("Static"),
- NULL,
- WS_CHILD|WS_VISIBLE|SS_ICON|SS_CENTERIMAGE|SS_NOTIFY,
- 3, 0,
- GetSystemMetrics(SM_CXICON),
- GetSystemMetrics(SM_CYICON),
- hwndFrame,
- NULL,
- params->hInstance,
- NULL);
- dat->hwndProgress=CreateWindowEx(WS_EX_NOPARENTNOTIFY,
- PROGRESS_CLASS,
- (dat->fTimeFlags&SDWTF_ST_TIME)?TranslateT("Shutdown at:"):TranslateT("Time left:"),
- WS_CHILD|WS_VISIBLE|PBS_SMOOTH,
- GetSystemMetrics(SM_CXICON)+5,
- 5, 90,
- (GetSystemMetrics(SM_CXICON)/2)-5,
- hwndFrame,
- NULL,
- params->hInstance,
- NULL);
- if (dat->hwndProgress==NULL) return -1; /* creation failed, calls WM_DESTROY */
- SendMessage(dat->hwndProgress,PBM_SETSTEP,1,0);
+ CountdownFrameWndData *dat = (CountdownFrameWndData*)GetWindowLongPtr(hwndFrame, GWLP_USERDATA);
+
+ switch (msg) {
+ case WM_NCCREATE: /* init window data */
+ dat = (struct CountdownFrameWndData*)mir_calloc(sizeof(*dat));
+ SetWindowLongPtr(hwndFrame, GWLP_USERDATA, (LONG_PTR)dat);
+ if (dat == NULL) return FALSE; /* creation failed */
+ dat->fTimeFlags = *(WORD*)((CREATESTRUCT*)lParam)->lpCreateParams;
+ dat->flags = FWPDF_COUNTDOWNINVALID;
+ break;
+
+ case WM_CREATE: /* create childs */
+ {
+ CREATESTRUCT *params = (CREATESTRUCT*)lParam;
+ dat->hwndIcon = CreateWindowEx(WS_EX_NOPARENTNOTIFY, _T("Static"), NULL, WS_CHILD | WS_VISIBLE | SS_ICON | SS_CENTERIMAGE | SS_NOTIFY,
+ 3, 0, GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON), hwndFrame, NULL, params->hInstance, NULL);
+ dat->hwndProgress = CreateWindowEx(WS_EX_NOPARENTNOTIFY, PROGRESS_CLASS, (dat->fTimeFlags&SDWTF_ST_TIME) ? TranslateT("Shutdown at:") : TranslateT("Time left:"),
+ WS_CHILD | WS_VISIBLE | PBS_SMOOTH, GetSystemMetrics(SM_CXICON) + 5, 5, 90, (GetSystemMetrics(SM_CXICON) / 2) - 5, hwndFrame, NULL, params->hInstance, NULL);
+ if (dat->hwndProgress == NULL) return -1; /* creation failed, calls WM_DESTROY */
+ SendMessage(dat->hwndProgress, PBM_SETSTEP, 1, 0);
mir_subclassWindow(dat->hwndProgress, ProgressBarSubclassProc);
- dat->hwndDesc=CreateWindowEx(WS_EX_NOPARENTNOTIFY,
- _T("Static"),
- (dat->fTimeFlags&SDWTF_ST_TIME)?TranslateT("Shutdown at:"):TranslateT("Time left:"),
- WS_CHILD|WS_VISIBLE|SS_LEFTNOWORDWRAP|SS_NOTIFY,
- GetSystemMetrics(SM_CXICON)+5,
- (GetSystemMetrics(SM_CXICON)/2),
- 75,
- (GetSystemMetrics(SM_CXICON)/2),
- hwndFrame,
- NULL,
- params->hInstance,
- NULL);
- dat->hwndTime=CreateWindowEx(WS_EX_NOPARENTNOTIFY,
- _T("Static"),
- NULL, /* hh:mm:ss */
- WS_CHILD|WS_VISIBLE|SS_RIGHT|SS_NOTIFY|SS_ENDELLIPSIS,
- (GetSystemMetrics(SM_CXICON)+80),
- (GetSystemMetrics(SM_CXICON)/2),
- 35,
- (GetSystemMetrics(SM_CXICON)/2),
- hwndFrame,
- NULL,
- params->hInstance,
- NULL);
- if (dat->hwndTime==NULL) return -1; /* creation failed, calls WM_DESTROY */
- /* create tooltips */
+ dat->hwndDesc = CreateWindowEx(WS_EX_NOPARENTNOTIFY, _T("Static"), (dat->fTimeFlags&SDWTF_ST_TIME) ? TranslateT("Shutdown at:") : TranslateT("Time left:"),
+ WS_CHILD | WS_VISIBLE | SS_LEFTNOWORDWRAP | SS_NOTIFY, GetSystemMetrics(SM_CXICON) + 5, (GetSystemMetrics(SM_CXICON) / 2), 75,
+ (GetSystemMetrics(SM_CXICON) / 2), hwndFrame, NULL, params->hInstance, NULL);
+ dat->hwndTime = CreateWindowEx(WS_EX_NOPARENTNOTIFY, _T("Static"), NULL, WS_CHILD | WS_VISIBLE | SS_RIGHT | SS_NOTIFY | SS_ENDELLIPSIS,
+ (GetSystemMetrics(SM_CXICON) + 80), (GetSystemMetrics(SM_CXICON) / 2), 35, (GetSystemMetrics(SM_CXICON) / 2), hwndFrame, NULL, params->hInstance, NULL);
+ if (dat->hwndTime == NULL)
+ return -1; /* creation failed, calls WM_DESTROY */
+
+ // create tooltips
TTTOOLINFO ti;
- dat->hwndToolTip=CreateWindowEx(WS_EX_TOPMOST,
- TOOLTIPS_CLASS,
- NULL,
- WS_POPUP|TTS_ALWAYSTIP|TTS_NOPREFIX,
- CW_USEDEFAULT, CW_USEDEFAULT,
- CW_USEDEFAULT, CW_USEDEFAULT,
- hwndFrame,
- NULL,
- params->hInstance,
- NULL);
+ dat->hwndToolTip = CreateWindowEx(WS_EX_TOPMOST, TOOLTIPS_CLASS, NULL, WS_POPUP | TTS_ALWAYSTIP | TTS_NOPREFIX,
+ CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, hwndFrame, NULL, params->hInstance, NULL);
if (dat->hwndToolTip != NULL) {
- SetWindowPos(dat->hwndToolTip,HWND_TOPMOST,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE);
+ SetWindowPos(dat->hwndToolTip, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
memset(&ti, 0, sizeof(ti));
- ti.cbSize=sizeof(ti);
- ti.hwnd=hwndFrame;
- ti.uFlags=TTF_IDISHWND|TTF_SUBCLASS|TTF_TRANSPARENT;
- ti.lpszText=LPSTR_TEXTCALLBACK; /* commctl 4.70+ */
- ti.uId=(UINT)dat->hwndTime; /* in-place tooltip */
- SendMessage(dat->hwndToolTip,TTM_ADDTOOL,0,(LPARAM)&ti);
- ti.uFlags&=~TTF_TRANSPARENT;
- ti.uId=(UINT)dat->hwndProgress;
- SendMessage(dat->hwndToolTip,TTM_ADDTOOL,0,(LPARAM)&ti);
+ ti.cbSize = sizeof(ti);
+ ti.hwnd = hwndFrame;
+ ti.uFlags = TTF_IDISHWND | TTF_SUBCLASS | TTF_TRANSPARENT;
+ ti.lpszText = LPSTR_TEXTCALLBACK; /* commctl 4.70+ */
+ ti.uId = (UINT_PTR)dat->hwndTime; /* in-place tooltip */
+ SendMessage(dat->hwndToolTip, TTM_ADDTOOL, 0, (LPARAM)&ti);
+ ti.uFlags &= ~TTF_TRANSPARENT;
+ ti.uId = (UINT_PTR)dat->hwndProgress;
+ SendMessage(dat->hwndToolTip, TTM_ADDTOOL, 0, (LPARAM)&ti);
if (dat->hwndDesc != NULL) {
- ti.uId=(UINT)dat->hwndDesc;
- SendMessage(dat->hwndToolTip,TTM_ADDTOOL,0,(LPARAM)&ti);
+ ti.uId = (UINT_PTR)dat->hwndDesc;
+ SendMessage(dat->hwndToolTip, TTM_ADDTOOL, 0, (LPARAM)&ti);
}
if (dat->hwndIcon != NULL) {
- ti.uId=(UINT)dat->hwndIcon;
- SendMessage(dat->hwndToolTip,TTM_ADDTOOL,0,(LPARAM)&ti);
+ ti.uId = (UINT_PTR)dat->hwndIcon;
+ SendMessage(dat->hwndToolTip, TTM_ADDTOOL, 0, (LPARAM)&ti);
}
}
/* init layout */
- dat->hHookColorsChanged=HookEventMessage(ME_COLOUR_RELOAD,hwndFrame,M_REFRESH_COLORS);
- dat->hHookFontsChanged=HookEventMessage(ME_FONT_RELOAD,hwndFrame,M_REFRESH_FONTS);
- dat->hHookIconsChanged=HookEventMessage(ME_SKIN2_ICONSCHANGED,hwndFrame,M_REFRESH_ICONS);
- SendMessage(hwndFrame,M_REFRESH_COLORS,0,0);
- SendMessage(hwndFrame,M_REFRESH_FONTS,0,0);
- SendMessage(hwndFrame,M_REFRESH_ICONS,0,0);
- SendMessage(hwndFrame,M_SET_COUNTDOWN,0,0);
- SendMessage(hwndFrame,M_UPDATE_COUNTDOWN,0,0);
- if (!SetTimer(hwndFrame,1,1000,NULL)) return -1; /* creation failed, calls WM_DESTROY */
- return 0;
- }
- case WM_DESTROY:
- {
- if (dat==NULL) return 0;
- UnhookEvent(dat->hHookColorsChanged);
- UnhookEvent(dat->hHookFontsChanged);
- UnhookEvent(dat->hHookIconsChanged);
- /* other childs are destroyed automatically */
- if (dat->hwndToolTip != NULL) DestroyWindow(dat->hwndToolTip);
- break;
+ dat->hHookColorsChanged = HookEventMessage(ME_COLOUR_RELOAD, hwndFrame, M_REFRESH_COLORS);
+ dat->hHookFontsChanged = HookEventMessage(ME_FONT_RELOAD, hwndFrame, M_REFRESH_FONTS);
+ dat->hHookIconsChanged = HookEventMessage(ME_SKIN2_ICONSCHANGED, hwndFrame, M_REFRESH_ICONS);
+ SendMessage(hwndFrame, M_REFRESH_COLORS, 0, 0);
+ SendMessage(hwndFrame, M_REFRESH_FONTS, 0, 0);
+ SendMessage(hwndFrame, M_REFRESH_ICONS, 0, 0);
+ SendMessage(hwndFrame, M_SET_COUNTDOWN, 0, 0);
+ SendMessage(hwndFrame, M_UPDATE_COUNTDOWN, 0, 0);
+ if (!SetTimer(hwndFrame, 1, 1000, NULL))
+ return -1; /* creation failed, calls WM_DESTROY */
}
- case WM_NCDESTROY:
- if (dat==NULL) return 0;
- if (dat->hFont != NULL) DeleteObject(dat->hFont);
- if (dat->hbrBackground != NULL) DeleteObject(dat->hbrBackground);
- mir_free(dat);
- SetWindowLongPtr(hwndFrame, GWLP_USERDATA, 0);
- break;
- case WM_SIZE:
+ return 0;
+
+ case WM_DESTROY:
+ if (dat == NULL) return 0;
+
+ UnhookEvent(dat->hHookColorsChanged);
+ UnhookEvent(dat->hHookFontsChanged);
+ UnhookEvent(dat->hHookIconsChanged);
+ /* other childs are destroyed automatically */
+ if (dat->hwndToolTip != NULL)
+ DestroyWindow(dat->hwndToolTip);
+ break;
+
+ case WM_NCDESTROY:
+ if (dat == NULL) return 0;
+ if (dat->hFont != NULL) DeleteObject(dat->hFont);
+ if (dat->hbrBackground != NULL) DeleteObject(dat->hbrBackground);
+ mir_free(dat);
+ SetWindowLongPtr(hwndFrame, GWLP_USERDATA, 0);
+ break;
+
+ case WM_SIZE:
{
RECT rc;
- LONG width,height;
- UINT defflg=SWP_NOZORDER|SWP_NOOWNERZORDER|SWP_NOACTIVATE;
- SetRect(&rc,0,0,LOWORD(lParam),HIWORD(lParam)); /* width,height */
+ UINT defflg = SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_NOACTIVATE;
+ SetRect(&rc, 0, 0, LOWORD(lParam), HIWORD(lParam)); /* width,height */
/* workaround: reduce flickering of frame in clist */
- InvalidateRect(hwndFrame,&rc,FALSE);
- HDWP hdwp=BeginDeferWindowPos(3);
+ InvalidateRect(hwndFrame, &rc, FALSE);
+ HDWP hdwp = BeginDeferWindowPos(3);
/* progress */
- width=rc.right-GetSystemMetrics(SM_CXICON)-10;
- height=rc.bottom-(GetSystemMetrics(SM_CYICON)/2)-5;
+ LONG width = rc.right - GetSystemMetrics(SM_CXICON) - 10;
+ LONG height = rc.bottom - (GetSystemMetrics(SM_CYICON) / 2) - 5;
if (NULL != dat->hwndProgress) /* Wine fix. */
- hdwp=DeferWindowPos(hdwp, dat->hwndProgress, NULL, 0, 0, width, height, SWP_NOMOVE|defflg);
+ hdwp = DeferWindowPos(hdwp, dat->hwndProgress, NULL, 0, 0, width, height, SWP_NOMOVE | defflg);
/* desc */
if (dat->hwndDesc != NULL) /* Wine fix. */
- hdwp = DeferWindowPos(hdwp, dat->hwndDesc, NULL, GetSystemMetrics(SM_CXICON)+5, 5+height, 0, 0, SWP_NOSIZE|defflg);
+ hdwp = DeferWindowPos(hdwp, dat->hwndDesc, NULL, GetSystemMetrics(SM_CXICON) + 5, 5 + height, 0, 0, SWP_NOSIZE | defflg);
/* time */
if (NULL != dat->hwndTime) /* Wine fix. */
- hdwp = DeferWindowPos(hdwp, dat->hwndTime, NULL, GetSystemMetrics(SM_CXICON)+85, 5+height, width-80, (GetSystemMetrics(SM_CXICON)/2),defflg);
+ hdwp = DeferWindowPos(hdwp, dat->hwndTime, NULL, GetSystemMetrics(SM_CXICON) + 85, 5 + height, width - 80, (GetSystemMetrics(SM_CXICON) / 2), defflg);
EndDeferWindowPos(hdwp);
- PostMessage(hwndFrame,M_CHECK_CLIPPED,0,0);
- return 0;
}
- case M_REFRESH_COLORS:
- {
- COLORREF clrBar;
- if (FontService_GetColor(_T("Automatic Shutdown"),_T("Progress Bar"),&clrBar))
- clrBar=GetDefaultColor(FRAMEELEMENT_BAR);
- if (FontService_GetColor(_T("Automatic Shutdown"),_T("Background"),&dat->clrBackground))
- dat->clrBackground=GetDefaultColor(FRAMEELEMENT_BKGRND);
- if (dat->hbrBackground != NULL) DeleteObject(dat->hbrBackground);
- dat->hbrBackground=CreateSolidBrush(dat->clrBackground);
- SendMessage(dat->hwndProgress,PBM_SETBARCOLOR,0,(LPARAM)clrBar);
- SendMessage(dat->hwndProgress,PBM_SETBKCOLOR,0,(LPARAM)dat->clrBackground);
- InvalidateRect(hwndFrame,NULL,TRUE);
- return 0;
- }
- case M_REFRESH_ICONS:
- return 0;
- case M_REFRESH_FONTS:
+ PostMessage(hwndFrame, M_CHECK_CLIPPED, 0, 0);
+ return 0;
+
+ case M_REFRESH_COLORS:
+ COLORREF clrBar;
+ if (FontService_GetColor(_T("Automatic Shutdown"), _T("Progress Bar"), &clrBar))
+ clrBar = GetDefaultColor(FRAMEELEMENT_BAR);
+ if (FontService_GetColor(_T("Automatic Shutdown"), _T("Background"), &dat->clrBackground))
+ dat->clrBackground = GetDefaultColor(FRAMEELEMENT_BKGRND);
+ if (dat->hbrBackground != NULL) DeleteObject(dat->hbrBackground);
+ dat->hbrBackground = CreateSolidBrush(dat->clrBackground);
+ SendMessage(dat->hwndProgress, PBM_SETBARCOLOR, 0, (LPARAM)clrBar);
+ SendMessage(dat->hwndProgress, PBM_SETBKCOLOR, 0, (LPARAM)dat->clrBackground);
+ InvalidateRect(hwndFrame, NULL, TRUE);
+ return 0;
+
+ case M_REFRESH_ICONS:
+ return 0;
+
+ case M_REFRESH_FONTS:
{
LOGFONT lf;
- if (!FontService_GetFont(_T("Automatic Shutdown"),_T("Countdown on Frame"),&dat->clrText,&lf)) {
+ if (!FontService_GetFont(_T("Automatic Shutdown"), _T("Countdown on Frame"), &dat->clrText, &lf)) {
if (dat->hFont != NULL) DeleteObject(dat->hFont);
- dat->hFont=CreateFontIndirect(&lf);
+ dat->hFont = CreateFontIndirect(&lf);
}
else {
- dat->clrText=GetDefaultColor(FRAMEELEMENT_TEXT);
+ dat->clrText = GetDefaultColor(FRAMEELEMENT_TEXT);
if (GetDefaultFont(&lf) != NULL) {
if (dat->hFont != NULL) DeleteObject(dat->hFont);
- dat->hFont=CreateFontIndirect(&lf);
+ dat->hFont = CreateFontIndirect(&lf);
}
}
- if (dat->hwndDesc != NULL)
- SendMessage(dat->hwndDesc,WM_SETFONT,(WPARAM)dat->hFont,FALSE);
- SendMessage(dat->hwndTime,WM_SETFONT,(WPARAM)dat->hFont,FALSE);
- InvalidateRect(hwndFrame,NULL,FALSE);
- return 0;
}
- case WM_SYSCOLORCHANGE:
- SendMessage(hwndFrame,M_REFRESH_COLORS,0,0);
- break;
- case WM_SETTINGCHANGE: /* colors depend on windows settings */
- SendMessage(hwndFrame,M_REFRESH_COLORS,0,0);
- SendMessage(hwndFrame,M_REFRESH_FONTS,0,0);
- SendMessage(hwndFrame,M_UPDATE_COUNTDOWN,0,0);
- RedrawWindow(hwndFrame,NULL,NULL,RDW_INVALIDATE|RDW_ALLCHILDREN|RDW_ERASE);
- break;
- case WM_TIMECHANGE: /* windows system clock changed */
- SendMessage(hwndFrame,M_SET_COUNTDOWN,0,0);
- PostMessage(hwndFrame,M_UPDATE_COUNTDOWN,0,0);
- break;
- case WM_CTLCOLORDLG:
- case WM_CTLCOLORSTATIC:
- SetTextColor((HDC)wParam,dat->clrText);
- SetBkColor((HDC)wParam,dat->clrBackground);
- return (BOOL)dat->hbrBackground;
- case WM_ERASEBKGND:
- { RECT rc;
- if (dat->hbrBackground != NULL && GetClientRect(hwndFrame,&rc)) {
- FillRect((HDC)wParam,&rc,dat->hbrBackground);
+ if (dat->hwndDesc != NULL)
+ SendMessage(dat->hwndDesc, WM_SETFONT, (WPARAM)dat->hFont, FALSE);
+ SendMessage(dat->hwndTime, WM_SETFONT, (WPARAM)dat->hFont, FALSE);
+ InvalidateRect(hwndFrame, NULL, FALSE);
+ return 0;
+
+ case WM_SYSCOLORCHANGE:
+ SendMessage(hwndFrame, M_REFRESH_COLORS, 0, 0);
+ break;
+
+ case WM_SETTINGCHANGE: /* colors depend on windows settings */
+ SendMessage(hwndFrame, M_REFRESH_COLORS, 0, 0);
+ SendMessage(hwndFrame, M_REFRESH_FONTS, 0, 0);
+ SendMessage(hwndFrame, M_UPDATE_COUNTDOWN, 0, 0);
+ RedrawWindow(hwndFrame, NULL, NULL, RDW_INVALIDATE | RDW_ALLCHILDREN | RDW_ERASE);
+ break;
+
+ case WM_TIMECHANGE: /* windows system clock changed */
+ SendMessage(hwndFrame, M_SET_COUNTDOWN, 0, 0);
+ PostMessage(hwndFrame, M_UPDATE_COUNTDOWN, 0, 0);
+ break;
+
+ case WM_CTLCOLORDLG:
+ case WM_CTLCOLORSTATIC:
+ SetTextColor((HDC)wParam, dat->clrText);
+ SetBkColor((HDC)wParam, dat->clrBackground);
+ return (INT_PTR)dat->hbrBackground;
+
+ case WM_ERASEBKGND:
+ {
+ RECT rc;
+ if (dat->hbrBackground != NULL && GetClientRect(hwndFrame, &rc)) {
+ FillRect((HDC)wParam, &rc, dat->hbrBackground);
return TRUE;
}
return FALSE;
}
- case M_SET_COUNTDOWN:
- if (dat->fTimeFlags&SDWTF_ST_TIME) {
- dat->settingLastTime=(time_t)db_get_dw(NULL,"AutoShutdown","TimeStamp",SETTING_TIMESTAMP_DEFAULT);
- dat->countdown=time(NULL);
- if (dat->settingLastTime>dat->countdown) dat->countdown=dat->settingLastTime-dat->countdown;
- else dat->countdown=0;
- }
- else if (dat->flags&FWPDF_COUNTDOWNINVALID) {
- dat->countdown=(time_t)db_get_dw(NULL,"AutoShutdown","Countdown",SETTING_COUNTDOWN_DEFAULT);
- dat->countdown*=(time_t)db_get_dw(NULL,"AutoShutdown","CountdownUnit",SETTING_COUNTDOWNUNIT_DEFAULT);
- }
- dat->flags&=~FWPDF_COUNTDOWNINVALID;
- /* commctl 4.70+, Win95: 1-100 will work fine (wrap around) */
- SendMessage(dat->hwndProgress,PBM_SETRANGE32,0,(LPARAM)dat->countdown);
- return 0;
- case WM_TIMER:
- if (dat==NULL) return 0;
- if (dat->countdown != 0 && !(dat->flags&FWPDF_COUNTDOWNINVALID) && !(dat->flags&FWPDF_PAUSED)) {
- dat->countdown--;
- PostMessage(dat->hwndProgress,PBM_STEPIT,0,0);
- }
- if (IsWindowVisible(hwndFrame)) PostMessage(hwndFrame,M_UPDATE_COUNTDOWN,0,0);
- if (dat->countdown==0) {
- SendMessage(hwndFrame,M_CLOSE_COUNTDOWN,0,0);
- ServiceShutdown(0,TRUE);
- ServiceStopWatcher(0,0);
- }
- return 0;
- case WM_SHOWWINDOW:
- /* the text is kept unchanged while hidden */
- if ((BOOL)wParam) SendMessage(hwndFrame,M_UPDATE_COUNTDOWN,0,0);
- break;
- case M_UPDATE_COUNTDOWN:
- if (dat->flags&FWPDF_PAUSED && !(dat->flags&FWPDF_PAUSEDSHOWN)) {
- SetWindowText(dat->hwndTime,TranslateT("Paused"));
- dat->flags|=FWPDF_PAUSEDSHOWN;
- }
- else {
- TCHAR szOutput[256];
- if (dat->fTimeFlags&SDWTF_ST_TIME)
- GetFormatedDateTime(szOutput,_countof(szOutput),dat->settingLastTime,TRUE);
- else GetFormatedCountdown(szOutput,_countof(szOutput),dat->countdown);
- SetWindowText(dat->hwndTime,szOutput);
- PostMessage(hwndFrame,M_CHECK_CLIPPED,0,0);
- /* update tooltip text (if shown) */
- if (dat->hwndToolTip != NULL && !(dat->flags&FWPDF_PAUSED)) {
- TTTOOLINFO ti;
- ti.cbSize=sizeof(ti);
- if (SendMessage(dat->hwndToolTip,TTM_GETCURRENTTOOL,0,(LPARAM)&ti) && (HWND)ti.uId != dat->hwndIcon)
- SendMessage(dat->hwndToolTip,TTM_UPDATE,0,0);
- } else dat->flags&=~FWPDF_PAUSEDSHOWN;
- }
- return 0;
- case M_CLOSE_COUNTDOWN:
- KillTimer(hwndFrame,1);
- dat->countdown=0;
- dat->flags&=~FWPDF_PAUSED;
- SendMessage(hwndFrame,M_UPDATE_COUNTDOWN,0,0);
- dat->flags|=FWPDF_COUNTDOWNINVALID;
- /* step up to upper range */
- SendMessage(dat->hwndProgress,PBM_SETPOS,SendMessage(dat->hwndProgress,PBM_GETRANGE,FALSE,0),0);
- SetWindowLongPtr(dat->hwndProgress, GWL_STYLE, GetWindowLongPtr(dat->hwndProgress, GWL_STYLE) | PBM_SETMARQUEE);
- SendMessage(dat->hwndProgress,PBM_SETMARQUEE,TRUE,10); /* marquee for rest of time */
- return 0;
- case M_PAUSE_COUNTDOWN:
- if (dat->flags&FWPDF_PAUSED) {
- /* unpause */
- dat->flags&=~(FWPDF_PAUSED|FWPDF_PAUSEDSHOWN);
- SendMessage(hwndFrame,M_SET_COUNTDOWN,0,0);
- SendMessage(dat->hwndProgress,PBM_SETSTATE,PBST_NORMAL,0); /* WinVista+ */
- }
- else {
- /* pause */
- dat->flags|=FWPDF_PAUSED;
- SendMessage(dat->hwndProgress,PBM_SETSTATE,PBST_PAUSED,0); /* WinVista+ */
+ case M_SET_COUNTDOWN:
+ if (dat->fTimeFlags&SDWTF_ST_TIME) {
+ dat->settingLastTime = (time_t)db_get_dw(NULL, "AutoShutdown", "TimeStamp", SETTING_TIMESTAMP_DEFAULT);
+ dat->countdown = time(NULL);
+ if (dat->settingLastTime > dat->countdown) dat->countdown = dat->settingLastTime - dat->countdown;
+ else dat->countdown = 0;
+ }
+ else if (dat->flags&FWPDF_COUNTDOWNINVALID) {
+ dat->countdown = (time_t)db_get_dw(NULL, "AutoShutdown", "Countdown", SETTING_COUNTDOWN_DEFAULT);
+ dat->countdown *= (time_t)db_get_dw(NULL, "AutoShutdown", "CountdownUnit", SETTING_COUNTDOWNUNIT_DEFAULT);
+ }
+ dat->flags &= ~FWPDF_COUNTDOWNINVALID;
+ /* commctl 4.70+, Win95: 1-100 will work fine (wrap around) */
+ SendMessage(dat->hwndProgress, PBM_SETRANGE32, 0, (LPARAM)dat->countdown);
+ return 0;
+ case WM_TIMER:
+ if (dat == NULL) return 0;
+ if (dat->countdown != 0 && !(dat->flags&FWPDF_COUNTDOWNINVALID) && !(dat->flags&FWPDF_PAUSED)) {
+ dat->countdown--;
+ PostMessage(dat->hwndProgress, PBM_STEPIT, 0, 0);
+ }
+ if (IsWindowVisible(hwndFrame)) PostMessage(hwndFrame, M_UPDATE_COUNTDOWN, 0, 0);
+ if (dat->countdown == 0) {
+ SendMessage(hwndFrame, M_CLOSE_COUNTDOWN, 0, 0);
+ ServiceShutdown(0, TRUE);
+ ServiceStopWatcher(0, 0);
+ }
+ return 0;
+ case WM_SHOWWINDOW:
+ /* the text is kept unchanged while hidden */
+ if ((BOOL)wParam) SendMessage(hwndFrame, M_UPDATE_COUNTDOWN, 0, 0);
+ break;
+ case M_UPDATE_COUNTDOWN:
+ if (dat->flags&FWPDF_PAUSED && !(dat->flags&FWPDF_PAUSEDSHOWN)) {
+ SetWindowText(dat->hwndTime, TranslateT("Paused"));
+ dat->flags |= FWPDF_PAUSEDSHOWN;
+ }
+ else {
+ TCHAR szOutput[256];
+ if (dat->fTimeFlags&SDWTF_ST_TIME)
+ GetFormatedDateTime(szOutput, _countof(szOutput), dat->settingLastTime, TRUE);
+ else GetFormatedCountdown(szOutput, _countof(szOutput), dat->countdown);
+ SetWindowText(dat->hwndTime, szOutput);
+ PostMessage(hwndFrame, M_CHECK_CLIPPED, 0, 0);
+ /* update tooltip text (if shown) */
+ if (dat->hwndToolTip != NULL && !(dat->flags&FWPDF_PAUSED)) {
+ TTTOOLINFO ti;
+ ti.cbSize = sizeof(ti);
+ if (SendMessage(dat->hwndToolTip, TTM_GETCURRENTTOOL, 0, (LPARAM)&ti) && (HWND)ti.uId != dat->hwndIcon)
+ SendMessage(dat->hwndToolTip, TTM_UPDATE, 0, 0);
}
- SendMessage(hwndFrame,M_UPDATE_COUNTDOWN,0,0);
- return 0;
- case WM_CONTEXTMENU:
- {
- if (dat->flags & FWPDF_COUNTDOWNINVALID)
- return 0;
+ else dat->flags &= ~FWPDF_PAUSEDSHOWN;
+ }
+ return 0;
+ case M_CLOSE_COUNTDOWN:
+ KillTimer(hwndFrame, 1);
+ dat->countdown = 0;
+ dat->flags &= ~FWPDF_PAUSED;
+ SendMessage(hwndFrame, M_UPDATE_COUNTDOWN, 0, 0);
+ dat->flags |= FWPDF_COUNTDOWNINVALID;
+ /* step up to upper range */
+ SendMessage(dat->hwndProgress, PBM_SETPOS, SendMessage(dat->hwndProgress, PBM_GETRANGE, FALSE, 0), 0);
+ SetWindowLongPtr(dat->hwndProgress, GWL_STYLE, GetWindowLongPtr(dat->hwndProgress, GWL_STYLE) | PBM_SETMARQUEE);
+ SendMessage(dat->hwndProgress, PBM_SETMARQUEE, TRUE, 10); /* marquee for rest of time */
+ return 0;
+ case M_PAUSE_COUNTDOWN:
+ if (dat->flags&FWPDF_PAUSED) {
+ /* unpause */
+ dat->flags &= ~(FWPDF_PAUSED | FWPDF_PAUSEDSHOWN);
+ SendMessage(hwndFrame, M_SET_COUNTDOWN, 0, 0);
+ SendMessage(dat->hwndProgress, PBM_SETSTATE, PBST_NORMAL, 0); /* WinVista+ */
+ }
+ else {
+ /* pause */
+ dat->flags |= FWPDF_PAUSED;
+ SendMessage(dat->hwndProgress, PBM_SETSTATE, PBST_PAUSED, 0); /* WinVista+ */
+ }
+ SendMessage(hwndFrame, M_UPDATE_COUNTDOWN, 0, 0);
+ return 0;
+ case WM_CONTEXTMENU:
+ {
+ if (dat->flags & FWPDF_COUNTDOWNINVALID)
+ return 0;
- POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
- if (pt.x==-1 && pt.y==-1) { /* invoked by keyboard */
- RECT rc;
- /* position in middle above rect */
- if (!GetWindowRect(hwndFrame, &rc)) return 0;
- pt.x=rc.left+((int)(rc.right-rc.left)/2);
- pt.y=rc.top+((int)(rc.bottom-rc.top)/2);
- }
- HMENU hContextMenu = CreatePopupMenu();
- if (hContextMenu != NULL) {
- AppendMenu(hContextMenu,MF_STRING,MENUITEM_PAUSECOUNTDOWN,(dat->flags&FWPDF_PAUSED)?TranslateT("&Unpause Countdown"):TranslateT("&Pause Countdown"));
- SetMenuDefaultItem(hContextMenu,MENUITEM_PAUSECOUNTDOWN,FALSE);
- AppendMenu(hContextMenu,MF_STRING,MENUITEM_STOPCOUNTDOWN,TranslateT("&Cancel Countdown"));
- TrackPopupMenuEx(hContextMenu,TPM_LEFTALIGN|TPM_TOPALIGN|TPM_HORPOSANIMATION|TPM_VERPOSANIMATION|TPM_RIGHTBUTTON,pt.x,pt.y,hwndFrame,NULL);
- DestroyMenu(hContextMenu);
- }
+ POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
+ if (pt.x == -1 && pt.y == -1) { /* invoked by keyboard */
+ RECT rc;
+ /* position in middle above rect */
+ if (!GetWindowRect(hwndFrame, &rc)) return 0;
+ pt.x = rc.left + ((int)(rc.right - rc.left) / 2);
+ pt.y = rc.top + ((int)(rc.bottom - rc.top) / 2);
+ }
+ HMENU hContextMenu = CreatePopupMenu();
+ if (hContextMenu != NULL) {
+ AppendMenu(hContextMenu, MF_STRING, MENUITEM_PAUSECOUNTDOWN, (dat->flags&FWPDF_PAUSED) ? TranslateT("&Unpause Countdown") : TranslateT("&Pause Countdown"));
+ SetMenuDefaultItem(hContextMenu, MENUITEM_PAUSECOUNTDOWN, FALSE);
+ AppendMenu(hContextMenu, MF_STRING, MENUITEM_STOPCOUNTDOWN, TranslateT("&Cancel Countdown"));
+ TrackPopupMenuEx(hContextMenu, TPM_LEFTALIGN | TPM_TOPALIGN | TPM_HORPOSANIMATION | TPM_VERPOSANIMATION | TPM_RIGHTBUTTON, pt.x, pt.y, hwndFrame, NULL);
+ DestroyMenu(hContextMenu);
}
+ }
+ return 0;
+ case WM_LBUTTONDBLCLK:
+ if (!(dat->flags&FWPDF_COUNTDOWNINVALID))
+ SendMessage(hwndFrame, M_PAUSE_COUNTDOWN, 0, 0);
+ return 0;
+ case WM_COMMAND:
+ switch (LOWORD(wParam)) {
+ case MENUITEM_STOPCOUNTDOWN:
+ /* close only countdown window when other watcher types running */
+ if (dat->fTimeFlags&~(SDWTF_SPECIFICTIME | SDWTF_ST_MASK))
+ CloseCountdownFrame(); /* something else is running */
+ else ServiceStopWatcher(0, 0); /* calls CloseCountdownFrame() */
return 0;
- case WM_LBUTTONDBLCLK:
- if (!(dat->flags&FWPDF_COUNTDOWNINVALID))
- SendMessage(hwndFrame,M_PAUSE_COUNTDOWN,0,0);
+ case MENUITEM_PAUSECOUNTDOWN:
+ SendMessage(hwndFrame, M_PAUSE_COUNTDOWN, 0, 0);
return 0;
- case WM_COMMAND:
- switch(LOWORD(wParam)) {
- case MENUITEM_STOPCOUNTDOWN:
- /* close only countdown window when other watcher types running */
- if (dat->fTimeFlags&~(SDWTF_SPECIFICTIME|SDWTF_ST_MASK))
- CloseCountdownFrame(); /* something else is running */
- else ServiceStopWatcher(0,0); /* calls CloseCountdownFrame() */
- return 0;
- case MENUITEM_PAUSECOUNTDOWN:
- SendMessage(hwndFrame,M_PAUSE_COUNTDOWN,0,0);
- return 0;
- }
- break;
- case M_CHECK_CLIPPED: /* for in-place tooltip on dat->hwndTime */
- { RECT rc;
+ }
+ break;
+ case M_CHECK_CLIPPED: /* for in-place tooltip on dat->hwndTime */
+ {
+ RECT rc;
HDC hdc;
SIZE size;
- HFONT hFontPrev=NULL;
+ HFONT hFontPrev = NULL;
TCHAR szOutput[256];
- dat->flags&=~FWPDF_TIMEISCLIPPED;
- if (GetWindowText(dat->hwndTime,szOutput,_countof(szOutput)))
- if (GetClientRect(dat->hwndTime,&rc)) {
- hdc=GetDC(dat->hwndTime);
+ dat->flags &= ~FWPDF_TIMEISCLIPPED;
+ if (GetWindowText(dat->hwndTime, szOutput, _countof(szOutput)))
+ if (GetClientRect(dat->hwndTime, &rc)) {
+ hdc = GetDC(dat->hwndTime);
if (hdc != NULL) {
if (dat->hFont != NULL)
- hFontPrev = (HFONT)SelectObject(hdc,dat->hFont);
+ hFontPrev = (HFONT)SelectObject(hdc, dat->hFont);
if (GetTextExtentPoint32(hdc, szOutput, (int)mir_tstrlen(szOutput), &size))
- if (size.cx>=(rc.right-rc.left))
- dat->flags&=FWPDF_TIMEISCLIPPED;
+ if (size.cx >= (rc.right - rc.left))
+ dat->flags &= FWPDF_TIMEISCLIPPED;
if (dat->hFont != NULL)
- SelectObject(hdc,hFontPrev);
- ReleaseDC(dat->hwndTime,hdc);
+ SelectObject(hdc, hFontPrev);
+ ReleaseDC(dat->hwndTime, hdc);
}
}
return 0;
}
- case WM_NOTIFY:
- if (((NMHDR*)lParam)->hwndFrom==dat->hwndToolTip)
- switch(((NMHDR*)lParam)->code) {
- case TTN_SHOW: /* 'in-place' tooltip on dat->hwndTime */
- if (dat->flags&FWPDF_TIMEISCLIPPED && (HWND)wParam==dat->hwndTime) {
- RECT rc;
- if (GetWindowRect(dat->hwndTime,&rc)) {
- SetWindowLongPtr(dat->hwndToolTip, GWL_STYLE, GetWindowLongPtr(dat->hwndToolTip, GWL_STYLE) | TTS_NOANIMATE);
- SetWindowLongPtr(dat->hwndToolTip, GWL_EXSTYLE, GetWindowLongPtr(dat->hwndToolTip, GWL_EXSTYLE) | WS_EX_TRANSPARENT);
- SendMessage(dat->hwndToolTip,TTM_ADJUSTRECT,TRUE,(LPARAM)&rc);
- SetWindowPos(dat->hwndToolTip,NULL,rc.left,rc.top,0,0,SWP_NOSIZE|SWP_NOZORDER|SWP_NOACTIVATE);
- return TRUE; /* self-defined position */
- }
- }
- SetWindowLongPtr(dat->hwndToolTip, GWL_STYLE, GetWindowLongPtr(dat->hwndToolTip, GWL_STYLE) & (~TTS_NOANIMATE));
- SetWindowLongPtr(dat->hwndToolTip, GWL_EXSTYLE, GetWindowLongPtr(dat->hwndToolTip, GWL_EXSTYLE) & (~WS_EX_TRANSPARENT));
- return 0;
- case TTN_POP:
- /* workaround #5: frame does not get redrawn after
- * in-place tooltip hidden on dat->hwndTime */
- RedrawWindow(hwndCountdownFrame,NULL,NULL,RDW_INVALIDATE|RDW_ALLCHILDREN|RDW_ERASE);
- return 0;
- case TTN_NEEDTEXT:
- { NMTTDISPINFO *ttdi=(NMTTDISPINFO*)lParam;
- if (dat->flags&FWPDF_TIMEISCLIPPED && (HWND)wParam==dat->hwndTime) {
- if (GetWindowText(dat->hwndTime,ttdi->szText,_countof(ttdi->szText)))
- ttdi->lpszText=ttdi->szText;
- }
- else if ((HWND)wParam==dat->hwndIcon)
- ttdi->lpszText=TranslateT("Automatic Shutdown");
- else {
- TCHAR szTime[_countof(ttdi->szText)];
- if (dat->fTimeFlags&SDWTF_ST_TIME)
- GetFormatedDateTime(szTime,_countof(szTime),dat->settingLastTime,FALSE);
- else GetFormatedCountdown(szTime,_countof(szTime),dat->countdown);
- mir_sntprintf(ttdi->szText,_countof(ttdi->szText),_T("%s %s"),(dat->fTimeFlags&SDWTF_ST_TIME)?TranslateT("Shutdown at:"):TranslateT("Time left:"),szTime);
- ttdi->lpszText=ttdi->szText;
- }
- return 0;
+ case WM_NOTIFY:
+ if (((NMHDR*)lParam)->hwndFrom == dat->hwndToolTip)
+ switch (((NMHDR*)lParam)->code) {
+ case TTN_SHOW: /* 'in-place' tooltip on dat->hwndTime */
+ if (dat->flags&FWPDF_TIMEISCLIPPED && (HWND)wParam == dat->hwndTime) {
+ RECT rc;
+ if (GetWindowRect(dat->hwndTime, &rc)) {
+ SetWindowLongPtr(dat->hwndToolTip, GWL_STYLE, GetWindowLongPtr(dat->hwndToolTip, GWL_STYLE) | TTS_NOANIMATE);
+ SetWindowLongPtr(dat->hwndToolTip, GWL_EXSTYLE, GetWindowLongPtr(dat->hwndToolTip, GWL_EXSTYLE) | WS_EX_TRANSPARENT);
+ SendMessage(dat->hwndToolTip, TTM_ADJUSTRECT, TRUE, (LPARAM)&rc);
+ SetWindowPos(dat->hwndToolTip, NULL, rc.left, rc.top, 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
+ return TRUE; /* self-defined position */
+ }
+ }
+ SetWindowLongPtr(dat->hwndToolTip, GWL_STYLE, GetWindowLongPtr(dat->hwndToolTip, GWL_STYLE) & (~TTS_NOANIMATE));
+ SetWindowLongPtr(dat->hwndToolTip, GWL_EXSTYLE, GetWindowLongPtr(dat->hwndToolTip, GWL_EXSTYLE) & (~WS_EX_TRANSPARENT));
+ return 0;
+ case TTN_POP:
+ /* workaround #5: frame does not get redrawn after
+ * in-place tooltip hidden on dat->hwndTime */
+ RedrawWindow(hwndCountdownFrame, NULL, NULL, RDW_INVALIDATE | RDW_ALLCHILDREN | RDW_ERASE);
+ return 0;
+ case TTN_NEEDTEXT:
+ {
+ NMTTDISPINFO *ttdi = (NMTTDISPINFO*)lParam;
+ if (dat->flags&FWPDF_TIMEISCLIPPED && (HWND)wParam == dat->hwndTime) {
+ if (GetWindowText(dat->hwndTime, ttdi->szText, _countof(ttdi->szText)))
+ ttdi->lpszText = ttdi->szText;
}
+ else if ((HWND)wParam == dat->hwndIcon)
+ ttdi->lpszText = TranslateT("Automatic Shutdown");
+ else {
+ TCHAR szTime[_countof(ttdi->szText)];
+ if (dat->fTimeFlags&SDWTF_ST_TIME)
+ GetFormatedDateTime(szTime, _countof(szTime), dat->settingLastTime, FALSE);
+ else GetFormatedCountdown(szTime, _countof(szTime), dat->countdown);
+ mir_sntprintf(ttdi->szText, _countof(ttdi->szText), _T("%s %s"), (dat->fTimeFlags&SDWTF_ST_TIME) ? TranslateT("Shutdown at:") : TranslateT("Time left:"), szTime);
+ ttdi->lpszText = ttdi->szText;
+ }
+ return 0;
}
- break;
+ }
+ break;
}
- return DefWindowProc(hwndFrame,msg,wParam,lParam);
+ return DefWindowProc(hwndFrame, msg, wParam, lParam);
}
/************************* Show Frame *********************************/
void ShowCountdownFrame(WORD fTimeFlags)
{
- hwndCountdownFrame=CreateWindowEx(WS_EX_CONTROLPARENT|WS_EX_NOPARENTNOTIFY|WS_EX_TRANSPARENT,
- COUNTDOWNFRAME_CLASS,
- NULL,
- WS_CHILD|WS_TABSTOP,
- 0, 0,
- GetSystemMetrics(SM_CXICON)+103,
- GetSystemMetrics(SM_CYICON)+2,
- pcli->hwndContactList,
- NULL,
- hInst,
- &fTimeFlags);
- if (hwndCountdownFrame==NULL) return;
+ hwndCountdownFrame = CreateWindowEx(WS_EX_CONTROLPARENT | WS_EX_NOPARENTNOTIFY | WS_EX_TRANSPARENT,
+ COUNTDOWNFRAME_CLASS,
+ NULL,
+ WS_CHILD | WS_TABSTOP,
+ 0, 0,
+ GetSystemMetrics(SM_CXICON) + 103,
+ GetSystemMetrics(SM_CYICON) + 2,
+ pcli->hwndContactList,
+ NULL,
+ hInst,
+ &fTimeFlags);
+ if (hwndCountdownFrame == NULL) return;
if (ServiceExists(MS_CLIST_FRAMES_ADDFRAME)) {
CLISTFrame clf = { sizeof(clf) };
- clf.hIcon=IcoLib_GetIcon("AutoShutdown_Active"); /* CListFrames does not make a copy */
- clf.align=alBottom;
- clf.height=GetSystemMetrics(SM_CYICON);
- clf.Flags=F_VISIBLE|F_SHOWTBTIP|F_NOBORDER|F_SKINNED;
- clf.name=Translate("AutoShutdown");
- clf.TBname=Translate("Automatic Shutdown");
- clf.hWnd=hwndCountdownFrame;
- hFrame=(WORD)CallService(MS_CLIST_FRAMES_ADDFRAME,(WPARAM)&clf,0);
+ clf.hIcon = IcoLib_GetIcon("AutoShutdown_Active"); /* CListFrames does not make a copy */
+ clf.align = alBottom;
+ clf.height = GetSystemMetrics(SM_CYICON);
+ clf.Flags = F_VISIBLE | F_SHOWTBTIP | F_NOBORDER | F_SKINNED;
+ clf.name = Translate("AutoShutdown");
+ clf.TBname = Translate("Automatic Shutdown");
+ clf.hWnd = hwndCountdownFrame;
+ hFrame = (WORD)CallService(MS_CLIST_FRAMES_ADDFRAME, (WPARAM)&clf, 0);
if (hFrame) {
- ShowWindow(hwndCountdownFrame,SW_SHOW);
- CallService(MS_CLIST_FRAMES_SETFRAMEOPTIONS,MAKEWPARAM(FO_TBTIPNAME,hFrame),(LPARAM)clf.name);
+ ShowWindow(hwndCountdownFrame, SW_SHOW);
+ CallService(MS_CLIST_FRAMES_SETFRAMEOPTIONS, MAKEWPARAM(FO_TBTIPNAME, hFrame), (LPARAM)clf.name);
/* HACKS TO FIX CLUI FRAMES:
* *** why is CLUIFrames is horribly buggy??! *** date: sept 2005, nothing changed until sept 2006
* workaround #1: MS_CLIST_FRAMES_REMOVEFRAME does not finish with destroy cycle (clist_modern, clist_nicer crashes) */
SendMessage(pcli->hwndContactList, WM_SIZE, 0, 0);
/* workaround #2: drawing glitch after adding a frame (frame positioned wrongly when hidden) */
- CallService(MS_CLIST_FRAMES_UPDATEFRAME,hFrame,FU_FMPOS|FU_FMREDRAW);
+ CallService(MS_CLIST_FRAMES_UPDATEFRAME, hFrame, FU_FMPOS | FU_FMREDRAW);
/* workaround #3: MS_CLIST_FRAMES_SETFRAMEOPTIONS does cause redrawing problems */
- if (!(CallService(MS_CLIST_FRAMES_GETFRAMEOPTIONS,MAKEWPARAM(FO_FLAGS,hFrame),0)&F_VISIBLE))
- CallService(MS_CLIST_FRAMES_SHFRAME,hFrame,0);
+ if (!(CallService(MS_CLIST_FRAMES_GETFRAMEOPTIONS, MAKEWPARAM(FO_FLAGS, hFrame), 0)&F_VISIBLE))
+ CallService(MS_CLIST_FRAMES_SHFRAME, hFrame, 0);
/* workaround #4: MS_CLIST_FRAMES_SHFRAME does cause redrawing problems when frame was hidden */
- RedrawWindow(hwndCountdownFrame,NULL,NULL,RDW_INVALIDATE|RDW_ALLCHILDREN|RDW_ERASE);
+ RedrawWindow(hwndCountdownFrame, NULL, NULL, RDW_INVALIDATE | RDW_ALLCHILDREN | RDW_ERASE);
/* workaround #5: for in-place tooltip TTN_POP
* workaround #6 and #7: see CloseCountdownFrame() */
}
@@ -555,21 +529,21 @@ void ShowCountdownFrame(WORD fTimeFlags)
void CloseCountdownFrame(void)
{
if (hwndCountdownFrame != NULL) {
- SendMessage(hwndCountdownFrame,M_CLOSE_COUNTDOWN,0,0);
+ SendMessage(hwndCountdownFrame, M_CLOSE_COUNTDOWN, 0, 0);
if (hFrame) {
/* HACKS TO FIX CLUIFrames:
* workaround #6: MS_CLIST_FRAMES_REMOVEFRAME does not finish with
* destroy cycle (clist_modern, clist_nicer crashes) */
- CallService(MS_CLIST_FRAMES_SETFRAMEOPTIONS,MAKEWPARAM(FO_FLAGS,hFrame),(LPARAM)CallService(MS_CLIST_FRAMES_GETFRAMEOPTIONS,MAKEWPARAM(FO_FLAGS,hFrame),0)&(~F_VISIBLE));
+ CallService(MS_CLIST_FRAMES_SETFRAMEOPTIONS, MAKEWPARAM(FO_FLAGS, hFrame), (LPARAM)CallService(MS_CLIST_FRAMES_GETFRAMEOPTIONS, MAKEWPARAM(FO_FLAGS, hFrame), 0)&(~F_VISIBLE));
#if !defined(_DEBUG)
- /* workaround #7: MS_CLIST_FRAMES_REMOVEFRAME crashes after two calls
- * clist_nicer crashes after some calls (bug in it) */
- CallService(MS_CLIST_FRAMES_REMOVEFRAME,hFrame,0);
+ /* workaround #7: MS_CLIST_FRAMES_REMOVEFRAME crashes after two calls
+ * clist_nicer crashes after some calls (bug in it) */
+ CallService(MS_CLIST_FRAMES_REMOVEFRAME, hFrame, 0);
#endif
}
else DestroyWindow(hwndCountdownFrame);
- hwndCountdownFrame=NULL;
- hFrame=0;
+ hwndCountdownFrame = NULL;
+ hFrame = 0;
}
}
@@ -582,13 +556,13 @@ static int FrameModulesLoaded(WPARAM, LPARAM)
LOGFONT lf;
/* built-in font module is not available before this hook */
COLORREF clr = GetDefaultColor(FRAMEELEMENT_TEXT);
- FontService_RegisterFont("AutoShutdown","CountdownFont",LPGENT("Automatic Shutdown"),LPGENT("Countdown on Frame"),LPGENT("Automatic Shutdown"),LPGENT("Background"),0,FALSE,GetDefaultFont(&lf),clr);
- clr=GetDefaultColor(FRAMEELEMENT_BKGRND);
- FontService_RegisterColor("AutoShutdown","BkgColor",LPGENT("Automatic Shutdown"),LPGENT("Background"),clr);
- if ( !IsThemeActive()) {
+ FontService_RegisterFont("AutoShutdown", "CountdownFont", LPGENT("Automatic Shutdown"), LPGENT("Countdown on Frame"), LPGENT("Automatic Shutdown"), LPGENT("Background"), 0, FALSE, GetDefaultFont(&lf), clr);
+ clr = GetDefaultColor(FRAMEELEMENT_BKGRND);
+ FontService_RegisterColor("AutoShutdown", "BkgColor", LPGENT("Automatic Shutdown"), LPGENT("Background"), clr);
+ if (!IsThemeActive()) {
/* progressbar color can only be changed with classic theme */
- clr=GetDefaultColor(FRAMEELEMENT_BAR);
- FontService_RegisterColor("AutoShutdown","ProgressColor",TranslateT("Automatic Shutdown"),TranslateT("Progress Bar"),clr);
+ clr = GetDefaultColor(FRAMEELEMENT_BAR);
+ FontService_RegisterColor("AutoShutdown", "ProgressColor", TranslateT("Automatic Shutdown"), TranslateT("Progress Bar"), clr);
}
}
return 0;
@@ -596,24 +570,24 @@ static int FrameModulesLoaded(WPARAM, LPARAM)
int InitFrame(void)
{
- WNDCLASSEX wcx;
- memset(&wcx, 0, sizeof(wcx));
- wcx.cbSize =sizeof(wcx);
- wcx.style =CS_DBLCLKS|CS_PARENTDC;
- wcx.lpfnWndProc =FrameWndProc;
- wcx.hInstance =hInst;
- wcx.hCursor =(HCURSOR)LoadImage(NULL,IDC_ARROW,IMAGE_CURSOR,0,0,LR_SHARED);
- wcx.lpszClassName =COUNTDOWNFRAME_CLASS;
- if (!RegisterClassEx(&wcx)) return 1;
-
- hwndCountdownFrame=NULL;
- hHookModulesLoaded=HookEvent(ME_SYSTEM_MODULESLOADED,FrameModulesLoaded);
+ WNDCLASSEX wcx = {};
+ wcx.cbSize = sizeof(wcx);
+ wcx.style = CS_DBLCLKS | CS_PARENTDC;
+ wcx.lpfnWndProc = FrameWndProc;
+ wcx.hInstance = hInst;
+ wcx.hCursor = (HCURSOR)LoadImage(NULL, IDC_ARROW, IMAGE_CURSOR, 0, 0, LR_SHARED);
+ wcx.lpszClassName = COUNTDOWNFRAME_CLASS;
+ if (!RegisterClassEx(&wcx))
+ return 1;
+
+ hwndCountdownFrame = NULL;
+ hHookModulesLoaded = HookEvent(ME_SYSTEM_MODULESLOADED, FrameModulesLoaded);
return 0;
}
void UninitFrame(void)
{
/* frame closed by UninitWatcher() */
- UnregisterClass(COUNTDOWNFRAME_CLASS,hInst); /* fails if window still exists */
+ UnregisterClass(COUNTDOWNFRAME_CLASS, hInst); /* fails if window still exists */
UnhookEvent(hHookModulesLoaded);
}
diff --git a/plugins/AutoShutdown/src/main.cpp b/plugins/AutoShutdown/src/main.cpp
index 480debca46..fca05d6585 100644
--- a/plugins/AutoShutdown/src/main.cpp
+++ b/plugins/AutoShutdown/src/main.cpp
@@ -38,7 +38,7 @@ PLUGININFOEX pluginInfo = {
{0x9de24579, 0x5c5c, 0x49aa, {0x80, 0xe8, 0x4d, 0x38, 0xe4, 0x34, 0x4e, 0x63}}
};
-IconItem iconList[] =
+IconItem iconList[] =
{
{ LPGEN("Header"), "AutoShutdown_Header", IDI_HEADER },
{ LPGEN("Active"), "AutoShutdown_Active", IDI_ACTIVE },
@@ -51,13 +51,12 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD, VOID*)
return TRUE;
}
-static int ShutdownModulesLoaded(WPARAM,LPARAM)
+static int ShutdownModulesLoaded(WPARAM, LPARAM)
{
/* Toolbar Item */
- HookEvent(ME_TTB_MODULELOADED,ToolbarLoaded); /* no service to check for */
+ HookEvent(ME_TTB_MODULELOADED, ToolbarLoaded); /* no service to check for */
WatcherModulesLoaded();
-
return 0;
}
@@ -72,8 +71,8 @@ extern "C" __declspec(dllexport) int Load(void)
mir_getCLI();
INITCOMMONCONTROLSEX icc;
- icc.dwSize=sizeof(icc);
- icc.dwICC=ICC_DATE_CLASSES|ICC_UPDOWN_CLASS|ICC_PROGRESS_CLASS;
+ icc.dwSize = sizeof(icc);
+ icc.dwICC = ICC_DATE_CLASSES | ICC_UPDOWN_CLASS | ICC_PROGRESS_CLASS;
if (!InitCommonControlsEx(&icc)) return 1;
if (InitFrame()) return 1; /* before icons */
@@ -98,4 +97,4 @@ extern "C" __declspec(dllexport) int Unload(void)
UninitFrame();
UninitShutdownSvc();
return 0;
-} \ No newline at end of file
+}
diff --git a/plugins/AutoShutdown/src/options.cpp b/plugins/AutoShutdown/src/options.cpp
index 0fa9d4f5e3..c783eb650b 100644
--- a/plugins/AutoShutdown/src/options.cpp
+++ b/plugins/AutoShutdown/src/options.cpp
@@ -31,71 +31,72 @@ static HANDLE hHookModulesLoaded;
#define M_ENABLE_SUBCTLS (WM_APP+111)
-static INT_PTR CALLBACK ShutdownOptDlgProc(HWND hwndDlg,UINT msg,WPARAM wParam,LPARAM lParam)
+static INT_PTR CALLBACK ShutdownOptDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
- switch(msg) {
+ switch (msg) {
case WM_INITDIALOG:
TranslateDialogDefault(hwndDlg);
{
- WORD setting=db_get_w(NULL,"AutoShutdown","ConfirmDlgCountdown",SETTING_CONFIRMDLGCOUNTDOWN_DEFAULT);
- if (setting<3) setting=SETTING_CONFIRMDLGCOUNTDOWN_DEFAULT;
- SendDlgItemMessage(hwndDlg,IDC_SPIN_CONFIRMDLGCOUNTDOWN,UDM_SETRANGE,0,MAKELPARAM(999,3));
- SendDlgItemMessage(hwndDlg,IDC_EDIT_CONFIRMDLGCOUNTDOWN,EM_SETLIMITTEXT,3,0);
- SendDlgItemMessage(hwndDlg,IDC_SPIN_CONFIRMDLGCOUNTDOWN,UDM_SETPOS,0,MAKELPARAM(setting,0));
- SetDlgItemInt(hwndDlg,IDC_EDIT_CONFIRMDLGCOUNTDOWN,setting,FALSE);
+ WORD setting = db_get_w(NULL, "AutoShutdown", "ConfirmDlgCountdown", SETTING_CONFIRMDLGCOUNTDOWN_DEFAULT);
+ if (setting < 3)
+ setting = SETTING_CONFIRMDLGCOUNTDOWN_DEFAULT;
+ SendDlgItemMessage(hwndDlg, IDC_SPIN_CONFIRMDLGCOUNTDOWN, UDM_SETRANGE, 0, MAKELPARAM(999, 3));
+ SendDlgItemMessage(hwndDlg, IDC_EDIT_CONFIRMDLGCOUNTDOWN, EM_SETLIMITTEXT, 3, 0);
+ SendDlgItemMessage(hwndDlg, IDC_SPIN_CONFIRMDLGCOUNTDOWN, UDM_SETPOS, 0, MAKELPARAM(setting, 0));
+ SetDlgItemInt(hwndDlg, IDC_EDIT_CONFIRMDLGCOUNTDOWN, setting, FALSE);
}
- CheckDlgButton(hwndDlg,IDC_CHECK_SMARTOFFLINECHECK,db_get_b(NULL,"AutoShutdown","SmartOfflineCheck",SETTING_SMARTOFFLINECHECK_DEFAULT) != 0 ? BST_CHECKED : BST_UNCHECKED);
- CheckDlgButton(hwndDlg,IDC_CHECK_REMEMBERONRESTART,db_get_b(NULL,"AutoShutdown","RememberOnRestart",SETTING_REMEMBERONRESTART_DEFAULT) != 0 ? BST_CHECKED : BST_UNCHECKED);
- CheckDlgButton(hwndDlg,IDC_CHECK_SHOWCONFIRMDLG,db_get_b(NULL,"AutoShutdown","ShowConfirmDlg",SETTING_SHOWCONFIRMDLG_DEFAULT) != 0 ? BST_CHECKED : BST_UNCHECKED);
+ CheckDlgButton(hwndDlg, IDC_CHECK_SMARTOFFLINECHECK, db_get_b(NULL, "AutoShutdown", "SmartOfflineCheck", SETTING_SMARTOFFLINECHECK_DEFAULT) != 0 ? BST_CHECKED : BST_UNCHECKED);
+ CheckDlgButton(hwndDlg, IDC_CHECK_REMEMBERONRESTART, db_get_b(NULL, "AutoShutdown", "RememberOnRestart", SETTING_REMEMBERONRESTART_DEFAULT) != 0 ? BST_CHECKED : BST_UNCHECKED);
+ CheckDlgButton(hwndDlg, IDC_CHECK_SHOWCONFIRMDLG, db_get_b(NULL, "AutoShutdown", "ShowConfirmDlg", SETTING_SHOWCONFIRMDLG_DEFAULT) != 0 ? BST_CHECKED : BST_UNCHECKED);
{
- BOOL enabled = ServiceIsTypeEnabled(SDSDT_SHUTDOWN,0);
+ BOOL enabled = ServiceIsTypeEnabled(SDSDT_SHUTDOWN, 0);
if (enabled) {
if (ServiceExists(MS_WEATHER_UPDATE)) {
- EnableWindow(GetDlgItem(hwndDlg,IDC_CHECK_WEATHER),TRUE);
- CheckDlgButton(hwndDlg,IDC_CHECK_WEATHER,db_get_b(NULL,"AutoShutdown","WeatherShutdown",SETTING_WEATHERSHUTDOWN_DEFAULT) != 0 ? BST_CHECKED : BST_UNCHECKED);
+ EnableWindow(GetDlgItem(hwndDlg, IDC_CHECK_WEATHER), TRUE);
+ CheckDlgButton(hwndDlg, IDC_CHECK_WEATHER, db_get_b(NULL, "AutoShutdown", "WeatherShutdown", SETTING_WEATHERSHUTDOWN_DEFAULT) != 0 ? BST_CHECKED : BST_UNCHECKED);
}
}
}
- SendMessage(hwndDlg,M_ENABLE_SUBCTLS,0,0);
+ SendMessage(hwndDlg, M_ENABLE_SUBCTLS, 0, 0);
return TRUE; /* default focus */
case M_ENABLE_SUBCTLS:
{
- BOOL checked=IsDlgButtonChecked(hwndDlg,IDC_CHECK_SHOWCONFIRMDLG) != 0;
- if (checked != IsWindowEnabled(GetDlgItem(hwndDlg,IDC_EDIT_CONFIRMDLGCOUNTDOWN))) {
- EnableWindow(GetDlgItem(hwndDlg,IDC_EDIT_CONFIRMDLGCOUNTDOWN),checked);
- EnableWindow(GetDlgItem(hwndDlg,IDC_SPIN_CONFIRMDLGCOUNTDOWN),checked);
- EnableWindow(GetDlgItem(hwndDlg,IDC_TEXT_COUNTDOWNSTARTS),checked);
- EnableWindow(GetDlgItem(hwndDlg,IDC_TEXT_SECONDS),checked);
+ BOOL checked = IsDlgButtonChecked(hwndDlg, IDC_CHECK_SHOWCONFIRMDLG) != 0;
+ if (checked != IsWindowEnabled(GetDlgItem(hwndDlg, IDC_EDIT_CONFIRMDLGCOUNTDOWN))) {
+ EnableWindow(GetDlgItem(hwndDlg, IDC_EDIT_CONFIRMDLGCOUNTDOWN), checked);
+ EnableWindow(GetDlgItem(hwndDlg, IDC_SPIN_CONFIRMDLGCOUNTDOWN), checked);
+ EnableWindow(GetDlgItem(hwndDlg, IDC_TEXT_COUNTDOWNSTARTS), checked);
+ EnableWindow(GetDlgItem(hwndDlg, IDC_TEXT_SECONDS), checked);
}
return TRUE;
}
case WM_COMMAND:
- switch(LOWORD(wParam)) {
+ switch (LOWORD(wParam)) {
case IDC_EDIT_CONFIRMDLGCOUNTDOWN:
- if (HIWORD(wParam)==EN_KILLFOCUS)
- if ((int)GetDlgItemInt(hwndDlg,IDC_EDIT_CONFIRMDLGCOUNTDOWN,NULL,TRUE)<3) {
- SendDlgItemMessage(hwndDlg,IDC_SPIN_CONFIRMDLGCOUNTDOWN,UDM_SETPOS,0,MAKELPARAM(3,0));
- SetDlgItemInt(hwndDlg,IDC_EDIT_CONFIRMDLGCOUNTDOWN,3,FALSE);
+ if (HIWORD(wParam) == EN_KILLFOCUS)
+ if ((int)GetDlgItemInt(hwndDlg, IDC_EDIT_CONFIRMDLGCOUNTDOWN, NULL, TRUE) < 3) {
+ SendDlgItemMessage(hwndDlg, IDC_SPIN_CONFIRMDLGCOUNTDOWN, UDM_SETPOS, 0, MAKELPARAM(3, 0));
+ SetDlgItemInt(hwndDlg, IDC_EDIT_CONFIRMDLGCOUNTDOWN, 3, FALSE);
}
- if (HIWORD(wParam) != EN_CHANGE || (HWND)lParam != GetFocus())
- return TRUE; /* no apply */
- break;
+ if (HIWORD(wParam) != EN_CHANGE || (HWND)lParam != GetFocus())
+ return TRUE; /* no apply */
+ break;
}
- PostMessage(hwndDlg,M_ENABLE_SUBCTLS,0,0);
- PostMessage(GetParent(hwndDlg),PSM_CHANGED,0,0); /* enable apply */
+ PostMessage(hwndDlg, M_ENABLE_SUBCTLS, 0, 0);
+ PostMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); /* enable apply */
return FALSE;
case WM_NOTIFY:
- switch(((NMHDR*)lParam)->code) {
+ switch (((NMHDR*)lParam)->code) {
case PSN_APPLY:
- db_set_b(NULL,"AutoShutdown","ShowConfirmDlg",(BYTE)(IsDlgButtonChecked(hwndDlg,IDC_CHECK_SHOWCONFIRMDLG) != 0));
- db_set_w(NULL,"AutoShutdown","ConfirmDlgCountdown",(WORD)GetDlgItemInt(hwndDlg,IDC_EDIT_CONFIRMDLGCOUNTDOWN,NULL,FALSE));
- db_set_b(NULL,"AutoShutdown","RememberOnRestart",(BYTE)(IsDlgButtonChecked(hwndDlg,IDC_CHECK_REMEMBERONRESTART) != 0));
- db_set_b(NULL,"AutoShutdown","SmartOfflineCheck",(BYTE)(IsDlgButtonChecked(hwndDlg,IDC_CHECK_SMARTOFFLINECHECK) != 0));
- if (IsWindowEnabled(GetDlgItem(hwndDlg,IDC_CHECK_WEATHER)))
- db_set_b(NULL,"AutoShutdown","WeatherShutdown",(BYTE)(IsDlgButtonChecked(hwndDlg,IDC_CHECK_WEATHER) != 0));
+ db_set_b(NULL, "AutoShutdown", "ShowConfirmDlg", (BYTE)(IsDlgButtonChecked(hwndDlg, IDC_CHECK_SHOWCONFIRMDLG) != 0));
+ db_set_w(NULL, "AutoShutdown", "ConfirmDlgCountdown", (WORD)GetDlgItemInt(hwndDlg, IDC_EDIT_CONFIRMDLGCOUNTDOWN, NULL, FALSE));
+ db_set_b(NULL, "AutoShutdown", "RememberOnRestart", (BYTE)(IsDlgButtonChecked(hwndDlg, IDC_CHECK_REMEMBERONRESTART) != 0));
+ db_set_b(NULL, "AutoShutdown", "SmartOfflineCheck", (BYTE)(IsDlgButtonChecked(hwndDlg, IDC_CHECK_SMARTOFFLINECHECK) != 0));
+ if (IsWindowEnabled(GetDlgItem(hwndDlg, IDC_CHECK_WEATHER)))
+ db_set_b(NULL, "AutoShutdown", "WeatherShutdown", (BYTE)(IsDlgButtonChecked(hwndDlg, IDC_CHECK_WEATHER) != 0));
return TRUE;
}
break;
@@ -123,7 +124,7 @@ static int ShutdownOptInit(WPARAM wParam, LPARAM)
void InitOptions(void)
{
/* Option Page */
- hHookOptInit=HookEvent(ME_OPT_INITIALISE,ShutdownOptInit);
+ hHookOptInit = HookEvent(ME_OPT_INITIALISE, ShutdownOptInit);
}
void UninitOptions(void)
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,&timestamp)) {
+ if (SystemTimeToTimeStamp(&st, &timestamp)) {
/* 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,&timestamp)) {
+ if (timestamp < time(NULL)) {
+ st.wDay = stBuf.wDay;
+ st.wDayOfWeek = stBuf.wDayOfWeek;
+ st.wMonth = stBuf.wMonth;
+ st.wYear = stBuf.wYear;
+ if (SystemTimeToTimeStamp(&st, &timestamp)) {
/* 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,&timestamp))
- 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, &timestamp))
+ 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);
}
-
diff --git a/plugins/AutoShutdown/src/shutdownsvc.cpp b/plugins/AutoShutdown/src/shutdownsvc.cpp
index 778fcd79e2..68f398d0f5 100644
--- a/plugins/AutoShutdown/src/shutdownsvc.cpp
+++ b/plugins/AutoShutdown/src/shutdownsvc.cpp
@@ -30,7 +30,8 @@ static HANDLE hEventOkToShutdown,hEventShutdown;
/************************* Utils **************************************/
-TCHAR *desc[] = {
+TCHAR *desc[] =
+{
LPGENT("Miranda NG is going to be automatically closed in %u second(s)."),
LPGENT("All Miranda NG protocols are going to be set to offline in %u second(s)."),
LPGENT("You will be logged off automatically in %u second(s)."),
@@ -42,87 +43,88 @@ TCHAR *desc[] = {
LPGENT("The computer will automatically be shut down in %u second(s).")
};
-static BOOL WinNT_SetPrivilege(TCHAR *pszPrivName,BOOL bEnable)
+static BOOL WinNT_SetPrivilege(TCHAR *pszPrivName, BOOL bEnable)
{
- BOOL bReturn=FALSE;
+ BOOL bReturn = FALSE;
HANDLE hToken;
TOKEN_PRIVILEGES tkp;
/* get a token for this process */
- if (OpenProcessToken(GetCurrentProcess(),TOKEN_ADJUST_PRIVILEGES|TOKEN_QUERY,&hToken)) {
- tkp.PrivilegeCount=1; /* one privilege is to set */
+ if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken)) {
+ tkp.PrivilegeCount = 1; /* one privilege is to set */
/* get the LUID for the shutdown privilege */
- if (LookupPrivilegeValue(NULL,pszPrivName,&tkp.Privileges[0].Luid)) {
- tkp.Privileges[0].Attributes=bEnable?SE_PRIVILEGE_ENABLED:0;
+ if (LookupPrivilegeValue(NULL, pszPrivName, &tkp.Privileges[0].Luid)) {
+ tkp.Privileges[0].Attributes = bEnable ? SE_PRIVILEGE_ENABLED : 0;
/* get the shutdown privilege for this process */
- bReturn=AdjustTokenPrivileges(hToken,FALSE,&tkp,0,(PTOKEN_PRIVILEGES)NULL,0);
+ bReturn = AdjustTokenPrivileges(hToken, FALSE, &tkp, 0, (PTOKEN_PRIVILEGES)NULL, 0);
}
CloseHandle(hToken);
}
return bReturn;
}
-static void BroadcastEndSession(DWORD dwRecipients,LPARAM lParam)
+static void BroadcastEndSession(DWORD dwRecipients, LPARAM lParam)
{
- BroadcastSystemMessage(BSF_FORCEIFHUNG,&dwRecipients,WM_ENDSESSION,TRUE,lParam);
+ BroadcastSystemMessage(BSF_FORCEIFHUNG, &dwRecipients, WM_ENDSESSION, TRUE, lParam);
}
/************************* Workers ************************************/
static BOOL IsShutdownTypeEnabled(BYTE shutdownType)
{
- BOOL bReturn=FALSE;
- switch(shutdownType) {
- case SDSDT_HIBERNATE:
- case SDSDT_STANDBY:
- bReturn = shutdownType == SDSDT_HIBERNATE ? IsPwrHibernateAllowed() : IsPwrSuspendAllowed() != 0;
- /* test privilege */
- if (bReturn) {
- bReturn=WinNT_SetPrivilege(SE_SHUTDOWN_NAME,TRUE);
- if (bReturn) WinNT_SetPrivilege(SE_SHUTDOWN_NAME,FALSE);
- }
- break;
- case SDSDT_LOGOFF:
- { HKEY hKey;
- DWORD dwSetting,dwSize;
- /* NoLogOff is BINARY on Win9x/ME and DWORD on Win2000+ */
- bReturn=TRUE;
- if (RegOpenKeyEx(HKEY_CURRENT_USER,_T("Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer"),0,KEY_QUERY_VALUE,&hKey)==ERROR_SUCCESS) {
- dwSize=sizeof(dwSetting);
- if (RegQueryValueEx(hKey, _T("NoLogOff"), 0, NULL, (LPBYTE)&dwSetting, &dwSize) == ERROR_SUCCESS)
- if (dwSetting) bReturn=FALSE;
- RegCloseKey(hKey);
- }
- }
- break;
- case SDSDT_LOCKWORKSTATION:
- {
- HKEY hKey;
- DWORD dwSize,dwSetting;
- /* DisableLockWorkstation is DWORD on Win2000+ */
- bReturn=TRUE;
- if (RegOpenKeyEx(HKEY_CURRENT_USER,_T("Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System"),0,KEY_QUERY_VALUE,&hKey)==ERROR_SUCCESS) {
- dwSize=sizeof(dwSetting);
- if (!RegQueryValueEx(hKey, _T("DisableLockWorkstation"), 0, NULL, (LPBYTE)&dwSetting, &dwSize))
- if (dwSetting)
- bReturn=FALSE;
- RegCloseKey(hKey);
- }
+ BOOL bReturn = FALSE;
+ switch (shutdownType) {
+ case SDSDT_HIBERNATE:
+ case SDSDT_STANDBY:
+ bReturn = shutdownType == SDSDT_HIBERNATE ? IsPwrHibernateAllowed() : IsPwrSuspendAllowed() != 0;
+ /* test privilege */
+ if (bReturn) {
+ bReturn = WinNT_SetPrivilege(SE_SHUTDOWN_NAME, TRUE);
+ if (bReturn) WinNT_SetPrivilege(SE_SHUTDOWN_NAME, FALSE);
+ }
+ break;
+ case SDSDT_LOGOFF:
+ {
+ HKEY hKey;
+ DWORD dwSetting, dwSize;
+ /* NoLogOff is BINARY on Win9x/ME and DWORD on Win2000+ */
+ bReturn = TRUE;
+ if (RegOpenKeyEx(HKEY_CURRENT_USER, _T("Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer"), 0, KEY_QUERY_VALUE, &hKey) == ERROR_SUCCESS) {
+ dwSize = sizeof(dwSetting);
+ if (RegQueryValueEx(hKey, _T("NoLogOff"), 0, NULL, (LPBYTE)&dwSetting, &dwSize) == ERROR_SUCCESS)
+ if (dwSetting) bReturn = FALSE;
+ RegCloseKey(hKey);
}
- break;
- case SDSDT_CLOSERASCONNECTIONS:
- /* check if RAS installed/available */
+ }
+ break;
+ case SDSDT_LOCKWORKSTATION:
+ {
+ HKEY hKey;
+ DWORD dwSize, dwSetting;
+ /* DisableLockWorkstation is DWORD on Win2000+ */
bReturn = TRUE;
- break;
- case SDSDT_SETMIRANDAOFFLINE:
- case SDSDT_CLOSEMIRANDA:
- bReturn=TRUE; /* always possible */
- break;
- case SDSDT_REBOOT:
- case SDSDT_SHUTDOWN:
- /* test privileges */
- bReturn=WinNT_SetPrivilege(SE_SHUTDOWN_NAME,TRUE);
- if (bReturn)
- WinNT_SetPrivilege(SE_SHUTDOWN_NAME,FALSE);
- break;
+ if (RegOpenKeyEx(HKEY_CURRENT_USER, _T("Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System"), 0, KEY_QUERY_VALUE, &hKey) == ERROR_SUCCESS) {
+ dwSize = sizeof(dwSetting);
+ if (!RegQueryValueEx(hKey, _T("DisableLockWorkstation"), 0, NULL, (LPBYTE)&dwSetting, &dwSize))
+ if (dwSetting)
+ bReturn = FALSE;
+ RegCloseKey(hKey);
+ }
+ }
+ break;
+ case SDSDT_CLOSERASCONNECTIONS:
+ /* check if RAS installed/available */
+ bReturn = TRUE;
+ break;
+ case SDSDT_SETMIRANDAOFFLINE:
+ case SDSDT_CLOSEMIRANDA:
+ bReturn = TRUE; /* always possible */
+ break;
+ case SDSDT_REBOOT:
+ case SDSDT_SHUTDOWN:
+ /* test privileges */
+ bReturn = WinNT_SetPrivilege(SE_SHUTDOWN_NAME, TRUE);
+ if (bReturn)
+ WinNT_SetPrivilege(SE_SHUTDOWN_NAME, FALSE);
+ break;
}
return bReturn;
}
@@ -130,94 +132,94 @@ static BOOL IsShutdownTypeEnabled(BYTE shutdownType)
static DWORD ShutdownNow(BYTE shutdownType)
{
DWORD dwErrCode = ERROR_SUCCESS;
- switch(shutdownType) {
+ switch (shutdownType) {
case SDSDT_CLOSEMIRANDA:
if (!Miranda_Terminated()) {
/* waiting for short until ready (but not too long...) */
- DWORD dwLastTickCount=GetTickCount();
- while(!CallService(MS_SYSTEM_OKTOEXIT,0,0)) {
+ DWORD dwLastTickCount = GetTickCount();
+ while (!CallService(MS_SYSTEM_OKTOEXIT, 0, 0)) {
/* infinite loop protection (max 5 sec) */
- if (GetTickCount()-dwLastTickCount>=5000) { /* wraparound works */
+ if (GetTickCount() - dwLastTickCount >= 5000) { /* wraparound works */
OutputDebugStringA("Timeout (5 sec)\n"); /* tell others, all ascii */
break;
}
- SleepEx(1000,TRUE);
+ SleepEx(1000, TRUE);
if (Miranda_Terminated()) break; /* someone else did it */
OutputDebugStringA("Not ready to exit. Waiting...\n"); /* tell others, all ascii */
}
/* shutdown service must be called from main thread anyway */
if (!DestroyWindow(pcli->hwndContactList))
- dwErrCode=GetLastError();
+ dwErrCode = GetLastError();
}
break;
case SDSDT_SETMIRANDAOFFLINE:
/* set global status mode to offline (is remembered by Miranda on exit) */
- CallService(MS_CLIST_SETSTATUSMODE,(WPARAM)ID_STATUS_OFFLINE,0);
+ CallService(MS_CLIST_SETSTATUSMODE, (WPARAM)ID_STATUS_OFFLINE, 0);
break;
case SDSDT_STANDBY:
case SDSDT_HIBERNATE:
- WinNT_SetPrivilege(SE_SHUTDOWN_NAME,TRUE);
+ WinNT_SetPrivilege(SE_SHUTDOWN_NAME, TRUE);
if (!SetSystemPowerState(shutdownType == SDSDT_STANDBY, TRUE))
dwErrCode = GetLastError();
- WinNT_SetPrivilege(SE_SHUTDOWN_NAME,FALSE);
+ WinNT_SetPrivilege(SE_SHUTDOWN_NAME, FALSE);
break;
case SDSDT_LOCKWORKSTATION:
- if ( !IsWorkstationLocked())
+ if (!IsWorkstationLocked())
dwErrCode = GetLastError();
break;
case SDSDT_CLOSERASCONNECTIONS:
ShutdownNow(SDSDT_SETMIRANDAOFFLINE); /* set Miranda offline */
/* hang up all ras connections */
- {
+ {
DWORD dwRetries;
RASCONNSTATUS rcs;
- DWORD dw,dwLastTickCount;
+ DWORD dw, dwLastTickCount;
- DWORD dwConnSize=sizeof(RASCONN);
- DWORD dwConnItems=0;
- RASCONN *paConn=(RASCONN*)mir_alloc(dwConnSize);
- dwErrCode=ERROR_NOT_ENOUGH_MEMORY;
+ DWORD dwConnSize = sizeof(RASCONN);
+ DWORD dwConnItems = 0;
+ RASCONN *paConn = (RASCONN*)mir_alloc(dwConnSize);
+ dwErrCode = ERROR_NOT_ENOUGH_MEMORY;
if (paConn != NULL) {
- for(dwRetries=5; dwRetries != 0; dwRetries--) { /* prevent infinite loop (rare) */
+ for (dwRetries = 5; dwRetries != 0; dwRetries--) { /* prevent infinite loop (rare) */
memset(paConn, 0, dwConnSize);
paConn[0].dwSize = sizeof(RASCONN);
dwErrCode = RasEnumConnections(paConn, &dwConnSize, &dwConnItems);
if (dwErrCode != ERROR_BUFFER_TOO_SMALL) break;
- RASCONN *paConnBuf=(RASCONN*)mir_realloc(paConn,dwConnSize);
+ RASCONN *paConnBuf = (RASCONN*)mir_realloc(paConn, dwConnSize);
if (paConnBuf == NULL) {
mir_free(paConn);
paConn = NULL;
dwErrCode = ERROR_NOT_ENOUGH_MEMORY;
break;
}
- paConn=paConnBuf;
+ paConn = paConnBuf;
}
- if (dwErrCode==ERROR_SUCCESS || dwErrCode==ERROR_BUFFER_TOO_SMALL) {
- for(dw=0;dw<dwConnItems;++dw) {
+ if (dwErrCode == ERROR_SUCCESS || dwErrCode == ERROR_BUFFER_TOO_SMALL) {
+ for (dw = 0; dw < dwConnItems; ++dw) {
if (dwErrCode) {
if (RasHangUp(paConn[dw].hrasconn))
- paConn[dw].hrasconn=NULL; /* do not wait for on error */
+ paConn[dw].hrasconn = NULL; /* do not wait for on error */
}
else {
dwErrCode = RasHangUp(paConn[dw].hrasconn);
- if (!dwErrCode) paConn[dw].hrasconn=NULL; /* do not wait for on error */
+ if (!dwErrCode) paConn[dw].hrasconn = NULL; /* do not wait for on error */
}
}
/* RAS does not allow to quit directly after HangUp (see docs) */
dwLastTickCount = GetTickCount();
memset(&rcs, 0, sizeof(RASCONNSTATUS));
rcs.dwSize = sizeof(RASCONNSTATUS);
- for(dw=0; dw < dwConnItems; ++dw) {
+ for (dw = 0; dw < dwConnItems; ++dw) {
if (paConn[dw].hrasconn != NULL) {
- while(RasGetConnectStatus(paConn[dw].hrasconn, &rcs) != ERROR_INVALID_HANDLE) {
+ while (RasGetConnectStatus(paConn[dw].hrasconn, &rcs) != ERROR_INVALID_HANDLE) {
Sleep(0); /* give rest of time silce to other threads with equal priority */
/* infinite loop protection (3000ms defined in docs) */
dwRetries = GetTickCount();
- if (dwRetries - dwLastTickCount>3000)
+ if (dwRetries - dwLastTickCount > 3000)
break; /* wraparound works */
}
}
@@ -233,21 +235,21 @@ static DWORD ShutdownNow(BYTE shutdownType)
case SDSDT_REBOOT:
case SDSDT_SHUTDOWN:
if (GetSystemMetrics(SM_SHUTTINGDOWN)) { /* Win2000+, 0 on error */
- dwErrCode=ERROR_SHUTDOWN_IN_PROGRESS;
+ dwErrCode = ERROR_SHUTDOWN_IN_PROGRESS;
break;
}
/* WinNT4/2000/XP */
{
- WinNT_SetPrivilege(SE_SHUTDOWN_NAME,TRUE);
+ WinNT_SetPrivilege(SE_SHUTDOWN_NAME, TRUE);
/* does not send out WM_ENDSESSION messages, so we do it manually to
* give the applications the chance to save their data */
- WinNT_SetPrivilege(SE_TCB_NAME,TRUE); /* for BSM_ALLDESKTOPS */
- BroadcastEndSession(BSM_APPLICATIONS|BSM_ALLDESKTOPS,ENDSESSION_CLOSEAPP); /* app should close itself */
- WinNT_SetPrivilege(SE_TCB_NAME,FALSE);
+ WinNT_SetPrivilege(SE_TCB_NAME, TRUE); /* for BSM_ALLDESKTOPS */
+ BroadcastEndSession(BSM_APPLICATIONS | BSM_ALLDESKTOPS, ENDSESSION_CLOSEAPP); /* app should close itself */
+ WinNT_SetPrivilege(SE_TCB_NAME, FALSE);
- if (!InitiateSystemShutdownEx(NULL,TranslateT("AutoShutdown"),0,TRUE,shutdownType==SDSDT_REBOOT,SHTDN_REASON_MAJOR_OTHER|SHTDN_REASON_MINOR_OTHER|SHTDN_REASON_FLAG_PLANNED))
- dwErrCode=GetLastError();
+ if (!InitiateSystemShutdownEx(NULL, TranslateT("AutoShutdown"), 0, TRUE, shutdownType == SDSDT_REBOOT, SHTDN_REASON_MAJOR_OTHER | SHTDN_REASON_MINOR_OTHER | SHTDN_REASON_FLAG_PLANNED))
+ dwErrCode = GetLastError();
/* cleanly close Miranda */
if (!dwErrCode) ShutdownNow(SDSDT_CLOSEMIRANDA);
@@ -257,20 +259,20 @@ static DWORD ShutdownNow(BYTE shutdownType)
case SDSDT_LOGOFF:
{
UINT flags;
- switch(shutdownType) {
- case SDSDT_LOGOFF: flags=EWX_LOGOFF; break;
- case SDSDT_REBOOT: flags=EWX_REBOOT; break;
- default: flags=EWX_SHUTDOWN|EWX_POWEROFF;
+ switch (shutdownType) {
+ case SDSDT_LOGOFF: flags = EWX_LOGOFF; break;
+ case SDSDT_REBOOT: flags = EWX_REBOOT; break;
+ default: flags = EWX_SHUTDOWN | EWX_POWEROFF;
}
if (shutdownType == SDSDT_LOGOFF && !IsWorkstationLocked())
flags |= EWX_FORCEIFHUNG; /* only considered for WM_ENDSESSION messages */
else
- flags|= EWX_FORCE; /* must be used when workstation locked */
+ flags |= EWX_FORCE; /* must be used when workstation locked */
if (flags & EWX_FORCE) {
/* EWX_FORCE does not send out WM_ENDSESSION messages, so we do it
* manually to give the applications the chance to save their data */
- BroadcastEndSession(BSM_APPLICATIONS,(shutdownType==SDSDT_LOGOFF)?ENDSESSION_LOGOFF:0);
+ BroadcastEndSession(BSM_APPLICATIONS, (shutdownType == SDSDT_LOGOFF) ? ENDSESSION_LOGOFF : 0);
/* Windows Me/98/95 (msdn): Because of the design of the shell,
* calling ExitWindowsEx with EWX_FORCE fails to completely log off
@@ -279,7 +281,7 @@ static DWORD ShutdownNow(BYTE shutdownType)
* To log off the user forcibly, terminate the Explorer process before calling
* ExitWindowsEx with EWX_LOGOFF and EWX_FORCE. */
}
- if (!ExitWindowsEx(flags,SHTDN_REASON_MAJOR_OTHER|SHTDN_REASON_MINOR_OTHER|SHTDN_REASON_FLAG_PLANNED))
+ if (!ExitWindowsEx(flags, SHTDN_REASON_MAJOR_OTHER | SHTDN_REASON_MINOR_OTHER | SHTDN_REASON_FLAG_PLANNED))
dwErrCode = GetLastError();
/* cleanly close Miranda */
if (!dwErrCode)
@@ -294,69 +296,72 @@ static DWORD ShutdownNow(BYTE shutdownType)
#define M_START_SHUTDOWN (WM_APP+111)
#define M_UPDATE_COUNTDOWN (WM_APP+112)
-static INT_PTR CALLBACK ShutdownDlgProc(HWND hwndDlg,UINT msg,WPARAM wParam,LPARAM lParam)
+static INT_PTR CALLBACK ShutdownDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
- BYTE shutdownType=(BYTE)GetWindowLongPtr(hwndDlg, DWLP_USER);
- WORD countdown=(WORD)GetWindowLongPtr(GetDlgItem(hwndDlg, IDC_TEXT_HEADER), GWLP_USERDATA);
+ BYTE shutdownType = (BYTE)GetWindowLongPtr(hwndDlg, DWLP_USER);
+ WORD countdown = (WORD)GetWindowLongPtr(GetDlgItem(hwndDlg, IDC_TEXT_HEADER), GWLP_USERDATA);
- switch(msg) {
+ switch (msg) {
case WM_INITDIALOG:
- hwndShutdownDlg=hwndDlg;
+ hwndShutdownDlg = hwndDlg;
SetWindowLongPtr(hwndDlg, DWLP_USER, (LONG_PTR)lParam);
TranslateDialogDefault(hwndDlg);
- if (lParam==SDSDT_SHUTDOWN || lParam==SDSDT_REBOOT || lParam==SDSDT_LOGOFF)
- ShowWindow(GetDlgItem(hwndDlg,IDC_TEXT_UNSAVEDWARNING),SW_SHOW);
- SendDlgItemMessage(hwndDlg,IDC_ICON_HEADER,STM_SETIMAGE,IMAGE_ICON,(LPARAM)IcoLib_GetIcon("AutoShutdown_Header"));
+ if (lParam == SDSDT_SHUTDOWN || lParam == SDSDT_REBOOT || lParam == SDSDT_LOGOFF)
+ ShowWindow(GetDlgItem(hwndDlg, IDC_TEXT_UNSAVEDWARNING), SW_SHOW);
+ 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);
+ 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);
+ else hBoldFont = NULL;
+ SendDlgItemMessage(hwndDlg, IDC_TEXT_HEADER, WM_SETFONT, (WPARAM)hBoldFont, FALSE);
SetWindowLongPtr(GetDlgItem(hwndDlg, IDC_TEXT_HEADER), GWLP_USERDATA, (LONG_PTR)hBoldFont);
}
{
- WORD countdown=db_get_w(NULL,"AutoShutdown","ConfirmDlgCountdown",SETTING_CONFIRMDLGCOUNTDOWN_DEFAULT);
- if (countdown<3) countdown=SETTING_CONFIRMDLGCOUNTDOWN_DEFAULT;
+ countdown = db_get_w(NULL, "AutoShutdown", "ConfirmDlgCountdown", SETTING_CONFIRMDLGCOUNTDOWN_DEFAULT);
+ if (countdown < 3)
+ countdown = SETTING_CONFIRMDLGCOUNTDOWN_DEFAULT;
SetWindowLongPtr(GetDlgItem(hwndDlg, IDC_TEXT_HEADER), GWLP_USERDATA, countdown);
- SendMessage(hwndDlg,M_UPDATE_COUNTDOWN,0,countdown);
+ SendMessage(hwndDlg, M_UPDATE_COUNTDOWN, 0, countdown);
}
SkinPlaySound("AutoShutdown_Countdown");
- if (!SetTimer(hwndDlg,1,1000,NULL)) PostMessage(hwndDlg,M_START_SHUTDOWN,0,0);
- Utils_RestoreWindowPositionNoSize(hwndDlg,NULL,"AutoShutdown","ConfirmDlg_");
+ if (!SetTimer(hwndDlg, 1, 1000, NULL))
+ PostMessage(hwndDlg, M_START_SHUTDOWN, 0, 0);
+
+ Utils_RestoreWindowPositionNoSize(hwndDlg, NULL, "AutoShutdown", "ConfirmDlg_");
/* disallow foreground window changes (WinMe/2000+) */
SetForegroundWindow(hwndDlg);
LockSetForegroundWindow(LSFW_LOCK);
- SendMessage(hwndDlg,WM_NEXTDLGCTL,(WPARAM)GetDlgItem(hwndDlg,IDCANCEL),TRUE);
+ SendMessage(hwndDlg, WM_NEXTDLGCTL, (WPARAM)GetDlgItem(hwndDlg, IDCANCEL), TRUE);
return FALSE; /* focus set on cancel */
case WM_DESTROY:
{
- hwndShutdownDlg=NULL;
- ShowWindow(hwndDlg,SW_HIDE);
+ hwndShutdownDlg = NULL;
+ ShowWindow(hwndDlg, SW_HIDE);
/* reallow foreground window changes (WinMe/2000+) */
LockSetForegroundWindow(LSFW_UNLOCK);
- Utils_SaveWindowPosition(hwndDlg,NULL,"AutoShutdown","ConfirmDlg_");
- HFONT hFont=(HFONT)SendDlgItemMessage(hwndDlg,IDC_TEXT_HEADER,WM_GETFONT,0,0);
- SendDlgItemMessage(hwndDlg,IDC_TEXT_HEADER,WM_SETFONT,0,FALSE); /* no return value */
+ Utils_SaveWindowPosition(hwndDlg, NULL, "AutoShutdown", "ConfirmDlg_");
+ 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);
}
return TRUE;
case M_START_SHUTDOWN:
- if (IsWindowEnabled(GetDlgItem(hwndDlg,IDC_BUTTON_SHUTDOWNNOW))) {
- EnableWindow(GetDlgItem(hwndDlg,IDC_BUTTON_SHUTDOWNNOW),FALSE);
- ShowWindow(hwndDlg,SW_HIDE); /* get rid of the dialog immediately */
- DWORD dwErrCode=ShutdownNow(shutdownType);
+ if (IsWindowEnabled(GetDlgItem(hwndDlg, IDC_BUTTON_SHUTDOWNNOW))) {
+ EnableWindow(GetDlgItem(hwndDlg, IDC_BUTTON_SHUTDOWNNOW), FALSE);
+ ShowWindow(hwndDlg, SW_HIDE); /* get rid of the dialog immediately */
+ DWORD dwErrCode = ShutdownNow(shutdownType);
if (dwErrCode != ERROR_SUCCESS) {
- char *pszErr=GetWinErrorDescription(dwErrCode);
- ShowInfoMessage(NIIF_ERROR,Translate("Automatic Shutdown Error"),Translate("The shutdown process failed!\nReason: %s"),(pszErr != NULL)?pszErr:Translate("Unknown"));
+ char *pszErr = GetWinErrorDescription(dwErrCode);
+ ShowInfoMessage(NIIF_ERROR, Translate("Automatic Shutdown Error"), Translate("The shutdown process failed!\nReason: %s"), (pszErr != NULL) ? pszErr : Translate("Unknown"));
if (pszErr != NULL) LocalFree(pszErr);
}
DestroyWindow(hwndDlg);
@@ -367,37 +372,37 @@ static INT_PTR CALLBACK ShutdownDlgProc(HWND hwndDlg,UINT msg,WPARAM wParam,LPAR
if (countdown) {
--countdown;
SetWindowLongPtr(GetDlgItem(hwndDlg, IDC_TEXT_HEADER), GWLP_USERDATA, countdown);
- if (countdown==27 || countdown==24 || countdown==21 || countdown==19 ||
- countdown==17 || countdown==15 || countdown==13 || countdown==11 ||
- countdown<=10)
+ if (countdown == 27 || countdown == 24 || countdown == 21 || countdown == 19 ||
+ countdown == 17 || countdown == 15 || countdown == 13 || countdown == 11 ||
+ countdown <= 10)
SkinPlaySound("AutoShutdown_Countdown");
}
- else KillTimer(hwndDlg,wParam); /* countdown finished */
- PostMessage(hwndDlg,M_UPDATE_COUNTDOWN,0,countdown);
+ else KillTimer(hwndDlg, wParam); /* countdown finished */
+ PostMessage(hwndDlg, M_UPDATE_COUNTDOWN, 0, countdown);
return TRUE;
case M_UPDATE_COUNTDOWN: /* lParam=(WORD)countdown */
{
TCHAR szText[256];
- mir_sntprintf(szText,_countof(szText),TranslateTS(desc[shutdownType-1]),lParam);
- SetDlgItemText(hwndDlg,IDC_TEXT_HEADER,szText);
+ mir_sntprintf(szText, _countof(szText), TranslateTS(desc[shutdownType - 1]), lParam);
+ SetDlgItemText(hwndDlg, IDC_TEXT_HEADER, szText);
/* countdown finished */
if (!lParam)
- PostMessage(hwndDlg,M_START_SHUTDOWN,0,0);
+ PostMessage(hwndDlg, M_START_SHUTDOWN, 0, 0);
}
return TRUE;
case WM_COMMAND:
- switch(LOWORD(wParam)) {
+ switch (LOWORD(wParam)) {
case IDC_BUTTON_SHUTDOWNNOW:
- KillTimer(hwndDlg,1);
+ KillTimer(hwndDlg, 1);
SetWindowLongPtr(GetDlgItem(hwndDlg, IDC_TEXT_HEADER), GWLP_USERDATA, 0);
- SendMessage(hwndDlg,M_UPDATE_COUNTDOWN,0,(LONG)0);
- PostMessage(hwndDlg,M_START_SHUTDOWN,0,0);
+ SendMessage(hwndDlg, M_UPDATE_COUNTDOWN, 0, (LONG)0);
+ PostMessage(hwndDlg, M_START_SHUTDOWN, 0, 0);
return TRUE;
case IDCANCEL: /* WM_CLOSE */
if (countdown) {
- KillTimer(hwndDlg,1);
+ KillTimer(hwndDlg, 1);
DestroyWindow(hwndDlg);
}
return TRUE;
@@ -409,22 +414,22 @@ static INT_PTR CALLBACK ShutdownDlgProc(HWND hwndDlg,UINT msg,WPARAM wParam,LPAR
/************************* Services ***********************************/
-INT_PTR ServiceShutdown(WPARAM wParam,LPARAM lParam)
+INT_PTR ServiceShutdown(WPARAM wParam, LPARAM lParam)
{
/* passing 0 as wParam is only to be used internally, undocumented */
- if (!wParam) wParam=db_get_b(NULL,"AutoShutdown","ShutdownType",SETTING_SHUTDOWNTYPE_DEFAULT);
+ if (!wParam) wParam = db_get_b(NULL, "AutoShutdown", "ShutdownType", SETTING_SHUTDOWNTYPE_DEFAULT);
if (!IsShutdownTypeEnabled((BYTE)wParam)) return 1; /* does shutdownType range check */
if ((BOOL)lParam && hwndShutdownDlg != NULL) return 2;
/* ask others if allowed */
- if (NotifyEventHooks(hEventOkToShutdown,wParam,lParam)) {
+ if (NotifyEventHooks(hEventOkToShutdown, wParam, lParam)) {
OutputDebugStringA("automatic shutdown denied by event hook\n"); /* all ascii */
return 3;
}
/* tell others */
- NotifyEventHooks(hEventShutdown,wParam,lParam);
+ NotifyEventHooks(hEventShutdown, wParam, lParam);
/* show dialog */
- if (lParam && db_get_b(NULL,"AutoShutdown","ShowConfirmDlg",SETTING_SHOWCONFIRMDLG_DEFAULT))
+ if (lParam && db_get_b(NULL, "AutoShutdown", "ShowConfirmDlg", SETTING_SHOWCONFIRMDLG_DEFAULT))
if (CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_SHUTDOWNNOW), NULL, ShutdownDlgProc, (BYTE)wParam) != NULL)
return 0;
/* show error */
@@ -432,7 +437,7 @@ INT_PTR ServiceShutdown(WPARAM wParam,LPARAM lParam)
DWORD dwErrCode = ShutdownNow((BYTE)wParam);
if (dwErrCode != ERROR_SUCCESS) {
char *pszErr = GetWinErrorDescription(dwErrCode);
- ShowInfoMessage(NIIF_ERROR,Translate("Automatic Shutdown Error"),Translate("Inititiating the shutdown process failed!\nReason: %s"),(pszErr != NULL)?pszErr:Translate("Unknown"));
+ ShowInfoMessage(NIIF_ERROR, Translate("Automatic Shutdown Error"), Translate("Inititiating the shutdown process failed!\nReason: %s"), (pszErr != NULL) ? pszErr : Translate("Unknown"));
if (pszErr != NULL)
LocalFree(pszErr);
return 4;
@@ -441,7 +446,7 @@ INT_PTR ServiceShutdown(WPARAM wParam,LPARAM lParam)
return 0;
}
-INT_PTR ServiceIsTypeEnabled(WPARAM wParam,LPARAM)
+INT_PTR ServiceIsTypeEnabled(WPARAM wParam, LPARAM)
{
return IsShutdownTypeEnabled((BYTE)wParam); /* does shutdownType range check */
}
@@ -466,19 +471,19 @@ const TCHAR *apszLong[] = {
LPGENT("Sets all protocols to offline and closes all RAS connections.")
};
-INT_PTR ServiceGetTypeDescription(WPARAM wParam,LPARAM lParam)
+INT_PTR ServiceGetTypeDescription(WPARAM wParam, LPARAM lParam)
{
/* shutdownType range check */
- if (!wParam || (BYTE)wParam>SDSDT_MAX) return 0;
+ if (!wParam || (BYTE)wParam > SDSDT_MAX) return 0;
/* select description */
- TCHAR *pszDesc=(TCHAR*)((lParam&GSTDF_LONGDESC)?apszLong:apszShort)[wParam-1];
- if (!(lParam&GSTDF_UNTRANSLATED)) pszDesc=TranslateTS(pszDesc);
+ TCHAR *pszDesc = (TCHAR*)((lParam&GSTDF_LONGDESC) ? apszLong : apszShort)[wParam - 1];
+ if (!(lParam&GSTDF_UNTRANSLATED)) pszDesc = TranslateTS(pszDesc);
/* convert as needed */
if (!(lParam&GSTDF_UNICODE)) {
static char szConvBuf[128];
- char *buf=u2a(pszDesc);
- if (buf==NULL) return 0;
- mir_strncpy(szConvBuf,buf,sizeof(szConvBuf));
+ char *buf = u2a(pszDesc);
+ if (buf == NULL) return 0;
+ mir_strncpy(szConvBuf, buf, sizeof(szConvBuf));
mir_free(buf);
return (INT_PTR)szConvBuf;
}
@@ -490,13 +495,13 @@ INT_PTR ServiceGetTypeDescription(WPARAM wParam,LPARAM lParam)
void InitShutdownSvc(void)
{
/* Shutdown Dialog */
- hwndShutdownDlg=NULL;
- SkinAddNewSoundExT("AutoShutdown_Countdown",LPGENT("Alerts"),LPGENT("Automatic Shutdown Countdown"));
+ hwndShutdownDlg = NULL;
+ SkinAddNewSoundExT("AutoShutdown_Countdown", LPGENT("Alerts"), LPGENT("Automatic Shutdown Countdown"));
/* Events */
hEventOkToShutdown = CreateHookableEvent(ME_AUTOSHUTDOWN_OKTOSHUTDOWN);
hEventShutdown = CreateHookableEvent(ME_AUTOSHUTDOWN_SHUTDOWN);
-
+
/* Services */
CreateServiceFunction(MS_AUTOSHUTDOWN_SHUTDOWN, ServiceShutdown);
CreateServiceFunction(MS_AUTOSHUTDOWN_ISTYPEENABLED, ServiceIsTypeEnabled);
diff --git a/plugins/AutoShutdown/src/utils.cpp b/plugins/AutoShutdown/src/utils.cpp
index d866eadd83..2d8de89575 100644
--- a/plugins/AutoShutdown/src/utils.cpp
+++ b/plugins/AutoShutdown/src/utils.cpp
@@ -26,19 +26,21 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
// mir_free() the return value
char* u2a(const WCHAR *pszUnicode)
{
- int codepage,cch;
- char *psz;
- DWORD flags;
+ if (pszUnicode == NULL)
+ return NULL;
+
+ int codepage = Langpack_GetDefaultCodePage();
- if (pszUnicode==NULL) return NULL;
- codepage = Langpack_GetDefaultCodePage();
/* without WC_COMPOSITECHECK some characters might get out strange (see MS blog) */
- cch=WideCharToMultiByte(codepage,flags=WC_COMPOSITECHECK,pszUnicode,-1,NULL,0,NULL,NULL);
- if (!cch) cch=WideCharToMultiByte(codepage,flags=0,pszUnicode,-1,NULL,0,NULL,NULL);
- if (!cch) return NULL;
+ DWORD flags;
+ int cch = WideCharToMultiByte(codepage, flags = WC_COMPOSITECHECK, pszUnicode, -1, NULL, 0, NULL, NULL);
+ if (!cch)
+ cch = WideCharToMultiByte(codepage, flags = 0, pszUnicode, -1, NULL, 0, NULL, NULL);
+ if (!cch)
+ return NULL;
- psz=(char*)mir_alloc(cch);
- if (psz != NULL && !WideCharToMultiByte(codepage,flags,pszUnicode,-1,psz,cch,NULL,NULL)){
+ char *psz = (char*)mir_alloc(cch);
+ if (psz != NULL && !WideCharToMultiByte(codepage, flags, pszUnicode, -1, psz, cch, NULL, NULL)) {
mir_free(psz);
return NULL;
}
@@ -47,18 +49,18 @@ char* u2a(const WCHAR *pszUnicode)
void TrimString(TCHAR *pszStr)
{
- int i;
- TCHAR *psz,szChars[]=_T(" \r\n\t");
- for(i=0;i<_countof(szChars);++i) {
+ TCHAR *psz, szChars[] = _T(" \r\n\t");
+ for (int i = 0; i < _countof(szChars); ++i) {
/* trim end */
- psz=&pszStr[mir_tstrlen(pszStr)-1];
- while(pszStr[0] && *psz==szChars[i]) {
- *psz=0;
- psz=CharPrev(pszStr,psz);
+ psz = &pszStr[mir_tstrlen(pszStr) - 1];
+ while (pszStr[0] && *psz == szChars[i]) {
+ *psz = 0;
+ psz = CharPrev(pszStr, psz);
}
/* trim beginning */
- for(psz=pszStr;(*psz && *psz==szChars[i]);psz=CharNext(psz));
- memmove(pszStr,psz,(mir_tstrlen(psz)+1)*sizeof(TCHAR));
+ for (psz = pszStr; (*psz && *psz == szChars[i]); psz = CharNext(psz))
+ ;
+ memmove(pszStr, psz, (mir_tstrlen(psz) + 1)*sizeof(TCHAR));
}
}
@@ -73,39 +75,38 @@ static void MessageBoxIndirectFree(void *param)
mir_free(mbp);
}
-void ShowInfoMessage(BYTE flags,const char *pszTitle,const char *pszTextFmt,...)
+void ShowInfoMessage(BYTE flags, const char *pszTitle, const char *pszTextFmt, ...)
{
char szText[256]; /* max for systray */
- MSGBOXPARAMSA *mbp;
va_list va;
- va_start(va,pszTextFmt);
- mir_vsnprintf(szText,_countof(szText),pszTextFmt,va);
+ va_start(va, pszTextFmt);
+ mir_vsnprintf(szText, _countof(szText), pszTextFmt, va);
va_end(va);
if (ServiceExists(MS_CLIST_SYSTRAY_NOTIFY)) {
MIRANDASYSTRAYNOTIFY msn;
- msn.cbSize=sizeof(msn);
- msn.szProto=NULL;
- msn.szInfoTitle=(char*)pszTitle;
- msn.szInfo=(char*)szText;
- msn.uTimeout=30000; /* max timeout */
- msn.dwInfoFlags=flags;
- if (!CallServiceSync(MS_CLIST_SYSTRAY_NOTIFY,0,(LPARAM)&msn))
+ msn.cbSize = sizeof(msn);
+ msn.szProto = NULL;
+ msn.szInfoTitle = (char*)pszTitle;
+ msn.szInfo = (char*)szText;
+ msn.uTimeout = 30000; /* max timeout */
+ msn.dwInfoFlags = flags;
+ if (!CallServiceSync(MS_CLIST_SYSTRAY_NOTIFY, 0, (LPARAM)&msn))
return; /* success */
}
- mbp=(MSGBOXPARAMSA*)mir_calloc(sizeof(*mbp));
- if (mbp==NULL) return;
+ MSGBOXPARAMSA *mbp = (MSGBOXPARAMSA*)mir_calloc(sizeof(*mbp));
+ if (mbp == NULL) return;
mbp->cbSize = sizeof(*mbp);
mbp->lpszCaption = mir_strdup(pszTitle);
mbp->lpszText = mir_strdup(szText);
- mbp->dwStyle = MB_OK|MB_SETFOREGROUND|MB_TASKMODAL;
+ mbp->dwStyle = MB_OK | MB_SETFOREGROUND | MB_TASKMODAL;
mbp->dwLanguageId = LANGIDFROMLCID(Langpack_GetDefaultLocale());
- switch(flags&NIIF_ICON_MASK) {
- case NIIF_INFO: mbp->dwStyle|=MB_ICONINFORMATION; break;
- case NIIF_WARNING: mbp->dwStyle|=MB_ICONWARNING; break;
- case NIIF_ERROR: mbp->dwStyle|=MB_ICONERROR;
+ switch (flags&NIIF_ICON_MASK) {
+ case NIIF_INFO: mbp->dwStyle |= MB_ICONINFORMATION; break;
+ case NIIF_WARNING: mbp->dwStyle |= MB_ICONWARNING; break;
+ case NIIF_ERROR: mbp->dwStyle |= MB_ICONERROR;
}
mir_forkthread(MessageBoxIndirectFree, mbp);
}
@@ -113,17 +114,17 @@ void ShowInfoMessage(BYTE flags,const char *pszTitle,const char *pszTextFmt,...)
// LocalFree() the return value
char* GetWinErrorDescription(DWORD dwLastError)
{
- char *buf=NULL;
- DWORD flags=FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM;
- if (!FormatMessageA(flags,NULL,dwLastError,LANGIDFROMLCID(Langpack_GetDefaultLocale()),(char*)&buf,0,NULL))
- if (GetLastError()==ERROR_RESOURCE_LANG_NOT_FOUND)
- FormatMessageA(flags,NULL,dwLastError,0,(char*)&buf,0,NULL);
+ char *buf = NULL;
+ DWORD flags = FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM;
+ if (!FormatMessageA(flags, NULL, dwLastError, LANGIDFROMLCID(Langpack_GetDefaultLocale()), (char*)&buf, 0, NULL))
+ if (GetLastError() == ERROR_RESOURCE_LANG_NOT_FOUND)
+ FormatMessageA(flags, NULL, dwLastError, 0, (char*)&buf, 0, NULL);
return buf;
}
/************************* Time ***********************************/
-BOOL SystemTimeToTimeStamp(SYSTEMTIME *st,time_t *timestamp)
+BOOL SystemTimeToTimeStamp(SYSTEMTIME *st, time_t *timestamp)
{
struct tm ts;
ts.tm_isdst = -1; /* daylight saving time (-1=compute) */
@@ -132,16 +133,16 @@ BOOL SystemTimeToTimeStamp(SYSTEMTIME *st,time_t *timestamp)
ts.tm_hour = st->wHour; /* 0-23 */
ts.tm_mday = st->wDay; /* 1-31 */
ts.tm_wday = st->wDayOfWeek; /* 0-6 (Sun-Sat) */
- ts.tm_mon = st->wMonth-1; /* 0-11 (Jan-Dec) */
- ts.tm_year = st->wYear-1900; /* current year minus 1900 */
- ts.tm_yday=0; /* 0-365 (Jan1=0) */
+ ts.tm_mon = st->wMonth - 1; /* 0-11 (Jan-Dec) */
+ ts.tm_year = st->wYear - 1900; /* current year minus 1900 */
+ ts.tm_yday = 0; /* 0-365 (Jan1=0) */
*timestamp = mktime(&ts);
return (*timestamp != -1);
}
-BOOL TimeStampToSystemTime(time_t timestamp,SYSTEMTIME *st)
+BOOL TimeStampToSystemTime(time_t timestamp, SYSTEMTIME *st)
{
- struct tm ts = {0};
+ struct tm ts = { 0 };
errno_t err = localtime_s(&ts, &timestamp); /* statically alloced, local time correction */
if (err != 0)
return FALSE;
@@ -152,52 +153,53 @@ BOOL TimeStampToSystemTime(time_t timestamp,SYSTEMTIME *st)
st->wHour = (WORD)ts.tm_hour; /* 0-23 */
st->wDay = (WORD)ts.tm_mday; /* 1-31 */
st->wDayOfWeek = (WORD)ts.tm_wday; /* 0-6 (Sun-Sat) */
- st->wMonth = (WORD)(ts.tm_mon+1); /* 1-12 (Jan-Dec) */
- st->wYear = (WORD)(ts.tm_year+1900); /* 1601-30827 */
+ st->wMonth = (WORD)(ts.tm_mon + 1); /* 1-12 (Jan-Dec) */
+ st->wYear = (WORD)(ts.tm_year + 1900); /* 1601-30827 */
return TRUE;
}
-BOOL GetFormatedCountdown(TCHAR *pszOut,int nSize,time_t countdown)
+BOOL GetFormatedCountdown(TCHAR *pszOut, int nSize, time_t countdown)
{
- static BOOL fInited=FALSE;
- static int (WINAPI *pfnGetDurationFormat)(LCID,DWORD,const SYSTEMTIME*,double,WCHAR*,WCHAR*,int);
+ static BOOL fInited = FALSE;
+ static int (WINAPI *pfnGetDurationFormat)(LCID, DWORD, const SYSTEMTIME*, double, WCHAR*, WCHAR*, int);
/* Init */
if (!fInited && IsWinVerVistaPlus()) {
- *(PROC*)&pfnGetDurationFormat=GetProcAddress(GetModuleHandleA("KERNEL32"),"GetDurationFormat");
- fInited=TRUE;
+ *(PROC*)&pfnGetDurationFormat = GetProcAddress(GetModuleHandleA("KERNEL32"), "GetDurationFormat");
+ fInited = TRUE;
}
+
/* WinVista */
if (pfnGetDurationFormat != NULL) {
SYSTEMTIME st;
LCID locale;
- locale=Langpack_GetDefaultLocale();
- if (TimeStampToSystemTime(countdown,&st))
- if (pfnGetDurationFormat(locale,0,&st,0,NULL,pszOut,nSize))
+ locale = Langpack_GetDefaultLocale();
+ if (TimeStampToSystemTime(countdown, &st))
+ if (pfnGetDurationFormat(locale, 0, &st, 0, NULL, pszOut, nSize))
return TRUE;
return FALSE;
}
/* Win9x/NT/XP */
- return StrFromTimeInterval(pszOut,nSize,(countdown>(MAXDWORD/1000))?MAXDWORD:(countdown*1000),10) != 0;
+ return StrFromTimeInterval(pszOut, nSize, (countdown > (MAXDWORD / 1000)) ? MAXDWORD : (countdown * 1000), 10) != 0;
}
-BOOL GetFormatedDateTime(TCHAR *pszOut,int nSize,time_t timestamp,BOOL fShowDateEvenToday)
+BOOL GetFormatedDateTime(TCHAR *pszOut, int nSize, time_t timestamp, BOOL fShowDateEvenToday)
{
- SYSTEMTIME st,stNow;
- LCID locale;
- locale=Langpack_GetDefaultLocale();
+ SYSTEMTIME st, stNow;
+ LCID locale = Langpack_GetDefaultLocale();
GetLocalTime(&stNow);
- TimeStampToSystemTime(timestamp,&st);
+ TimeStampToSystemTime(timestamp, &st);
/* today: no need to show the date */
- if (!fShowDateEvenToday && st.wDay==stNow.wDay && st.wMonth==stNow.wMonth && st.wYear==stNow.wYear)
- return GetTimeFormat(locale,((st.wSecond==0)?TIME_NOSECONDS:0)|TIME_FORCE24HOURFORMAT,&st,NULL,pszOut,nSize) != 0;
+ if (!fShowDateEvenToday && st.wDay == stNow.wDay && st.wMonth == stNow.wMonth && st.wYear == stNow.wYear)
+ return GetTimeFormat(locale, ((st.wSecond == 0) ? TIME_NOSECONDS : 0) | TIME_FORCE24HOURFORMAT, &st, NULL, pszOut, nSize) != 0;
/* show both date and time */
- { TCHAR szDate[128],szTime[128];
- if (!GetTimeFormat(locale,((st.wSecond==0)?TIME_NOSECONDS:0)|TIME_FORCE24HOURFORMAT,&st,NULL,szTime,_countof(szTime)))
+ {
+ TCHAR szDate[128], szTime[128];
+ if (!GetTimeFormat(locale, ((st.wSecond == 0) ? TIME_NOSECONDS : 0) | TIME_FORCE24HOURFORMAT, &st, NULL, szTime, _countof(szTime)))
return FALSE;
- if (!GetDateFormat(locale,DATE_SHORTDATE,&st,NULL,szDate,_countof(szDate)))
+ if (!GetDateFormat(locale, DATE_SHORTDATE, &st, NULL, szDate, _countof(szDate)))
return FALSE;
- mir_sntprintf(pszOut,nSize,_T("%s %s"),szTime,szDate);
+ mir_sntprintf(pszOut, nSize, _T("%s %s"), szTime, szDate);
return TRUE;
}
}
@@ -206,7 +208,7 @@ BOOL GetFormatedDateTime(TCHAR *pszOut,int nSize,time_t timestamp,BOOL fShowDate
void AddHotkey()
{
- HOTKEYDESC hkd = {0};
+ HOTKEYDESC hkd = { 0 };
hkd.cbSize = sizeof(hkd);
hkd.dwFlags = HKD_TCHAR;
hkd.pszName = "AutoShutdown_Toggle";
diff --git a/plugins/AutoShutdown/src/watcher.cpp b/plugins/AutoShutdown/src/watcher.cpp
index f8194f3394..32fba6793e 100644
--- a/plugins/AutoShutdown/src/watcher.cpp
+++ b/plugins/AutoShutdown/src/watcher.cpp
@@ -32,7 +32,7 @@ static HANDLE hHookSettingChanged;
/* Weather Shutdown */
static HANDLE hHookWeatherUpdated;
/* Services */
-static HANDLE hServiceStartWatcher,hServiceStopWatcher,hServiceIsEnabled;
+static HANDLE hServiceStartWatcher, hServiceStopWatcher, hServiceIsEnabled;
static HANDLE hEventWatcherChanged;
/* Misc */
static HANDLE hHookModulesLoaded;
@@ -44,18 +44,18 @@ static WORD currentWatcherType;
static void __stdcall MainThreadMapping(void *param)
{
HANDLE *phDoneEvent = (HANDLE*)param;
- ServiceShutdown(0,TRUE); /* ensure main thread (for cpu usage shutdown) */
- ServiceStopWatcher(0,0);
+ ServiceShutdown(0, TRUE); /* ensure main thread (for cpu usage shutdown) */
+ ServiceStopWatcher(0, 0);
if (*phDoneEvent != NULL)
SetEvent(*phDoneEvent);
}
static void __inline ShutdownAndStopWatcher(void)
{
- HANDLE hDoneEvent = CreateEvent(NULL,FALSE,FALSE,NULL);
+ HANDLE hDoneEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
CallFunctionAsync(MainThreadMapping, &hDoneEvent);
if (hDoneEvent != NULL) {
- WaitForSingleObject(hDoneEvent,INFINITE);
+ WaitForSingleObject(hDoneEvent, INFINITE);
CloseHandle(hDoneEvent);
}
}
@@ -63,29 +63,29 @@ static void __inline ShutdownAndStopWatcher(void)
/************************* Msg Shutdown *******************************/
// ppBlob might get reallocated, must have been allocated using mir_alloc()
-static TCHAR* GetMessageText(BYTE **ppBlob,DWORD *pcbBlob)
+static TCHAR* GetMessageText(BYTE **ppBlob, DWORD *pcbBlob)
{
- (*ppBlob)[*pcbBlob]=0;
+ (*ppBlob)[*pcbBlob] = 0;
size_t cb = mir_strlen((char*)*ppBlob);
/* use Unicode data if present */
- if (*pcbBlob>(cb+3)) {
- (*ppBlob)[*pcbBlob-1]=0;
+ if (*pcbBlob > (cb + 3)) {
+ (*ppBlob)[*pcbBlob - 1] = 0;
return (WCHAR*)&(*ppBlob)[cb];
}
/* no Unicode data present, convert from ANSI */
- int len = MultiByteToWideChar(CP_ACP,0,(char*)*ppBlob,-1,NULL,0);
+ int len = MultiByteToWideChar(CP_ACP, 0, (char*)*ppBlob, -1, NULL, 0);
if (!len)
return NULL;
- BYTE *buf=(BYTE*)mir_realloc(*ppBlob,(*pcbBlob)+(len*sizeof(WCHAR)));
+ BYTE *buf = (BYTE*)mir_realloc(*ppBlob, (*pcbBlob) + (len*sizeof(WCHAR)));
if (buf == NULL)
return NULL;
*pcbBlob += len*sizeof(WCHAR);
*ppBlob = buf;
buf = &(*ppBlob)[cb];
- MultiByteToWideChar(CP_ACP,0,(char*)*ppBlob,-1,(WCHAR*)buf,len);
- ((WCHAR*)buf)[len-1] = 0;
+ MultiByteToWideChar(CP_ACP, 0, (char*)*ppBlob, -1, (WCHAR*)buf, len);
+ ((WCHAR*)buf)[len - 1] = 0;
return (WCHAR*)buf;
}
@@ -94,16 +94,16 @@ static int MsgEventAdded(WPARAM, LPARAM hDbEvent)
if (currentWatcherType & SDWTF_MESSAGE) {
DBEVENTINFO dbe = { sizeof(dbe) };
dbe.cbBlob = db_event_getBlobSize(hDbEvent);
- dbe.pBlob = (BYTE*)mir_alloc(dbe.cbBlob+2); /* ensure term zero */
+ dbe.pBlob = (BYTE*)mir_alloc(dbe.cbBlob + 2); /* ensure term zero */
if (dbe.pBlob == NULL)
return 0;
if (!db_event_get(hDbEvent, &dbe))
if (dbe.eventType == EVENTTYPE_MESSAGE && !(dbe.flags & DBEF_SENT)) {
DBVARIANT dbv;
- if (!db_get_ts(NULL,"AutoShutdown","Message",&dbv)) {
+ if (!db_get_ts(NULL, "AutoShutdown", "Message", &dbv)) {
TrimString(dbv.ptszVal);
- TCHAR *pszMsg = GetMessageText(&dbe.pBlob,&dbe.cbBlob);
- if (pszMsg != NULL && _tcsstr(pszMsg,dbv.ptszVal) != NULL)
+ TCHAR *pszMsg = GetMessageText(&dbe.pBlob, &dbe.cbBlob);
+ if (pszMsg != NULL && _tcsstr(pszMsg, dbv.ptszVal) != NULL)
ShutdownAndStopWatcher(); /* msg with specified text recvd */
mir_free(dbv.ptszVal); /* does NULL check */
}
@@ -120,18 +120,18 @@ static int nTransfersCount;
static int ProtoAck(WPARAM, LPARAM lParam)
{
- ACKDATA *ack=(ACKDATA*)lParam;
+ ACKDATA *ack = (ACKDATA*)lParam;
if (ack->type != ACKTYPE_FILE)
return 0;
- switch(ack->result) {
+ switch (ack->result) {
case ACKRESULT_DATA:
{
- for(int i=0; i < nTransfersCount; ++i)
- if (transfers[i]==ack->hProcess)
+ for (int i = 0; i < nTransfersCount; ++i)
+ if (transfers[i] == ack->hProcess)
break; /* already in list */
/* insert into list */
- HANDLE *buf = (HANDLE*)mir_realloc(transfers,(nTransfersCount+1)*sizeof(HANDLE));
+ HANDLE *buf = (HANDLE*)mir_realloc(transfers, (nTransfersCount + 1)*sizeof(HANDLE));
if (buf != NULL) {
transfers = buf;
transfers[nTransfersCount] = ack->hProcess;
@@ -142,15 +142,15 @@ static int ProtoAck(WPARAM, LPARAM lParam)
case ACKRESULT_SUCCESS:
case ACKRESULT_FAILED:
case ACKRESULT_DENIED:
- for(int i=0;i<nTransfersCount;++i) {
- if (transfers[i]==ack->hProcess) {
+ for (int i = 0; i < nTransfersCount; ++i) {
+ if (transfers[i] == ack->hProcess) {
/* remove from list */
- if (i<(nTransfersCount-1))
- memmove(&transfers[i],&transfers[i+1],(nTransfersCount-i-1)*sizeof(HANDLE));
+ if (i < (nTransfersCount - 1))
+ memmove(&transfers[i], &transfers[i + 1], (nTransfersCount - i - 1)*sizeof(HANDLE));
--nTransfersCount;
- HANDLE *buf = (HANDLE*)mir_realloc(transfers,nTransfersCount*sizeof(HANDLE));
- if (buf != NULL) transfers=buf;
- else if (!nTransfersCount) transfers=NULL;
+ HANDLE *buf = (HANDLE*)mir_realloc(transfers, nTransfersCount*sizeof(HANDLE));
+ if (buf != NULL) transfers = buf;
+ else if (!nTransfersCount) transfers = NULL;
/* stop watcher */
if (!nTransfersCount && (currentWatcherType&SDWTF_FILETRANSFER))
ShutdownAndStopWatcher();
@@ -164,7 +164,7 @@ static int ProtoAck(WPARAM, LPARAM lParam)
/************************* Idle Shutdown ******************************/
-static int IdleChanged(WPARAM,LPARAM lParam)
+static int IdleChanged(WPARAM, LPARAM lParam)
{
if (currentWatcherType&SDWTF_IDLE && lParam&IDF_ISIDLE)
ShutdownAndStopWatcher();
@@ -175,18 +175,18 @@ static int IdleChanged(WPARAM,LPARAM lParam)
static BOOL CheckAllContactsOffline(void)
{
- BOOL fSmartCheck,fAllOffline=TRUE; /* tentatively */
- fSmartCheck=db_get_b(NULL,"AutoShutdown","SmartOfflineCheck",SETTING_SMARTOFFLINECHECK_DEFAULT);
+ BOOL fSmartCheck, fAllOffline = TRUE; /* tentatively */
+ fSmartCheck = db_get_b(NULL, "AutoShutdown", "SmartOfflineCheck", SETTING_SMARTOFFLINECHECK_DEFAULT);
for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) {
char *pszProto = GetContactProto(hContact);
if (pszProto != NULL && CallProtoService(pszProto, PS_GETSTATUS, 0, 0) != ID_STATUS_OFFLINE) {
- if (db_get_b(hContact,pszProto,"ChatRoom",0)) continue;
- if (db_get_w(hContact,pszProto,"Status",0) != ID_STATUS_OFFLINE) {
+ if (db_get_b(hContact, pszProto, "ChatRoom", 0)) continue;
+ if (db_get_w(hContact, pszProto, "Status", 0) != ID_STATUS_OFFLINE) {
if (fSmartCheck) {
- if (db_get_b(hContact,"CList","Hidden",0)) continue;
- if (db_get_b(hContact,"CList","NotOnList",0)) continue;
+ if (db_get_b(hContact, "CList", "Hidden", 0)) continue;
+ if (db_get_b(hContact, "CList", "NotOnList", 0)) continue;
}
- fAllOffline=FALSE;
+ fAllOffline = FALSE;
break;
}
}
@@ -194,13 +194,13 @@ static BOOL CheckAllContactsOffline(void)
return fAllOffline;
}
-static int StatusSettingChanged(WPARAM wParam,LPARAM lParam)
+static int StatusSettingChanged(WPARAM wParam, LPARAM lParam)
{
if (currentWatcherType&SDWTF_STATUS) {
- DBCONTACTWRITESETTING *dbcws=(DBCONTACTWRITESETTING*)lParam;
- if ((HANDLE)wParam != NULL && dbcws->value.wVal==ID_STATUS_OFFLINE && !mir_strcmp(dbcws->szSetting,"Status")) {
+ DBCONTACTWRITESETTING *dbcws = (DBCONTACTWRITESETTING*)lParam;
+ if ((HANDLE)wParam != NULL && dbcws->value.wVal == ID_STATUS_OFFLINE && !mir_strcmp(dbcws->szSetting, "Status")) {
char *pszProto = GetContactProto(wParam);
- if (pszProto != NULL && !mir_strcmp(dbcws->szModule,pszProto))
+ if (pszProto != NULL && !mir_strcmp(dbcws->szModule, pszProto))
if (CheckAllContactsOffline())
ShutdownAndStopWatcher();
}
@@ -212,19 +212,19 @@ static int StatusSettingChanged(WPARAM wParam,LPARAM lParam)
static DWORD idCpuUsageThread;
-static BOOL CALLBACK CpuUsageWatcherProc(BYTE nCpuUsage,LPARAM lParam)
+static BOOL CALLBACK CpuUsageWatcherProc(BYTE nCpuUsage, LPARAM lParam)
{
- static BYTE nTimesBelow=0; /* only one watcher thread */
+ static BYTE nTimesBelow = 0; /* only one watcher thread */
/* terminated? */
if (idCpuUsageThread != GetCurrentThreadId()) {
- nTimesBelow=0;
+ nTimesBelow = 0;
return FALSE; /* stop poll thread */
}
/* ignore random peaks */
- if (nCpuUsage<(BYTE)lParam) ++nTimesBelow;
- else nTimesBelow=0;
- if (nTimesBelow==3) {
- nTimesBelow=0;
+ if (nCpuUsage < (BYTE)lParam) ++nTimesBelow;
+ else nTimesBelow = 0;
+ if (nTimesBelow == 3) {
+ nTimesBelow = 0;
ShutdownAndStopWatcher();
return FALSE; /* stop poll thread */
}
@@ -233,12 +233,12 @@ static BOOL CALLBACK CpuUsageWatcherProc(BYTE nCpuUsage,LPARAM lParam)
/************************* Weather Shutdown ***************************/
-static int WeatherUpdated(WPARAM wParam,LPARAM lParam)
+static int WeatherUpdated(WPARAM wParam, LPARAM lParam)
{
char *pszProto = GetContactProto(wParam);
- if ((BOOL)lParam && pszProto != NULL && CallProtoService(pszProto,PS_GETSTATUS,0,0)==THUNDER)
- if (db_get_b(NULL,"AutoShutdown","WeatherShutdown",SETTING_WEATHERSHUTDOWN_DEFAULT))
- ServiceShutdown(SDSDT_SHUTDOWN,TRUE);
+ if ((BOOL)lParam && pszProto != NULL && CallProtoService(pszProto, PS_GETSTATUS, 0, 0) == THUNDER)
+ if (db_get_b(NULL, "AutoShutdown", "WeatherShutdown", SETTING_WEATHERSHUTDOWN_DEFAULT))
+ ServiceShutdown(SDSDT_SHUTDOWN, TRUE);
return 0;
}
@@ -247,8 +247,8 @@ static int WeatherUpdated(WPARAM wParam,LPARAM lParam)
INT_PTR ServiceStartWatcher(WPARAM, LPARAM lParam)
{
/* passing watcherType as lParam is only to be used internally, undocumented */
- if (lParam==0)
- lParam=(LPARAM)db_get_w(NULL,"AutoShutdown","WatcherFlags",0);
+ if (lParam == 0)
+ lParam = (LPARAM)db_get_w(NULL, "AutoShutdown", "WatcherFlags", 0);
/* invalid flags or empty? */
if (!(lParam&SDWTF_MASK))
@@ -258,26 +258,26 @@ INT_PTR ServiceStartWatcher(WPARAM, LPARAM lParam)
if (lParam&SDWTF_SPECIFICTIME && !(lParam&SDWTF_ST_MASK))
return 2;
- if (currentWatcherType==(WORD)lParam)
+ if (currentWatcherType == (WORD)lParam)
return 3;
if (currentWatcherType != 0) {
/* Time Shutdown */
CloseCountdownFrame(); /* fails if not opened */
/* Cpu Shutdown */
- idCpuUsageThread=0;
+ idCpuUsageThread = 0;
}
SetShutdownMenuItem(true);
SetShutdownToolbarButton(true);
- currentWatcherType=(WORD)lParam;
- NotifyEventHooks(hEventWatcherChanged,TRUE,0);
+ currentWatcherType = (WORD)lParam;
+ NotifyEventHooks(hEventWatcherChanged, TRUE, 0);
/* Time Shutdown */
if (currentWatcherType&SDWTF_SPECIFICTIME)
ShowCountdownFrame(currentWatcherType); /* after modules loaded */
/* Cpu Shutdown */
if (currentWatcherType&SDWTF_CPUUSAGE)
- idCpuUsageThread=PollCpuUsage(CpuUsageWatcherProc,(LPARAM)DBGetContactSettingRangedByte(NULL,"AutoShutdown","CpuUsageThreshold",SETTING_CPUUSAGETHRESHOLD_DEFAULT,1,100),1500);
+ idCpuUsageThread = PollCpuUsage(CpuUsageWatcherProc, (LPARAM)DBGetContactSettingRangedByte(NULL, "AutoShutdown", "CpuUsageThreshold", SETTING_CPUUSAGETHRESHOLD_DEFAULT, 1, 100), 1500);
/* Transfer Shutdown */
if (currentWatcherType&SDWTF_FILETRANSFER && !nTransfersCount)
ShutdownAndStopWatcher();
@@ -287,24 +287,24 @@ INT_PTR ServiceStartWatcher(WPARAM, LPARAM lParam)
return 0;
}
-INT_PTR ServiceStopWatcher(WPARAM,LPARAM)
+INT_PTR ServiceStopWatcher(WPARAM, LPARAM)
{
- if (currentWatcherType==0) return 1;
+ if (currentWatcherType == 0) return 1;
/* Time Shutdown */
if (currentWatcherType&SDWTF_SPECIFICTIME)
CloseCountdownFrame();
/* Cpu Shutdown */
- idCpuUsageThread=0;
+ idCpuUsageThread = 0;
- currentWatcherType=0;
+ currentWatcherType = 0;
SetShutdownMenuItem(FALSE);
SetShutdownToolbarButton(FALSE);
- NotifyEventHooks(hEventWatcherChanged,FALSE,0);
+ NotifyEventHooks(hEventWatcherChanged, FALSE, 0);
return 0;
}
-INT_PTR ServiceIsWatcherEnabled(WPARAM,LPARAM)
+INT_PTR ServiceIsWatcherEnabled(WPARAM, LPARAM)
{
return currentWatcherType != 0;
}
@@ -315,44 +315,44 @@ void WatcherModulesLoaded(void)
{
/* Weather Shutdown */
if (ServiceExists(MS_WEATHER_UPDATE))
- hHookWeatherUpdated=HookEvent(ME_WEATHER_UPDATED,WeatherUpdated);
+ hHookWeatherUpdated = HookEvent(ME_WEATHER_UPDATED, WeatherUpdated);
/* restore watcher if it was running on last exit */
- if (db_get_b(NULL,"AutoShutdown","RememberOnRestart",0)==SDROR_RUNNING) {
- db_set_b(NULL,"AutoShutdown","RememberOnRestart",1);
- ServiceStartWatcher(0,0); /* after modules loaded */
+ if (db_get_b(NULL, "AutoShutdown", "RememberOnRestart", 0) == SDROR_RUNNING) {
+ db_set_b(NULL, "AutoShutdown", "RememberOnRestart", 1);
+ ServiceStartWatcher(0, 0); /* after modules loaded */
}
}
void InitWatcher(void)
{
/* Shared */
- currentWatcherType=0;
+ currentWatcherType = 0;
/* Message Shutdown */
- hHookEventAdded=HookEvent(ME_DB_EVENT_ADDED,MsgEventAdded);
+ hHookEventAdded = HookEvent(ME_DB_EVENT_ADDED, MsgEventAdded);
/* Status Shutdown*/
- hHookSettingChanged=HookEvent(ME_DB_CONTACT_SETTINGCHANGED,StatusSettingChanged);
+ hHookSettingChanged = HookEvent(ME_DB_CONTACT_SETTINGCHANGED, StatusSettingChanged);
/* Idle Shutdown */
- hHookIdleChanged=HookEvent(ME_IDLE_CHANGED,IdleChanged);
+ hHookIdleChanged = HookEvent(ME_IDLE_CHANGED, IdleChanged);
/* Transfer Shutdown */
- transfers=NULL;
- nTransfersCount=0;
- hHookProtoAck=HookEvent(ME_PROTO_ACK,ProtoAck);
+ transfers = NULL;
+ nTransfersCount = 0;
+ hHookProtoAck = HookEvent(ME_PROTO_ACK, ProtoAck);
/* Weather Shutdown */
- hHookWeatherUpdated=NULL;
+ hHookWeatherUpdated = NULL;
/* Services */
- hEventWatcherChanged=CreateHookableEvent(ME_AUTOSHUTDOWN_WATCHERCHANGED);
+ hEventWatcherChanged = CreateHookableEvent(ME_AUTOSHUTDOWN_WATCHERCHANGED);
hServiceStartWatcher = CreateServiceFunction(MS_AUTOSHUTDOWN_STARTWATCHER, ServiceStartWatcher);
- hServiceStopWatcher = CreateServiceFunction(MS_AUTOSHUTDOWN_STOPWATCHER, ServiceStopWatcher);
+ hServiceStopWatcher = CreateServiceFunction(MS_AUTOSHUTDOWN_STOPWATCHER, ServiceStopWatcher);
hServiceIsEnabled = CreateServiceFunction(MS_AUTOSHUTDOWN_ISWATCHERENABLED, ServiceIsWatcherEnabled);
}
void UninitWatcher(void)
{
/* remember watcher if running */
- if (!ServiceStopWatcher(0,0))
- if (db_get_b(NULL,"AutoShutdown","RememberOnRestart",SETTING_REMEMBERONRESTART_DEFAULT))
- db_set_b(NULL,"AutoShutdown","RememberOnRestart",SDROR_RUNNING);
+ if (!ServiceStopWatcher(0, 0))
+ if (db_get_b(NULL, "AutoShutdown", "RememberOnRestart", SETTING_REMEMBERONRESTART_DEFAULT))
+ db_set_b(NULL, "AutoShutdown", "RememberOnRestart", SDROR_RUNNING);
/* Message Shutdown */
UnhookEvent(hHookEventAdded);