2010-03-20 19:40:30 +00:00
|
|
|
/*
|
|
|
|
Copyright (C) 2010 spx
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
2012-01-23 06:36:15 +00:00
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2010-03-20 19:40:30 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "StdAfx.h"
|
|
|
|
#include "System.h"
|
|
|
|
#include "Litestep.h"
|
|
|
|
#include "Rainmeter.h"
|
2010-09-04 08:04:13 +00:00
|
|
|
#include "MeterWindow.h"
|
2010-03-29 21:50:05 +00:00
|
|
|
#include "MeasureNet.h"
|
2010-03-20 19:40:30 +00:00
|
|
|
#include "Error.h"
|
|
|
|
|
2012-02-04 15:54:30 +00:00
|
|
|
using namespace Gdiplus;
|
|
|
|
|
2010-03-29 21:50:05 +00:00
|
|
|
#define DEBUG_VERBOSE (0) // Set 1 if you need verbose logging.
|
|
|
|
|
2011-09-03 21:51:25 +00:00
|
|
|
#define ZPOS_FLAGS (SWP_NOMOVE | SWP_NOSIZE | SWP_NOOWNERZORDER | SWP_NOACTIVATE | SWP_NOSENDCHANGING)
|
|
|
|
|
2010-03-20 19:40:30 +00:00
|
|
|
enum TIMER
|
|
|
|
{
|
2012-02-15 02:51:27 +00:00
|
|
|
TIMER_SHOWDESKTOP = 1
|
2010-03-20 19:40:30 +00:00
|
|
|
};
|
|
|
|
enum INTERVAL
|
|
|
|
{
|
2011-11-10 13:44:19 +00:00
|
|
|
INTERVAL_SHOWDESKTOP = 250,
|
2012-02-15 02:51:27 +00:00
|
|
|
INTERVAL_RESTOREWINDOWS = 100
|
2010-03-20 19:40:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
MULTIMONITOR_INFO CSystem::c_Monitors = { 0 };
|
|
|
|
|
|
|
|
HWND CSystem::c_Window = NULL;
|
2010-03-29 21:50:05 +00:00
|
|
|
HWND CSystem::c_HelperWindow = NULL;
|
|
|
|
|
|
|
|
HWINEVENTHOOK CSystem::c_WinEventHook = NULL;
|
|
|
|
|
2010-03-20 19:40:30 +00:00
|
|
|
bool CSystem::c_ShowDesktop = false;
|
|
|
|
|
2010-09-11 19:39:45 +00:00
|
|
|
OSPLATFORM CSystem::c_Platform = OSPLATFORM_UNKNOWN;
|
|
|
|
|
2011-05-22 16:02:43 +00:00
|
|
|
std::wstring CSystem::c_WorkingDirectory;
|
|
|
|
|
2011-11-10 13:44:19 +00:00
|
|
|
std::vector<std::wstring> CSystem::c_IniFileMappings;
|
|
|
|
|
2010-03-20 19:40:30 +00:00
|
|
|
extern CRainmeter* Rainmeter;
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Initialize
|
|
|
|
**
|
2010-03-29 21:50:05 +00:00
|
|
|
** Creates a helper window to detect changes in the system.
|
2010-03-20 19:40:30 +00:00
|
|
|
**
|
|
|
|
*/
|
|
|
|
void CSystem::Initialize(HINSTANCE instance)
|
|
|
|
{
|
|
|
|
WNDCLASS wc = {0};
|
|
|
|
wc.lpfnWndProc = (WNDPROC)WndProc;
|
|
|
|
wc.hInstance = instance;
|
|
|
|
wc.lpszClassName = L"RainmeterSystemClass";
|
|
|
|
|
|
|
|
RegisterClass(&wc);
|
|
|
|
|
|
|
|
c_Window = CreateWindowEx(
|
|
|
|
WS_EX_TOOLWINDOW,
|
|
|
|
L"RainmeterSystemClass",
|
2010-03-29 21:50:05 +00:00
|
|
|
L"SystemWindow",
|
2011-09-03 21:51:25 +00:00
|
|
|
WS_POPUP | WS_DISABLED,
|
2010-03-20 19:40:30 +00:00
|
|
|
CW_USEDEFAULT,
|
|
|
|
CW_USEDEFAULT,
|
|
|
|
CW_USEDEFAULT,
|
|
|
|
CW_USEDEFAULT,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
instance,
|
|
|
|
NULL);
|
|
|
|
|
2010-03-29 21:50:05 +00:00
|
|
|
c_HelperWindow = CreateWindowEx(
|
|
|
|
WS_EX_TOOLWINDOW,
|
|
|
|
L"RainmeterSystemClass",
|
|
|
|
L"PositioningHelperWindow",
|
2011-09-03 21:51:25 +00:00
|
|
|
WS_POPUP | WS_DISABLED,
|
2010-03-29 21:50:05 +00:00
|
|
|
CW_USEDEFAULT,
|
|
|
|
CW_USEDEFAULT,
|
|
|
|
CW_USEDEFAULT,
|
|
|
|
CW_USEDEFAULT,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
instance,
|
|
|
|
NULL);
|
2010-03-20 19:40:30 +00:00
|
|
|
|
2011-09-03 21:51:25 +00:00
|
|
|
SetWindowPos(c_Window, HWND_BOTTOM, 0, 0, 0, 0, ZPOS_FLAGS);
|
|
|
|
SetWindowPos(c_HelperWindow, HWND_BOTTOM, 0, 0, 0, 0, ZPOS_FLAGS);
|
2010-03-29 21:50:05 +00:00
|
|
|
|
2011-11-10 12:09:50 +00:00
|
|
|
SetOSPlatform();
|
2011-11-10 11:50:47 +00:00
|
|
|
|
2011-11-18 22:40:58 +00:00
|
|
|
c_Monitors.monitors.reserve(4);
|
2010-03-20 19:40:30 +00:00
|
|
|
SetMultiMonitorInfo();
|
|
|
|
|
2011-06-23 13:29:51 +00:00
|
|
|
WCHAR directory[MAX_PATH] = {0};
|
|
|
|
GetCurrentDirectory(MAX_PATH, directory);
|
|
|
|
c_WorkingDirectory = directory;
|
|
|
|
|
2010-03-29 21:50:05 +00:00
|
|
|
c_WinEventHook = SetWinEventHook(
|
|
|
|
EVENT_SYSTEM_FOREGROUND,
|
|
|
|
EVENT_SYSTEM_FOREGROUND,
|
|
|
|
NULL,
|
|
|
|
MyWinEventProc,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
WINEVENT_OUTOFCONTEXT | WINEVENT_SKIPOWNPROCESS);
|
|
|
|
|
2011-08-10 14:13:53 +00:00
|
|
|
SetTimer(c_Window, TIMER_SHOWDESKTOP, INTERVAL_SHOWDESKTOP, NULL);
|
2010-03-20 19:40:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Finalize
|
|
|
|
**
|
|
|
|
** Destroys a window.
|
|
|
|
**
|
|
|
|
*/
|
|
|
|
void CSystem::Finalize()
|
|
|
|
{
|
|
|
|
KillTimer(c_Window, TIMER_SHOWDESKTOP);
|
|
|
|
|
2010-07-17 13:02:34 +00:00
|
|
|
if (c_WinEventHook)
|
|
|
|
{
|
|
|
|
UnhookWinEvent(c_WinEventHook);
|
|
|
|
c_WinEventHook = NULL;
|
|
|
|
}
|
2010-03-29 21:50:05 +00:00
|
|
|
|
2010-07-17 13:02:34 +00:00
|
|
|
if (c_HelperWindow)
|
|
|
|
{
|
|
|
|
DestroyWindow(c_HelperWindow);
|
|
|
|
c_HelperWindow = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (c_Window)
|
|
|
|
{
|
|
|
|
DestroyWindow(c_Window);
|
|
|
|
c_Window = NULL;
|
|
|
|
}
|
2010-03-20 19:40:30 +00:00
|
|
|
}
|
|
|
|
|
2011-11-19 11:32:23 +00:00
|
|
|
/*
|
|
|
|
** MyInfoEnumProc
|
2010-03-20 19:40:30 +00:00
|
|
|
**
|
|
|
|
** Retrieves the multi-monitor information.
|
|
|
|
**
|
|
|
|
*/
|
|
|
|
BOOL CALLBACK MyInfoEnumProc(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData)
|
|
|
|
{
|
|
|
|
MULTIMONITOR_INFO* m = (MULTIMONITOR_INFO*)dwData;
|
|
|
|
|
|
|
|
MONITORINFOEX info;
|
|
|
|
info.cbSize = sizeof(MONITORINFOEX);
|
|
|
|
GetMonitorInfo(hMonitor, &info);
|
|
|
|
|
2011-09-28 18:28:35 +00:00
|
|
|
if (Rainmeter->GetDebug())
|
2010-03-20 19:40:30 +00:00
|
|
|
{
|
2010-12-20 08:57:37 +00:00
|
|
|
Log(LOG_DEBUG, info.szDevice);
|
2010-12-19 23:06:13 +00:00
|
|
|
LogWithArgs(LOG_DEBUG, L" Flags : %s(0x%08X)", (info.dwFlags & MONITORINFOF_PRIMARY) ? L"PRIMARY " : L"", info.dwFlags);
|
|
|
|
LogWithArgs(LOG_DEBUG, L" Handle : 0x%p", hMonitor);
|
|
|
|
LogWithArgs(LOG_DEBUG, L" ScrArea : L=%i, T=%i, R=%i, B=%i (W=%i, H=%i)",
|
2010-03-20 19:40:30 +00:00
|
|
|
lprcMonitor->left, lprcMonitor->top, lprcMonitor->right, lprcMonitor->bottom,
|
|
|
|
lprcMonitor->right - lprcMonitor->left, lprcMonitor->bottom - lprcMonitor->top);
|
2010-12-19 23:06:13 +00:00
|
|
|
LogWithArgs(LOG_DEBUG, L" WorkArea : L=%i, T=%i, R=%i, B=%i (W=%i, H=%i)",
|
2010-03-20 19:40:30 +00:00
|
|
|
info.rcWork.left, info.rcWork.top, info.rcWork.right, info.rcWork.bottom,
|
|
|
|
info.rcWork.right - info.rcWork.left, info.rcWork.bottom - info.rcWork.top);
|
|
|
|
}
|
|
|
|
if (m == NULL) return TRUE;
|
|
|
|
|
|
|
|
if (m->useEnumDisplayDevices)
|
|
|
|
{
|
2011-02-15 13:22:19 +00:00
|
|
|
for (size_t i = 0, isize = m->monitors.size(); i < isize; ++i)
|
2010-03-20 19:40:30 +00:00
|
|
|
{
|
2011-12-09 19:49:06 +00:00
|
|
|
if (m->monitors[i].handle == NULL && _wcsicmp(info.szDevice, m->monitors[i].deviceName.c_str()) == 0)
|
2010-03-20 19:40:30 +00:00
|
|
|
{
|
|
|
|
m->monitors[i].handle = hMonitor;
|
|
|
|
m->monitors[i].screen = *lprcMonitor;
|
|
|
|
m->monitors[i].work = info.rcWork;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else // use only EnumDisplayMonitors
|
|
|
|
{
|
2011-12-09 19:49:06 +00:00
|
|
|
MONITOR_INFO monitor;
|
2010-03-20 19:40:30 +00:00
|
|
|
monitor.active = true;
|
|
|
|
|
|
|
|
monitor.handle = hMonitor;
|
|
|
|
monitor.screen = *lprcMonitor;
|
|
|
|
monitor.work = info.rcWork;
|
|
|
|
|
2011-12-09 19:49:06 +00:00
|
|
|
monitor.deviceName = info.szDevice; // E.g. "\\.\DISPLAY1"
|
2010-03-20 19:40:30 +00:00
|
|
|
|
|
|
|
// Get the monitor name (E.g. "Generic Non-PnP Monitor")
|
2011-06-23 13:29:51 +00:00
|
|
|
DISPLAY_DEVICE ddm = {sizeof(DISPLAY_DEVICE)};
|
2010-03-20 19:40:30 +00:00
|
|
|
DWORD dwMon = 0;
|
|
|
|
while (EnumDisplayDevices(info.szDevice, dwMon++, &ddm, 0))
|
|
|
|
{
|
|
|
|
if (ddm.StateFlags & DISPLAY_DEVICE_ACTIVE && ddm.StateFlags & DISPLAY_DEVICE_ATTACHED)
|
|
|
|
{
|
2011-12-09 19:49:06 +00:00
|
|
|
monitor.monitorName.assign(ddm.DeviceString, wcsnlen(ddm.DeviceString, _countof(ddm.DeviceString)));
|
2010-03-20 19:40:30 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
m->monitors.push_back(monitor);
|
|
|
|
|
|
|
|
if (info.dwFlags & MONITORINFOF_PRIMARY)
|
|
|
|
{
|
|
|
|
// It's primary monitor!
|
|
|
|
m->primary = (int)m->monitors.size();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2011-11-19 11:32:23 +00:00
|
|
|
/*
|
|
|
|
** GetMonitorCount
|
2010-03-20 19:40:30 +00:00
|
|
|
**
|
|
|
|
** Returns the number of monitors.
|
|
|
|
**
|
|
|
|
*/
|
|
|
|
size_t CSystem::GetMonitorCount()
|
|
|
|
{
|
2011-02-15 13:22:19 +00:00
|
|
|
if (c_Monitors.monitors.empty())
|
2010-03-20 19:40:30 +00:00
|
|
|
{
|
|
|
|
SetMultiMonitorInfo();
|
|
|
|
}
|
|
|
|
return c_Monitors.monitors.size();
|
|
|
|
}
|
|
|
|
|
2011-11-19 11:32:23 +00:00
|
|
|
/*
|
|
|
|
** SetMultiMonitorInfo
|
2010-03-20 19:40:30 +00:00
|
|
|
**
|
|
|
|
** Sets the multi-monitor information.
|
|
|
|
**
|
|
|
|
*/
|
|
|
|
void CSystem::SetMultiMonitorInfo()
|
|
|
|
{
|
|
|
|
std::vector<MONITOR_INFO>& monitors = c_Monitors.monitors;
|
2011-09-28 18:28:35 +00:00
|
|
|
bool logging = Rainmeter->GetDebug();
|
2010-03-20 19:40:30 +00:00
|
|
|
|
|
|
|
c_Monitors.vsT = GetSystemMetrics(SM_YVIRTUALSCREEN);
|
|
|
|
c_Monitors.vsL = GetSystemMetrics(SM_XVIRTUALSCREEN);
|
|
|
|
c_Monitors.vsH = GetSystemMetrics(SM_CYVIRTUALSCREEN);
|
|
|
|
c_Monitors.vsW = GetSystemMetrics(SM_CXVIRTUALSCREEN);
|
|
|
|
|
|
|
|
c_Monitors.primary = 1; // If primary screen is not found, 1st screen is assumed as primary screen.
|
|
|
|
|
|
|
|
c_Monitors.useEnumDisplayDevices = true;
|
|
|
|
c_Monitors.useEnumDisplayMonitors = false;
|
|
|
|
|
|
|
|
if (logging)
|
|
|
|
{
|
2010-12-20 08:57:37 +00:00
|
|
|
Log(LOG_DEBUG, L"------------------------------");
|
|
|
|
Log(LOG_DEBUG, L"* EnumDisplayDevices / EnumDisplaySettings API");
|
2010-03-20 19:40:30 +00:00
|
|
|
}
|
|
|
|
|
2011-06-23 13:29:51 +00:00
|
|
|
DISPLAY_DEVICE dd = {sizeof(DISPLAY_DEVICE)};
|
2010-03-20 19:40:30 +00:00
|
|
|
|
|
|
|
if (EnumDisplayDevices(NULL, 0, &dd, 0))
|
|
|
|
{
|
|
|
|
DWORD dwDevice = 0;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
std::wstring msg;
|
|
|
|
|
2011-12-09 19:49:06 +00:00
|
|
|
std::wstring deviceName(dd.DeviceName, wcsnlen(dd.DeviceName, _countof(dd.DeviceName)));
|
|
|
|
std::wstring deviceString;
|
|
|
|
|
2010-03-20 19:40:30 +00:00
|
|
|
if (logging)
|
|
|
|
{
|
2011-12-09 19:49:06 +00:00
|
|
|
deviceString.assign(dd.DeviceString, wcsnlen(dd.DeviceString, _countof(dd.DeviceString)));
|
|
|
|
|
|
|
|
Log(LOG_DEBUG, deviceName.c_str());
|
2010-03-20 19:40:30 +00:00
|
|
|
|
|
|
|
if (dd.StateFlags & DISPLAY_DEVICE_ACTIVE)
|
|
|
|
{
|
|
|
|
msg += L"ACTIVE ";
|
|
|
|
}
|
|
|
|
if (dd.StateFlags & DISPLAY_DEVICE_MULTI_DRIVER)
|
|
|
|
{
|
|
|
|
msg += L"MULTI ";
|
|
|
|
}
|
|
|
|
if (dd.StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE)
|
|
|
|
{
|
|
|
|
msg += L"PRIMARY ";
|
|
|
|
}
|
|
|
|
if (dd.StateFlags & DISPLAY_DEVICE_MIRRORING_DRIVER)
|
|
|
|
{
|
|
|
|
msg += L"MIRROR ";
|
|
|
|
}
|
|
|
|
if (dd.StateFlags & DISPLAY_DEVICE_VGA_COMPATIBLE)
|
|
|
|
{
|
|
|
|
msg += L"VGA ";
|
|
|
|
}
|
|
|
|
if (dd.StateFlags & DISPLAY_DEVICE_REMOVABLE)
|
|
|
|
{
|
|
|
|
msg += L"REMOVABLE ";
|
|
|
|
}
|
|
|
|
if (dd.StateFlags & DISPLAY_DEVICE_MODESPRUNED)
|
|
|
|
{
|
|
|
|
msg += L"PRUNED ";
|
|
|
|
}
|
|
|
|
if (dd.StateFlags & DISPLAY_DEVICE_REMOTE)
|
|
|
|
{
|
|
|
|
msg += L"REMOTE ";
|
|
|
|
}
|
|
|
|
if (dd.StateFlags & DISPLAY_DEVICE_DISCONNECT)
|
|
|
|
{
|
|
|
|
msg += L"DISCONNECT ";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((dd.StateFlags & DISPLAY_DEVICE_MIRRORING_DRIVER) == 0)
|
|
|
|
{
|
|
|
|
MONITOR_INFO monitor = {0};
|
|
|
|
|
|
|
|
monitor.handle = NULL;
|
2011-12-09 19:49:06 +00:00
|
|
|
monitor.deviceName = deviceName; // E.g. "\\.\DISPLAY1"
|
2010-03-20 19:40:30 +00:00
|
|
|
|
|
|
|
// Get the monitor name (E.g. "Generic Non-PnP Monitor")
|
2011-06-23 13:29:51 +00:00
|
|
|
DISPLAY_DEVICE ddm = {sizeof(DISPLAY_DEVICE)};
|
2010-03-20 19:40:30 +00:00
|
|
|
DWORD dwMon = 0;
|
2011-12-09 19:49:06 +00:00
|
|
|
while (EnumDisplayDevices(deviceName.c_str(), dwMon++, &ddm, 0))
|
2010-03-20 19:40:30 +00:00
|
|
|
{
|
|
|
|
if (ddm.StateFlags & DISPLAY_DEVICE_ACTIVE && ddm.StateFlags & DISPLAY_DEVICE_ATTACHED)
|
|
|
|
{
|
2011-12-09 19:49:06 +00:00
|
|
|
monitor.monitorName.assign(ddm.DeviceString, wcsnlen(ddm.DeviceString, _countof(ddm.DeviceString)));
|
2010-03-20 19:40:30 +00:00
|
|
|
|
|
|
|
if (logging)
|
|
|
|
{
|
2011-12-09 19:49:06 +00:00
|
|
|
LogWithArgs(LOG_DEBUG, L" Name : %s", monitor.monitorName.c_str());
|
2010-03-20 19:40:30 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (logging)
|
|
|
|
{
|
2011-12-09 19:49:06 +00:00
|
|
|
LogWithArgs(LOG_DEBUG, L" Adapter : %s", deviceString.c_str());
|
2010-12-19 23:06:13 +00:00
|
|
|
LogWithArgs(LOG_DEBUG, L" Flags : %s(0x%08X)", msg.c_str(), dd.StateFlags);
|
2010-03-20 19:40:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (dd.StateFlags & DISPLAY_DEVICE_ACTIVE)
|
|
|
|
{
|
|
|
|
monitor.active = true;
|
|
|
|
|
|
|
|
DEVMODE dm = {0};
|
|
|
|
dm.dmSize = sizeof(DEVMODE);
|
|
|
|
|
2011-12-09 19:49:06 +00:00
|
|
|
if (EnumDisplaySettings(deviceName.c_str(), ENUM_CURRENT_SETTINGS, &dm))
|
2010-03-20 19:40:30 +00:00
|
|
|
{
|
|
|
|
POINT pos = {dm.dmPosition.x, dm.dmPosition.y};
|
|
|
|
monitor.handle = MonitorFromPoint(pos, MONITOR_DEFAULTTONULL);
|
|
|
|
|
|
|
|
if (logging)
|
|
|
|
{
|
2010-12-19 23:06:13 +00:00
|
|
|
LogWithArgs(LOG_DEBUG, L" Handle : 0x%p", monitor.handle);
|
2010-03-20 19:40:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (monitor.handle != NULL)
|
|
|
|
{
|
2011-06-23 13:29:51 +00:00
|
|
|
MONITORINFO info = {sizeof(MONITORINFO)};
|
2010-03-20 19:40:30 +00:00
|
|
|
GetMonitorInfo(monitor.handle, &info);
|
|
|
|
|
|
|
|
monitor.screen = info.rcMonitor;
|
|
|
|
monitor.work = info.rcWork;
|
|
|
|
|
|
|
|
if (logging)
|
|
|
|
{
|
2010-12-19 23:06:13 +00:00
|
|
|
LogWithArgs(LOG_DEBUG, L" ScrArea : L=%i, T=%i, R=%i, B=%i (W=%i, H=%i)",
|
2010-03-20 19:40:30 +00:00
|
|
|
info.rcMonitor.left, info.rcMonitor.top, info.rcMonitor.right, info.rcMonitor.bottom,
|
|
|
|
info.rcMonitor.right - info.rcMonitor.left, info.rcMonitor.bottom - info.rcMonitor.top);
|
2010-12-19 23:06:13 +00:00
|
|
|
LogWithArgs(LOG_DEBUG, L" WorkArea : L=%i, T=%i, R=%i, B=%i (W=%i, H=%i)",
|
2010-03-20 19:40:30 +00:00
|
|
|
info.rcWork.left, info.rcWork.top, info.rcWork.right, info.rcWork.bottom,
|
|
|
|
info.rcWork.right - info.rcWork.left, info.rcWork.bottom - info.rcWork.top);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else // monitor not found
|
|
|
|
{
|
|
|
|
c_Monitors.useEnumDisplayMonitors = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
monitor.active = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
monitors.push_back(monitor);
|
|
|
|
|
|
|
|
if (dd.StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE)
|
|
|
|
{
|
|
|
|
// It's primary monitor!
|
|
|
|
c_Monitors.primary = (int)monitors.size();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (logging)
|
|
|
|
{
|
2011-12-09 19:49:06 +00:00
|
|
|
LogWithArgs(LOG_DEBUG, L" Adapter : %s", deviceString.c_str());
|
2010-12-19 23:06:13 +00:00
|
|
|
LogWithArgs(LOG_DEBUG, L" Flags : %s(0x%08X)", msg.c_str(), dd.StateFlags);
|
2010-03-20 19:40:30 +00:00
|
|
|
}
|
|
|
|
}
|
2010-03-30 22:37:05 +00:00
|
|
|
++dwDevice;
|
2011-11-08 10:32:57 +00:00
|
|
|
}
|
|
|
|
while (EnumDisplayDevices(NULL, dwDevice, &dd, 0));
|
2010-03-20 19:40:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (monitors.empty()) // Failed to enumerate the non-mirroring monitors
|
|
|
|
{
|
2010-12-20 08:57:37 +00:00
|
|
|
Log(LOG_WARNING, L"Failed to enumerate the non-mirroring monitors. Only EnumDisplayMonitors is used instead.");
|
2010-03-20 19:40:30 +00:00
|
|
|
c_Monitors.useEnumDisplayDevices = false;
|
|
|
|
c_Monitors.useEnumDisplayMonitors = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (logging)
|
|
|
|
{
|
2010-12-20 08:57:37 +00:00
|
|
|
Log(LOG_DEBUG, L"------------------------------");
|
|
|
|
Log(LOG_DEBUG, L"* EnumDisplayMonitors API");
|
2010-03-20 19:40:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (c_Monitors.useEnumDisplayMonitors)
|
|
|
|
{
|
|
|
|
EnumDisplayMonitors(NULL, NULL, MyInfoEnumProc, (LPARAM)(&c_Monitors));
|
|
|
|
|
|
|
|
if (monitors.empty()) // Failed to enumerate the monitors
|
|
|
|
{
|
2011-09-09 16:31:55 +00:00
|
|
|
Log(LOG_WARNING, L"Failed to enumerate monitors. Using dummy monitor info.");
|
2010-03-20 19:40:30 +00:00
|
|
|
c_Monitors.useEnumDisplayMonitors = false;
|
|
|
|
|
2011-12-09 19:49:06 +00:00
|
|
|
MONITOR_INFO monitor;
|
|
|
|
monitor.active = true;
|
|
|
|
|
2010-03-20 19:40:30 +00:00
|
|
|
POINT pos = {0, 0};
|
|
|
|
monitor.handle = MonitorFromPoint(pos, MONITOR_DEFAULTTOPRIMARY);
|
|
|
|
monitor.screen.left = 0;
|
|
|
|
monitor.screen.top = 0;
|
|
|
|
monitor.screen.right = GetSystemMetrics(SM_CXSCREEN);
|
|
|
|
monitor.screen.bottom = GetSystemMetrics(SM_CYSCREEN);
|
2011-12-09 19:49:06 +00:00
|
|
|
if (SystemParametersInfo(SPI_GETWORKAREA, 0, &(monitor.work), 0) == 0) // failed
|
|
|
|
{
|
|
|
|
monitor.work = monitor.screen;
|
|
|
|
}
|
|
|
|
|
|
|
|
monitor.deviceName = L"DUMMY";
|
2010-03-20 19:40:30 +00:00
|
|
|
|
|
|
|
monitors.push_back(monitor);
|
|
|
|
|
|
|
|
c_Monitors.primary = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (logging)
|
|
|
|
{
|
|
|
|
EnumDisplayMonitors(NULL, NULL, MyInfoEnumProc, (LPARAM)NULL); // Only logging
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (logging)
|
|
|
|
{
|
2010-12-20 08:57:37 +00:00
|
|
|
Log(LOG_DEBUG, L"------------------------------");
|
2010-03-20 19:40:30 +00:00
|
|
|
|
|
|
|
std::wstring method = L"* METHOD: ";
|
|
|
|
if (c_Monitors.useEnumDisplayDevices)
|
|
|
|
{
|
|
|
|
method += L"EnumDisplayDevices + ";
|
|
|
|
method += c_Monitors.useEnumDisplayMonitors ? L"EnumDisplayMonitors Mode" : L"EnumDisplaySettings Mode";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
method += c_Monitors.useEnumDisplayMonitors ? L"EnumDisplayMonitors Mode" : L"Dummy Mode";
|
|
|
|
}
|
2010-12-20 08:57:37 +00:00
|
|
|
Log(LOG_DEBUG, method.c_str());
|
2010-03-20 19:40:30 +00:00
|
|
|
|
2010-12-19 23:06:13 +00:00
|
|
|
LogWithArgs(LOG_DEBUG, L"* MONITORS: Count=%i, Primary=@%i", (int)monitors.size(), c_Monitors.primary);
|
2010-12-20 08:57:37 +00:00
|
|
|
Log(LOG_DEBUG, L"@0: Virtual screen");
|
2010-12-19 23:06:13 +00:00
|
|
|
LogWithArgs(LOG_DEBUG, L" L=%i, T=%i, R=%i, B=%i (W=%i, H=%i)",
|
2010-03-20 19:40:30 +00:00
|
|
|
c_Monitors.vsL, c_Monitors.vsT, c_Monitors.vsL + c_Monitors.vsW, c_Monitors.vsT + c_Monitors.vsH,
|
|
|
|
c_Monitors.vsW, c_Monitors.vsH);
|
|
|
|
|
2011-02-15 13:22:19 +00:00
|
|
|
for (size_t i = 0, isize = monitors.size(); i < isize; ++i)
|
2010-03-20 19:40:30 +00:00
|
|
|
{
|
|
|
|
if (monitors[i].active)
|
|
|
|
{
|
2011-12-09 19:49:06 +00:00
|
|
|
LogWithArgs(LOG_DEBUG, L"@%i: %s (active), MonitorName: %s", (int)i + 1, monitors[i].deviceName.c_str(), monitors[i].monitorName.c_str());
|
2010-12-19 23:06:13 +00:00
|
|
|
LogWithArgs(LOG_DEBUG, L" L=%i, T=%i, R=%i, B=%i (W=%i, H=%i)",
|
2010-03-20 19:40:30 +00:00
|
|
|
monitors[i].screen.left, monitors[i].screen.top, monitors[i].screen.right, monitors[i].screen.bottom,
|
|
|
|
monitors[i].screen.right - monitors[i].screen.left, monitors[i].screen.bottom - monitors[i].screen.top);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-12-09 19:49:06 +00:00
|
|
|
LogWithArgs(LOG_DEBUG, L"@%i: %s (inactive), MonitorName: %s", (int)i + 1, monitors[i].deviceName.c_str(), monitors[i].monitorName.c_str());
|
2010-03-20 19:40:30 +00:00
|
|
|
}
|
|
|
|
}
|
2010-12-20 08:57:37 +00:00
|
|
|
Log(LOG_DEBUG, L"------------------------------");
|
2010-03-20 19:40:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-19 11:32:23 +00:00
|
|
|
/*
|
|
|
|
** UpdateWorkareaInfo
|
2010-03-20 19:40:30 +00:00
|
|
|
**
|
|
|
|
** Updates the workarea information.
|
|
|
|
**
|
|
|
|
*/
|
|
|
|
void CSystem::UpdateWorkareaInfo()
|
|
|
|
{
|
|
|
|
std::vector<MONITOR_INFO>& monitors = c_Monitors.monitors;
|
|
|
|
|
|
|
|
if (monitors.empty())
|
|
|
|
{
|
|
|
|
SetMultiMonitorInfo();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-02-15 13:22:19 +00:00
|
|
|
for (size_t i = 0, isize = monitors.size(); i < isize; ++i)
|
2010-03-20 19:40:30 +00:00
|
|
|
{
|
|
|
|
if (monitors[i].active && monitors[i].handle != NULL)
|
|
|
|
{
|
2011-06-23 13:29:51 +00:00
|
|
|
MONITORINFO info = {sizeof(MONITORINFO)};
|
2010-03-20 19:40:30 +00:00
|
|
|
GetMonitorInfo(monitors[i].handle, &info);
|
|
|
|
|
|
|
|
monitors[i].work = info.rcWork;
|
|
|
|
|
2011-09-28 18:28:35 +00:00
|
|
|
if (Rainmeter->GetDebug())
|
2010-03-20 19:40:30 +00:00
|
|
|
{
|
2010-12-19 23:06:13 +00:00
|
|
|
LogWithArgs(LOG_DEBUG, L"WorkArea@%i : L=%i, T=%i, R=%i, B=%i (W=%i, H=%i)",
|
2010-12-16 20:35:44 +00:00
|
|
|
(int)i + 1,
|
2010-03-20 19:40:30 +00:00
|
|
|
info.rcWork.left, info.rcWork.top, info.rcWork.right, info.rcWork.bottom,
|
|
|
|
info.rcWork.right - info.rcWork.left, info.rcWork.bottom - info.rcWork.top);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2011-11-10 12:09:50 +00:00
|
|
|
** SetOSPlatform
|
|
|
|
**
|
|
|
|
** Sets the OS platform.
|
|
|
|
**
|
|
|
|
*/
|
|
|
|
void CSystem::SetOSPlatform()
|
|
|
|
{
|
|
|
|
OSVERSIONINFOEX osvi = {sizeof(OSVERSIONINFOEX)};
|
|
|
|
if (GetVersionEx((OSVERSIONINFO*)&osvi))
|
|
|
|
{
|
|
|
|
if (osvi.dwMajorVersion == 5)
|
|
|
|
{
|
|
|
|
// Not checking for osvi.dwMinorVersion >= 1 because Rainmeter won't run on pre-XP
|
|
|
|
c_Platform = OSPLATFORM_XP;
|
|
|
|
}
|
|
|
|
else if (osvi.dwMajorVersion == 6)
|
|
|
|
{
|
|
|
|
if (osvi.dwMinorVersion == 0)
|
|
|
|
{
|
|
|
|
c_Platform = OSPLATFORM_VISTA; // Vista, Server 2008
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
c_Platform = OSPLATFORM_7; // 7, Server 2008R2
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else // newer OS
|
|
|
|
{
|
|
|
|
c_Platform = OSPLATFORM_7;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2010-03-29 21:50:05 +00:00
|
|
|
** GetDefaultShellWindow
|
2010-03-20 19:40:30 +00:00
|
|
|
**
|
2010-03-29 21:50:05 +00:00
|
|
|
** Finds the Default Shell's window.
|
2010-03-20 19:40:30 +00:00
|
|
|
**
|
|
|
|
*/
|
2010-03-29 21:50:05 +00:00
|
|
|
HWND CSystem::GetDefaultShellWindow()
|
2010-03-20 19:40:30 +00:00
|
|
|
{
|
2011-08-10 14:13:53 +00:00
|
|
|
static HWND c_ShellW = NULL; // cache
|
2010-03-29 21:50:05 +00:00
|
|
|
HWND ShellW = GetShellWindow();
|
2010-03-20 19:40:30 +00:00
|
|
|
|
2010-03-29 21:50:05 +00:00
|
|
|
if (ShellW)
|
2010-03-20 19:40:30 +00:00
|
|
|
{
|
2011-08-10 14:13:53 +00:00
|
|
|
if (ShellW == c_ShellW)
|
2010-03-20 19:40:30 +00:00
|
|
|
{
|
2011-04-19 01:20:17 +00:00
|
|
|
return ShellW;
|
2010-03-20 19:40:30 +00:00
|
|
|
}
|
2011-08-10 14:13:53 +00:00
|
|
|
else
|
|
|
|
{
|
2011-11-18 07:33:41 +00:00
|
|
|
const int classLen = _countof(L"Progman");
|
|
|
|
WCHAR className[classLen];
|
|
|
|
if (!(GetClassName(ShellW, className, classLen) > 0 &&
|
2011-08-13 10:03:16 +00:00
|
|
|
wcscmp(className, L"Progman") == 0))
|
2011-08-10 14:13:53 +00:00
|
|
|
{
|
2011-08-13 10:03:16 +00:00
|
|
|
ShellW = NULL;
|
2011-08-10 14:13:53 +00:00
|
|
|
}
|
|
|
|
}
|
2010-03-20 19:40:30 +00:00
|
|
|
}
|
|
|
|
|
2011-08-13 10:03:16 +00:00
|
|
|
c_ShellW = ShellW;
|
|
|
|
return ShellW;
|
2010-03-20 19:40:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2011-04-26 09:58:06 +00:00
|
|
|
** GetWorkerW
|
2010-03-20 19:40:30 +00:00
|
|
|
**
|
2011-04-26 09:58:06 +00:00
|
|
|
** Finds the WorkerW window.
|
2011-08-13 10:03:16 +00:00
|
|
|
** If the WorkerW window is not active, returns NULL.
|
2010-03-20 19:40:30 +00:00
|
|
|
**
|
|
|
|
*/
|
2011-04-26 09:58:06 +00:00
|
|
|
HWND CSystem::GetWorkerW()
|
2010-03-20 19:40:30 +00:00
|
|
|
{
|
2011-08-13 10:03:16 +00:00
|
|
|
static HWND c_DefView = NULL; // cache
|
2010-03-29 21:50:05 +00:00
|
|
|
HWND ShellW = GetDefaultShellWindow();
|
|
|
|
if (!ShellW) return NULL; // Default Shell (Explorer) not running
|
2010-03-20 19:40:30 +00:00
|
|
|
|
2011-08-13 10:03:16 +00:00
|
|
|
if (c_DefView && IsWindow(c_DefView))
|
|
|
|
{
|
|
|
|
HWND parent = GetAncestor(c_DefView, GA_PARENT);
|
|
|
|
if (parent)
|
|
|
|
{
|
|
|
|
if (parent == ShellW)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-11-18 07:33:41 +00:00
|
|
|
const int classLen = _countof(L"WorkerW");
|
|
|
|
WCHAR className[classLen];
|
|
|
|
if (GetClassName(parent, className, classLen) > 0 &&
|
2011-08-13 10:03:16 +00:00
|
|
|
wcscmp(className, L"WorkerW") == 0)
|
|
|
|
{
|
|
|
|
return parent;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
HWND WorkerW = NULL, DefView = FindWindowEx(ShellW, NULL, L"SHELLDLL_DefView", L"");
|
|
|
|
if (DefView == NULL)
|
2010-03-20 19:40:30 +00:00
|
|
|
{
|
|
|
|
while (WorkerW = FindWindowEx(NULL, WorkerW, L"WorkerW", L""))
|
|
|
|
{
|
2011-08-13 10:03:16 +00:00
|
|
|
if (IsWindowVisible(WorkerW) &&
|
|
|
|
BelongToSameProcess(ShellW, WorkerW) &&
|
|
|
|
(DefView = FindWindowEx(WorkerW, NULL, L"SHELLDLL_DefView", L"")))
|
2010-03-29 21:50:05 +00:00
|
|
|
{
|
2011-08-13 10:03:16 +00:00
|
|
|
break;
|
2010-03-29 21:50:05 +00:00
|
|
|
}
|
2010-03-20 19:40:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-13 10:03:16 +00:00
|
|
|
c_DefView = DefView;
|
|
|
|
return WorkerW;
|
2010-03-29 21:50:05 +00:00
|
|
|
}
|
|
|
|
|
2011-11-10 11:50:47 +00:00
|
|
|
/*
|
|
|
|
** GetBackmostTopWindow
|
|
|
|
**
|
|
|
|
** Returns the first window whose position is not ZPOSITION_ONDESKTOP,
|
|
|
|
** ZPOSITION_BOTTOM, or ZPOSITION_NORMAL.
|
|
|
|
**
|
|
|
|
*/
|
|
|
|
HWND CSystem::GetBackmostTopWindow()
|
|
|
|
{
|
|
|
|
HWND winPos = c_HelperWindow;
|
|
|
|
|
|
|
|
// Skip all ZPOSITION_ONDESKTOP, ZPOSITION_BOTTOM, and ZPOSITION_NORMAL windows
|
|
|
|
while (winPos = ::GetNextWindow(winPos, GW_HWNDPREV))
|
|
|
|
{
|
|
|
|
CMeterWindow* wnd = Rainmeter->GetMeterWindow(winPos);
|
|
|
|
if (!wnd ||
|
|
|
|
(wnd->GetWindowZPosition() != ZPOSITION_NORMAL &&
|
|
|
|
wnd->GetWindowZPosition() != ZPOSITION_ONDESKTOP &&
|
|
|
|
wnd->GetWindowZPosition() != ZPOSITION_ONBOTTOM))
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return winPos;
|
|
|
|
}
|
|
|
|
|
2010-03-29 21:50:05 +00:00
|
|
|
/*
|
|
|
|
** BelongToSameProcess
|
|
|
|
**
|
|
|
|
** Checks whether the given windows belong to the same process.
|
|
|
|
**
|
|
|
|
*/
|
|
|
|
bool CSystem::BelongToSameProcess(HWND hwndA, HWND hwndB)
|
|
|
|
{
|
|
|
|
DWORD procAId = 0, procBId = 0;
|
|
|
|
|
|
|
|
GetWindowThreadProcessId(hwndA, &procAId);
|
|
|
|
GetWindowThreadProcessId(hwndB, &procBId);
|
|
|
|
|
|
|
|
return (procAId == procBId);
|
2010-03-20 19:40:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** MyEnumWindowsProc
|
|
|
|
**
|
2010-03-29 21:50:05 +00:00
|
|
|
** Retrieves the Rainmeter's meter windows in Z-order.
|
2010-03-20 19:40:30 +00:00
|
|
|
**
|
|
|
|
*/
|
|
|
|
BOOL CALLBACK MyEnumWindowsProc(HWND hwnd, LPARAM lParam)
|
|
|
|
{
|
2011-09-28 18:28:35 +00:00
|
|
|
bool logging = Rainmeter->GetDebug() && DEBUG_VERBOSE;
|
2011-11-18 07:33:41 +00:00
|
|
|
const int classLen = _countof(METERWINDOW_CLASS_NAME) + (DEBUG_VERBOSE ? 32 : 0);
|
|
|
|
WCHAR className[classLen];
|
2010-03-20 19:40:30 +00:00
|
|
|
CMeterWindow* Window;
|
2011-09-03 21:51:25 +00:00
|
|
|
WCHAR flag;
|
2010-03-20 19:40:30 +00:00
|
|
|
|
2011-11-18 07:33:41 +00:00
|
|
|
if (GetClassName(hwnd, className, classLen) > 0 &&
|
2010-09-04 08:04:13 +00:00
|
|
|
wcscmp(className, METERWINDOW_CLASS_NAME) == 0 &&
|
2011-11-08 10:32:57 +00:00
|
|
|
(Window = Rainmeter->GetMeterWindow(hwnd)))
|
2010-03-20 19:40:30 +00:00
|
|
|
{
|
2010-03-29 21:50:05 +00:00
|
|
|
ZPOSITION zPos = Window->GetWindowZPosition();
|
2011-11-10 11:50:47 +00:00
|
|
|
if (zPos == ZPOSITION_ONDESKTOP ||
|
|
|
|
(zPos == ZPOSITION_NORMAL && Rainmeter->IsNormalStayDesktop()) ||
|
|
|
|
zPos == ZPOSITION_ONBOTTOM)
|
2010-03-20 19:40:30 +00:00
|
|
|
{
|
|
|
|
if (lParam)
|
|
|
|
{
|
|
|
|
((std::vector<CMeterWindow*>*)lParam)->push_back(Window);
|
|
|
|
}
|
2011-09-03 21:51:25 +00:00
|
|
|
|
|
|
|
if (logging) flag = L'+';
|
2010-03-20 19:40:30 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-09-03 21:51:25 +00:00
|
|
|
if (logging) flag = L'-';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (logging)
|
|
|
|
{
|
|
|
|
LogWithArgs(LOG_DEBUG, L"%c [%c] 0x%p : %s (Name: \"%s\", zPos=%i)",
|
|
|
|
flag, IsWindowVisible(hwnd) ? L'V' : L'H', hwnd, className, Window->GetSkinName().c_str(), (int)zPos);
|
2010-03-20 19:40:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-09-03 21:51:25 +00:00
|
|
|
if (logging)
|
|
|
|
{
|
|
|
|
flag = (hwnd == CSystem::GetHelperWindow()) ? L'o' : ' ';
|
|
|
|
LogWithArgs(LOG_DEBUG, L"%c [%c] 0x%p : %s", flag, IsWindowVisible(hwnd) ? L'V' : L'H', hwnd, className);
|
|
|
|
}
|
2010-03-20 19:40:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** ChangeZPosInOrder
|
|
|
|
**
|
|
|
|
** Arranges the meter window in Z-order.
|
|
|
|
**
|
|
|
|
*/
|
|
|
|
void CSystem::ChangeZPosInOrder()
|
|
|
|
{
|
2011-11-08 10:32:57 +00:00
|
|
|
bool logging = Rainmeter->GetDebug() && DEBUG_VERBOSE;
|
|
|
|
std::vector<CMeterWindow*> windowsInZOrder;
|
2010-03-20 19:40:30 +00:00
|
|
|
|
2011-11-08 10:32:57 +00:00
|
|
|
if (logging) Log(LOG_DEBUG, L"1: ----- BEFORE -----");
|
2010-03-20 19:40:30 +00:00
|
|
|
|
2011-11-08 10:32:57 +00:00
|
|
|
// Retrieve the Rainmeter's meter windows in Z-order
|
|
|
|
EnumWindows(MyEnumWindowsProc, (LPARAM)(&windowsInZOrder));
|
2010-11-24 22:30:18 +00:00
|
|
|
|
2011-11-18 07:33:41 +00:00
|
|
|
auto resetZPos = [&](ZPOSITION zpos)
|
2011-11-08 10:32:57 +00:00
|
|
|
{
|
|
|
|
// Reset ZPos in Z-order (Bottom)
|
2012-02-07 08:32:37 +00:00
|
|
|
std::vector<CMeterWindow*>::const_iterator iter = windowsInZOrder.begin();
|
|
|
|
for ( ; iter != windowsInZOrder.end(); ++iter)
|
2010-11-24 22:30:18 +00:00
|
|
|
{
|
2011-11-10 11:50:47 +00:00
|
|
|
if ((*iter)->GetWindowZPosition() == zpos)
|
2010-11-24 22:30:18 +00:00
|
|
|
{
|
2011-11-10 11:50:47 +00:00
|
|
|
(*iter)->ChangeZPos(zpos); // reset
|
2010-11-24 22:30:18 +00:00
|
|
|
}
|
2010-03-20 19:40:30 +00:00
|
|
|
}
|
2011-11-10 11:50:47 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
if (Rainmeter->IsNormalStayDesktop())
|
|
|
|
{
|
|
|
|
resetZPos(ZPOSITION_NORMAL);
|
2011-11-08 10:32:57 +00:00
|
|
|
}
|
2010-03-20 19:40:30 +00:00
|
|
|
|
2011-11-10 11:50:47 +00:00
|
|
|
if (!c_ShowDesktop)
|
2011-11-08 10:32:57 +00:00
|
|
|
{
|
2011-11-10 11:50:47 +00:00
|
|
|
resetZPos(ZPOSITION_ONBOTTOM);
|
2010-03-29 21:50:05 +00:00
|
|
|
}
|
2011-11-08 10:32:57 +00:00
|
|
|
|
2011-11-10 11:50:47 +00:00
|
|
|
resetZPos(ZPOSITION_ONDESKTOP);
|
|
|
|
|
2011-11-08 10:32:57 +00:00
|
|
|
if (logging)
|
|
|
|
{
|
|
|
|
Log(LOG_DEBUG, L"2: ----- AFTER -----");
|
|
|
|
|
|
|
|
// Log all windows in Z-order
|
|
|
|
EnumWindows(MyEnumWindowsProc, (LPARAM)NULL);
|
|
|
|
}
|
2010-03-29 21:50:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** PrepareHelperWindow
|
|
|
|
**
|
|
|
|
** Moves the helper window to the reference position.
|
|
|
|
**
|
|
|
|
*/
|
|
|
|
void CSystem::PrepareHelperWindow(HWND WorkerW)
|
|
|
|
{
|
2011-09-28 18:28:35 +00:00
|
|
|
bool logging = Rainmeter->GetDebug() && DEBUG_VERBOSE;
|
2010-03-29 21:50:05 +00:00
|
|
|
|
2011-09-03 21:51:25 +00:00
|
|
|
SetWindowPos(c_Window, HWND_BOTTOM, 0, 0, 0, 0, ZPOS_FLAGS); // always on bottom
|
2010-12-21 04:49:01 +00:00
|
|
|
|
2010-03-29 21:50:05 +00:00
|
|
|
if (c_ShowDesktop && WorkerW)
|
|
|
|
{
|
|
|
|
// Set WS_EX_TOPMOST flag
|
2011-09-03 21:51:25 +00:00
|
|
|
SetWindowPos(c_HelperWindow, HWND_TOPMOST, 0, 0, 0, 0, ZPOS_FLAGS);
|
2010-03-29 21:50:05 +00:00
|
|
|
|
|
|
|
// Find the "backmost" topmost window
|
|
|
|
HWND hwnd = WorkerW;
|
|
|
|
while (hwnd = ::GetNextWindow(hwnd, GW_HWNDPREV))
|
|
|
|
{
|
|
|
|
if (GetWindowLong(hwnd, GWL_EXSTYLE) & WS_EX_TOPMOST)
|
|
|
|
{
|
2011-04-19 01:20:17 +00:00
|
|
|
WCHAR className[64], windowText[64];
|
2010-03-20 19:40:30 +00:00
|
|
|
|
2010-03-29 21:50:05 +00:00
|
|
|
if (logging)
|
|
|
|
{
|
2011-04-19 01:20:17 +00:00
|
|
|
GetClassName(hwnd, className, 64);
|
|
|
|
GetWindowText(hwnd, windowText, 64);
|
2011-09-03 21:51:25 +00:00
|
|
|
|
2011-09-06 08:41:42 +00:00
|
|
|
SetLastError(ERROR_SUCCESS);
|
2010-03-29 21:50:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Insert the helper window after the found window
|
2011-09-03 21:51:25 +00:00
|
|
|
if (0 != SetWindowPos(c_HelperWindow, hwnd, 0, 0, 0, 0, ZPOS_FLAGS))
|
2010-03-29 21:50:05 +00:00
|
|
|
{
|
|
|
|
if (logging)
|
|
|
|
{
|
2010-12-19 23:06:13 +00:00
|
|
|
LogWithArgs(LOG_DEBUG, L"System: HelperWindow: hwnd=0x%p (WorkerW=0x%p), hwndInsertAfter=0x%p (\"%s\" %s) - %s",
|
2010-03-29 21:50:05 +00:00
|
|
|
c_HelperWindow, WorkerW, hwnd, windowText, className, (GetWindowLong(c_HelperWindow, GWL_EXSTYLE) & WS_EX_TOPMOST) ? L"TOPMOST" : L"NORMAL");
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (logging)
|
|
|
|
{
|
2011-09-03 21:51:25 +00:00
|
|
|
DWORD err = GetLastError();
|
|
|
|
LogWithArgs(LOG_DEBUG, L"System: HelperWindow: hwnd=0x%p (WorkerW=0x%p), hwndInsertAfter=0x%p (\"%s\" %s) - FAILED (ErrorCode=0x%08X)",
|
|
|
|
c_HelperWindow, WorkerW, hwnd, windowText, className, err);
|
2010-03-29 21:50:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (logging)
|
|
|
|
{
|
2010-12-19 23:06:13 +00:00
|
|
|
LogWithArgs(LOG_DEBUG, L"System: HelperWindow: hwnd=0x%p (WorkerW=0x%p), hwndInsertAfter=HWND_TOPMOST - %s",
|
2010-03-29 21:50:05 +00:00
|
|
|
c_HelperWindow, WorkerW, (GetWindowLong(c_HelperWindow, GWL_EXSTYLE) & WS_EX_TOPMOST) ? L"TOPMOST" : L"NORMAL");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Insert the helper window to the bottom
|
2011-09-03 21:51:25 +00:00
|
|
|
SetWindowPos(c_HelperWindow, HWND_BOTTOM, 0, 0, 0, 0, ZPOS_FLAGS);
|
2010-03-29 21:50:05 +00:00
|
|
|
|
|
|
|
if (logging)
|
|
|
|
{
|
2010-12-19 23:06:13 +00:00
|
|
|
LogWithArgs(LOG_DEBUG, L"System: HelperWindow: hwnd=0x%p (WorkerW=0x%p), hwndInsertAfter=HWND_BOTTOM - %s",
|
2010-03-29 21:50:05 +00:00
|
|
|
c_HelperWindow, WorkerW, (GetWindowLong(c_HelperWindow, GWL_EXSTYLE) & WS_EX_TOPMOST) ? L"TOPMOST" : L"NORMAL");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** CheckDesktopState
|
|
|
|
**
|
|
|
|
** Changes the "Show Desktop" state.
|
|
|
|
**
|
|
|
|
*/
|
2011-06-23 13:29:51 +00:00
|
|
|
bool CSystem::CheckDesktopState(HWND WorkerW)
|
2010-03-29 21:50:05 +00:00
|
|
|
{
|
|
|
|
HWND hwnd = NULL;
|
|
|
|
|
2011-06-23 13:29:51 +00:00
|
|
|
if (WorkerW && IsWindowVisible(WorkerW))
|
2010-03-29 21:50:05 +00:00
|
|
|
{
|
|
|
|
hwnd = FindWindowEx(NULL, WorkerW, L"RainmeterSystemClass", L"SystemWindow");
|
|
|
|
}
|
|
|
|
|
2011-06-23 13:29:51 +00:00
|
|
|
bool stateChanged = (hwnd && !c_ShowDesktop) || (!hwnd && c_ShowDesktop);
|
|
|
|
|
|
|
|
if (stateChanged)
|
2010-03-29 21:50:05 +00:00
|
|
|
{
|
|
|
|
c_ShowDesktop = !c_ShowDesktop;
|
|
|
|
|
2011-09-28 18:28:35 +00:00
|
|
|
if (Rainmeter->GetDebug())
|
2010-03-29 21:50:05 +00:00
|
|
|
{
|
2011-09-09 16:31:55 +00:00
|
|
|
LogWithArgs(LOG_DEBUG, L"System: \"Show %s\" has been detected.",
|
|
|
|
c_ShowDesktop ? L"desktop" : L"open windows");
|
2010-03-29 21:50:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PrepareHelperWindow(WorkerW);
|
|
|
|
|
|
|
|
ChangeZPosInOrder();
|
2011-11-10 11:50:47 +00:00
|
|
|
|
|
|
|
if (c_ShowDesktop)
|
|
|
|
{
|
2011-11-10 13:44:19 +00:00
|
|
|
SetTimer(c_Window, TIMER_SHOWDESKTOP, INTERVAL_RESTOREWINDOWS, NULL);
|
2011-11-10 11:50:47 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SetTimer(c_Window, TIMER_SHOWDESKTOP, INTERVAL_SHOWDESKTOP, NULL);
|
|
|
|
}
|
2010-03-29 21:50:05 +00:00
|
|
|
}
|
2011-06-23 13:29:51 +00:00
|
|
|
|
|
|
|
return stateChanged;
|
2010-03-29 21:50:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** MyWinEventHook
|
|
|
|
**
|
|
|
|
** The event hook procedure
|
|
|
|
**
|
|
|
|
*/
|
|
|
|
void CALLBACK CSystem::MyWinEventProc(HWINEVENTHOOK hWinEventHook, DWORD event, HWND hwnd, LONG idObject, LONG idChild, DWORD dwEventThread, DWORD dwmsEventTime)
|
|
|
|
{
|
|
|
|
if (event == EVENT_SYSTEM_FOREGROUND)
|
|
|
|
{
|
|
|
|
if (!c_ShowDesktop)
|
|
|
|
{
|
2011-11-18 07:33:41 +00:00
|
|
|
const int classLen = _countof(L"WorkerW");
|
|
|
|
WCHAR className[classLen];
|
|
|
|
if (GetClassName(hwnd, className, classLen) > 0 &&
|
2011-08-10 14:13:53 +00:00
|
|
|
wcscmp(className, L"WorkerW") == 0 &&
|
2011-06-23 13:29:51 +00:00
|
|
|
BelongToSameProcess(GetDefaultShellWindow(), hwnd))
|
2010-03-20 19:40:30 +00:00
|
|
|
{
|
2011-06-23 13:29:51 +00:00
|
|
|
const int max = 5;
|
|
|
|
int loop = 0;
|
|
|
|
while (loop < max && FindWindowEx(hwnd, NULL, L"SHELLDLL_DefView", L"") == NULL)
|
|
|
|
{
|
|
|
|
Sleep(2); // Wait for 2-16 ms before retrying
|
|
|
|
++loop;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (loop < max)
|
|
|
|
{
|
|
|
|
loop = 0;
|
|
|
|
while (loop < max && !CheckDesktopState(hwnd))
|
|
|
|
{
|
|
|
|
Sleep(2); // Wait for 2-16 ms before retrying
|
|
|
|
++loop;
|
|
|
|
}
|
|
|
|
}
|
2010-03-20 19:40:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** WndProc
|
|
|
|
**
|
|
|
|
** The window procedure
|
|
|
|
**
|
|
|
|
*/
|
|
|
|
LRESULT CALLBACK CSystem::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
|
|
|
{
|
2010-12-21 04:49:01 +00:00
|
|
|
if (hWnd != c_Window)
|
2010-03-29 21:50:05 +00:00
|
|
|
{
|
2011-09-06 08:41:42 +00:00
|
|
|
if (uMsg == WM_WINDOWPOSCHANGING)
|
|
|
|
{
|
|
|
|
((LPWINDOWPOS)lParam)->flags |= SWP_NOZORDER;
|
|
|
|
return 0;
|
|
|
|
}
|
2010-03-29 21:50:05 +00:00
|
|
|
return DefWindowProc(hWnd, uMsg, wParam, lParam);
|
|
|
|
}
|
|
|
|
|
2010-03-20 19:40:30 +00:00
|
|
|
switch (uMsg)
|
|
|
|
{
|
|
|
|
case WM_WINDOWPOSCHANGING:
|
|
|
|
((LPWINDOWPOS)lParam)->flags |= SWP_NOZORDER;
|
2012-02-15 02:51:27 +00:00
|
|
|
break;
|
2010-03-20 19:40:30 +00:00
|
|
|
|
|
|
|
case WM_TIMER:
|
2012-02-15 02:51:27 +00:00
|
|
|
if (wParam == TIMER_SHOWDESKTOP)
|
2010-03-20 19:40:30 +00:00
|
|
|
{
|
2010-03-29 21:50:05 +00:00
|
|
|
CheckDesktopState(GetWorkerW());
|
2010-03-20 19:40:30 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WM_DISPLAYCHANGE:
|
2011-09-09 16:31:55 +00:00
|
|
|
Log(LOG_NOTICE, L"System: Display settings changed");
|
2010-03-20 19:40:30 +00:00
|
|
|
ClearMultiMonitorInfo();
|
|
|
|
CConfigParser::ClearMultiMonitorVariables();
|
|
|
|
case WM_SETTINGCHANGE:
|
|
|
|
if (uMsg == WM_DISPLAYCHANGE || (uMsg == WM_SETTINGCHANGE && wParam == SPI_SETWORKAREA))
|
|
|
|
{
|
|
|
|
if (uMsg == WM_SETTINGCHANGE) // SPI_SETWORKAREA
|
|
|
|
{
|
2011-09-09 16:31:55 +00:00
|
|
|
Log(LOG_NOTICE, L"System: Work area changed");
|
2010-03-20 19:40:30 +00:00
|
|
|
UpdateWorkareaInfo();
|
|
|
|
CConfigParser::UpdateWorkareaVariables();
|
|
|
|
}
|
|
|
|
|
2011-11-08 10:32:57 +00:00
|
|
|
// Deliver WM_DISPLAYCHANGE / WM_SETTINGCHANGE message to all meter windows
|
2012-02-07 08:32:37 +00:00
|
|
|
std::map<std::wstring, CMeterWindow*>::const_iterator iter = Rainmeter->GetAllMeterWindows().begin();
|
|
|
|
for ( ; iter != Rainmeter->GetAllMeterWindows().end(); ++iter)
|
2010-03-20 19:40:30 +00:00
|
|
|
{
|
2011-11-08 10:32:57 +00:00
|
|
|
PostMessage((*iter).second->GetWindow(), WM_DELAYED_MOVE, (WPARAM)uMsg, (LPARAM)0);
|
2010-03-20 19:40:30 +00:00
|
|
|
}
|
|
|
|
}
|
2012-02-15 02:51:27 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return DefWindowProc(hWnd, uMsg, wParam, lParam);
|
2010-03-20 19:40:30 +00:00
|
|
|
}
|
|
|
|
|
2012-02-15 02:51:27 +00:00
|
|
|
return 0;
|
2010-03-20 19:40:30 +00:00
|
|
|
}
|
|
|
|
|
2011-06-05 12:32:18 +00:00
|
|
|
/*
|
|
|
|
** GetTickCount64
|
|
|
|
**
|
|
|
|
** Retrieves the number of milliseconds that have elapsed since the system was started.
|
|
|
|
** In XP, returns the predictive value due to the 32bit limitation.
|
|
|
|
**
|
|
|
|
*/
|
|
|
|
ULONGLONG CSystem::GetTickCount64()
|
|
|
|
{
|
|
|
|
typedef ULONGLONG (WINAPI * FPGETTICKCOUNT64)();
|
|
|
|
static FPGETTICKCOUNT64 c_GetTickCount64 = (FPGETTICKCOUNT64)GetProcAddress(GetModuleHandle(L"kernel32"), "GetTickCount64");
|
|
|
|
|
|
|
|
if (c_GetTickCount64)
|
|
|
|
{
|
|
|
|
return c_GetTickCount64();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
static ULONGLONG lastTicks = 0;
|
|
|
|
ULONGLONG ticks = GetTickCount();
|
|
|
|
while (ticks < lastTicks) ticks += 0x100000000;
|
|
|
|
lastTicks = ticks;
|
|
|
|
return ticks;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-08 19:02:31 +00:00
|
|
|
/*
|
|
|
|
** IsFileWritable
|
|
|
|
**
|
|
|
|
** Checks if file is writable.
|
|
|
|
**
|
|
|
|
*/
|
|
|
|
bool CSystem::IsFileWritable(LPCWSTR file)
|
|
|
|
{
|
|
|
|
HANDLE hFile = CreateFile(file, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
|
|
|
|
if (hFile == INVALID_HANDLE_VALUE)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
CloseHandle(hFile);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-09-11 19:39:45 +00:00
|
|
|
/*
|
|
|
|
** RmLoadLibrary
|
|
|
|
**
|
|
|
|
** This function is a wrapper function for LoadLibrary().
|
|
|
|
**
|
2011-09-29 17:14:51 +00:00
|
|
|
** Avoids loading a DLL from current directory.
|
2010-09-11 19:39:45 +00:00
|
|
|
**
|
|
|
|
*/
|
|
|
|
HMODULE CSystem::RmLoadLibrary(LPCWSTR lpLibFileName, DWORD* dwError, bool ignoreErrors)
|
|
|
|
{
|
|
|
|
UINT oldMode;
|
2011-09-29 17:14:51 +00:00
|
|
|
|
2010-09-11 19:39:45 +00:00
|
|
|
if (ignoreErrors)
|
|
|
|
{
|
|
|
|
oldMode = SetErrorMode(0);
|
|
|
|
SetErrorMode(oldMode | SEM_FAILCRITICALERRORS); // Prevent the system from displaying message box
|
|
|
|
}
|
|
|
|
|
2011-09-29 17:14:51 +00:00
|
|
|
// Remove current directory from DLL search path
|
|
|
|
SetDllDirectory(L"");
|
|
|
|
|
2010-09-11 19:39:45 +00:00
|
|
|
SetLastError(ERROR_SUCCESS);
|
2011-09-28 18:28:35 +00:00
|
|
|
HMODULE hLib = LoadLibrary(lpLibFileName);
|
2010-09-11 19:39:45 +00:00
|
|
|
|
2011-09-28 18:28:35 +00:00
|
|
|
if (dwError)
|
2010-09-11 19:39:45 +00:00
|
|
|
{
|
2011-09-28 18:28:35 +00:00
|
|
|
*dwError = GetLastError();
|
2010-09-11 19:39:45 +00:00
|
|
|
}
|
|
|
|
|
2011-09-28 18:28:35 +00:00
|
|
|
if (ignoreErrors)
|
2010-09-11 19:39:45 +00:00
|
|
|
{
|
2011-09-28 18:28:35 +00:00
|
|
|
SetErrorMode(oldMode); // Reset
|
2010-09-11 19:39:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return hLib;
|
|
|
|
}
|
|
|
|
|
2011-05-23 20:21:19 +00:00
|
|
|
/*
|
|
|
|
** ResetWorkingDirectory
|
|
|
|
**
|
|
|
|
** Resets working directory to default.
|
|
|
|
**
|
|
|
|
*/
|
|
|
|
void CSystem::ResetWorkingDirectory()
|
|
|
|
{
|
|
|
|
WCHAR directory[MAX_PATH] = {0};
|
|
|
|
GetCurrentDirectory(MAX_PATH, directory);
|
|
|
|
|
|
|
|
if (_wcsicmp(directory, c_WorkingDirectory.c_str()) != 0)
|
|
|
|
{
|
|
|
|
SetCurrentDirectory(c_WorkingDirectory.c_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-28 10:58:26 +00:00
|
|
|
/*
|
|
|
|
** SetClipboardText
|
|
|
|
**
|
|
|
|
** Sets clipboard text to given string.
|
|
|
|
**
|
|
|
|
*/
|
|
|
|
void CSystem::SetClipboardText(const std::wstring& text)
|
|
|
|
{
|
|
|
|
if (OpenClipboard(NULL))
|
|
|
|
{
|
|
|
|
// Include terminating null char
|
|
|
|
size_t len = text.length() + 1;
|
|
|
|
|
|
|
|
HGLOBAL hMem = GlobalAlloc(GMEM_MOVEABLE, len * sizeof(WCHAR));
|
|
|
|
if (hMem)
|
|
|
|
{
|
|
|
|
LPVOID data = GlobalLock(hMem);
|
2011-12-09 08:40:19 +00:00
|
|
|
memcpy(data, text.c_str(), len * sizeof(WCHAR));
|
|
|
|
GlobalUnlock(hMem);
|
2011-08-28 10:58:26 +00:00
|
|
|
|
2011-12-09 08:40:19 +00:00
|
|
|
EmptyClipboard();
|
|
|
|
if (!SetClipboardData(CF_UNICODETEXT, hMem))
|
|
|
|
{
|
|
|
|
GlobalFree(hMem);
|
2011-08-28 10:58:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CloseClipboard();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-04 15:54:30 +00:00
|
|
|
/*
|
|
|
|
** SetWallpaper
|
|
|
|
**
|
|
|
|
** Sets the system wallpapar.
|
|
|
|
**
|
|
|
|
*/
|
|
|
|
void CSystem::SetWallpaper(const std::wstring& wallpaper, const std::wstring& style)
|
|
|
|
{
|
|
|
|
auto setWallpaperStyle = [&]()
|
|
|
|
{
|
|
|
|
if (!style.empty())
|
|
|
|
{
|
|
|
|
HKEY hKey;
|
|
|
|
if (RegOpenKeyEx(HKEY_CURRENT_USER, L"Control Panel\\Desktop", 0, KEY_SET_VALUE, &hKey) == ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
const WCHAR* wallStyle = NULL;
|
|
|
|
const WCHAR* wallTile = L"0";
|
|
|
|
|
|
|
|
const WCHAR* option = style.c_str();
|
|
|
|
if (_wcsicmp(option, L"CENTER") == 0)
|
|
|
|
{
|
|
|
|
wallStyle = L"0";
|
|
|
|
}
|
|
|
|
else if (_wcsicmp(option, L"TILE") == 0)
|
|
|
|
{
|
|
|
|
wallStyle = L"0";
|
|
|
|
wallTile = L"1";
|
|
|
|
}
|
|
|
|
else if (_wcsicmp(option, L"STRETCH") == 0)
|
|
|
|
{
|
|
|
|
wallStyle = L"2";
|
|
|
|
}
|
|
|
|
else if (GetOSPlatform() >= OSPLATFORM_7)
|
|
|
|
{
|
|
|
|
if (_wcsicmp(option, L"FIT") == 0)
|
|
|
|
{
|
|
|
|
wallStyle = L"6";
|
|
|
|
}
|
|
|
|
else if (_wcsicmp(option, L"FILL") == 0)
|
|
|
|
{
|
|
|
|
wallStyle = L"10";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (wallStyle)
|
|
|
|
{
|
|
|
|
RegSetValueEx(hKey, L"WallpaperStyle", 0, REG_SZ, (const BYTE*)wallStyle, sizeof(WCHAR) * 2);
|
|
|
|
RegSetValueEx(hKey, L"TileWallpaper", 0, REG_SZ, (const BYTE*)wallTile, sizeof(WCHAR) * 2);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Log(LOG_ERROR, L"!SetWallpaper: Invalid style");
|
|
|
|
}
|
|
|
|
|
|
|
|
RegCloseKey(hKey);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
if (!wallpaper.empty())
|
|
|
|
{
|
2012-02-04 16:51:14 +00:00
|
|
|
if (_waccess(wallpaper.c_str(), 0) == -1)
|
|
|
|
{
|
|
|
|
LogWithArgs(LOG_ERROR, L"!SetWallpaper: Unable to read file: %s", wallpaper.c_str());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-02-04 15:54:30 +00:00
|
|
|
if (GetOSPlatform() < OSPLATFORM_7)
|
|
|
|
{
|
|
|
|
// Gotta convert to .bmp for pre-7
|
|
|
|
Bitmap* bitmap = Bitmap::FromFile(wallpaper.c_str());
|
|
|
|
if (bitmap && bitmap->GetLastStatus() == Ok)
|
|
|
|
{
|
|
|
|
std::wstring file = Rainmeter->GetSettingsPath();
|
|
|
|
file += L"Wallpaper.bmp";
|
|
|
|
|
2012-02-04 16:06:29 +00:00
|
|
|
const CLSID bmpClsid = { 0x557cf400, 0x1a04, 0x11d3, { 0x9a, 0x73, 0x0, 0x0, 0xf8, 0x1e, 0xf3, 0x2e } };
|
|
|
|
if (bitmap->Save(file.c_str(), &bmpClsid) == Ok)
|
2012-02-04 15:54:30 +00:00
|
|
|
{
|
|
|
|
setWallpaperStyle();
|
|
|
|
SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, (void*)file.c_str(), SPIF_UPDATEINIFILE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
setWallpaperStyle();
|
|
|
|
SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, (void*)wallpaper.c_str(), SPIF_UPDATEINIFILE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-29 19:21:57 +00:00
|
|
|
/*
|
2010-08-03 15:10:42 +00:00
|
|
|
** CopyFiles
|
|
|
|
**
|
|
|
|
** Copies files and folders from one location to another.
|
|
|
|
**
|
|
|
|
*/
|
|
|
|
bool CSystem::CopyFiles(const std::wstring& strFrom, const std::wstring& strTo, bool bMove)
|
|
|
|
{
|
|
|
|
std::wstring tmpFrom(strFrom), tmpTo(strTo);
|
|
|
|
|
|
|
|
// The strings must end with double nul
|
2011-09-04 18:06:19 +00:00
|
|
|
tmpFrom.append(1, L'\0');
|
|
|
|
tmpTo.append(1, L'\0');
|
2010-08-03 15:10:42 +00:00
|
|
|
|
2011-11-14 14:32:11 +00:00
|
|
|
SHFILEOPSTRUCT fo =
|
|
|
|
{
|
|
|
|
NULL,
|
|
|
|
bMove ? FO_MOVE : FO_COPY,
|
|
|
|
tmpFrom.c_str(),
|
|
|
|
tmpTo.c_str(),
|
|
|
|
FOF_NO_UI | FOF_NOCONFIRMATION | FOF_ALLOWUNDO
|
|
|
|
};
|
2010-08-03 15:10:42 +00:00
|
|
|
|
|
|
|
int result = SHFileOperation(&fo);
|
|
|
|
if (result != 0)
|
|
|
|
{
|
2010-12-19 23:06:13 +00:00
|
|
|
LogWithArgs(LOG_ERROR, L"Unable to copy files from %s to %s (%i)", strFrom.c_str(), strTo.c_str(), result);
|
2010-08-03 15:10:42 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-03-29 19:21:57 +00:00
|
|
|
/*
|
2010-08-03 15:10:42 +00:00
|
|
|
** RemoveFile
|
|
|
|
**
|
|
|
|
** Removes a file even if a file is read-only.
|
|
|
|
**
|
|
|
|
*/
|
|
|
|
bool CSystem::RemoveFile(const std::wstring& file)
|
|
|
|
{
|
|
|
|
DWORD attr = GetFileAttributes(file.c_str());
|
|
|
|
if (attr == -1 || (attr & FILE_ATTRIBUTE_READONLY))
|
|
|
|
{
|
|
|
|
// Unset read-only
|
|
|
|
SetFileAttributes(file.c_str(), (attr == -1) ? FILE_ATTRIBUTE_NORMAL : attr - FILE_ATTRIBUTE_READONLY);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (DeleteFile(file.c_str()) != 0);
|
|
|
|
}
|
|
|
|
|
2011-08-28 10:58:26 +00:00
|
|
|
/*
|
|
|
|
** RemoveFolder
|
|
|
|
**
|
|
|
|
** Recursively removes folder.
|
|
|
|
**
|
|
|
|
*/
|
|
|
|
bool CSystem::RemoveFolder(const std::wstring& strFolder)
|
|
|
|
{
|
|
|
|
std::wstring tmpFolder(strFolder);
|
|
|
|
|
|
|
|
// The strings must end with double nul
|
2011-09-04 18:06:19 +00:00
|
|
|
tmpFolder.append(1, L'\0');
|
2011-08-28 10:58:26 +00:00
|
|
|
|
2011-11-14 14:32:11 +00:00
|
|
|
SHFILEOPSTRUCT fo =
|
|
|
|
{
|
|
|
|
NULL,
|
|
|
|
FO_DELETE,
|
|
|
|
tmpFolder.c_str(),
|
|
|
|
NULL,
|
|
|
|
FOF_NO_UI | FOF_NOCONFIRMATION | FOF_ALLOWUNDO
|
|
|
|
};
|
2011-08-28 10:58:26 +00:00
|
|
|
|
|
|
|
int result = SHFileOperation(&fo);
|
|
|
|
if (result != 0)
|
|
|
|
{
|
|
|
|
LogWithArgs(LOG_ERROR, L"Unable to delete folder %s (%i)", strFolder.c_str(), result);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-03-29 19:21:57 +00:00
|
|
|
/*
|
2011-11-10 13:44:19 +00:00
|
|
|
** UpdateIniFileMappingList
|
2010-08-03 15:10:42 +00:00
|
|
|
**
|
|
|
|
** Retrieves the "IniFileMapping" entries from Registry.
|
|
|
|
**
|
|
|
|
*/
|
2011-11-10 13:44:19 +00:00
|
|
|
void CSystem::UpdateIniFileMappingList()
|
2010-08-03 15:10:42 +00:00
|
|
|
{
|
2011-12-02 10:42:11 +00:00
|
|
|
static ULONGLONG s_LastWriteTime = 0;
|
2010-08-03 15:10:42 +00:00
|
|
|
|
2011-11-10 13:44:19 +00:00
|
|
|
HKEY hKey;
|
|
|
|
LONG ret = RegOpenKeyEx(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\IniFileMapping", 0, KEY_QUERY_VALUE | KEY_ENUMERATE_SUB_KEYS, &hKey);
|
2010-08-03 15:10:42 +00:00
|
|
|
if (ret == ERROR_SUCCESS)
|
|
|
|
{
|
2011-11-10 13:44:19 +00:00
|
|
|
DWORD numSubKeys;
|
2011-12-02 10:42:11 +00:00
|
|
|
ULONGLONG ftLastWriteTime;
|
2011-11-10 13:44:19 +00:00
|
|
|
bool changed = false;
|
2010-08-03 15:10:42 +00:00
|
|
|
|
2011-11-10 13:44:19 +00:00
|
|
|
ret = RegQueryInfoKey(hKey, NULL, NULL, NULL, &numSubKeys, NULL, NULL, NULL, NULL, NULL, NULL, (LPFILETIME)&ftLastWriteTime);
|
|
|
|
if (ret == ERROR_SUCCESS)
|
2010-08-03 15:10:42 +00:00
|
|
|
{
|
2011-12-02 10:42:11 +00:00
|
|
|
//LogWithArgs(LOG_DEBUG, L"IniFileMapping: numSubKeys=%u, ftLastWriteTime=%llu", numSubKeys, ftLastWriteTime);
|
2011-11-10 13:44:19 +00:00
|
|
|
|
2011-12-02 10:42:11 +00:00
|
|
|
if (ftLastWriteTime != s_LastWriteTime ||
|
2011-11-10 13:44:19 +00:00
|
|
|
numSubKeys != c_IniFileMappings.size())
|
2010-08-03 15:10:42 +00:00
|
|
|
{
|
2011-12-02 10:42:11 +00:00
|
|
|
s_LastWriteTime = ftLastWriteTime;
|
2011-11-10 13:44:19 +00:00
|
|
|
if (numSubKeys > c_IniFileMappings.capacity())
|
|
|
|
{
|
|
|
|
c_IniFileMappings.reserve(numSubKeys);
|
|
|
|
}
|
|
|
|
changed = true;
|
2010-08-03 15:10:42 +00:00
|
|
|
}
|
|
|
|
}
|
2011-11-10 13:44:19 +00:00
|
|
|
else
|
|
|
|
{
|
2011-12-02 10:42:11 +00:00
|
|
|
s_LastWriteTime = 0;
|
2011-11-10 13:44:19 +00:00
|
|
|
changed = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (changed)
|
|
|
|
{
|
|
|
|
if (!c_IniFileMappings.empty())
|
|
|
|
{
|
|
|
|
c_IniFileMappings.clear();
|
|
|
|
}
|
|
|
|
|
2011-11-14 14:32:11 +00:00
|
|
|
WCHAR* buffer = new WCHAR[MAX_PATH];
|
2011-11-10 13:44:19 +00:00
|
|
|
DWORD index = 0, cch = MAX_PATH;
|
|
|
|
|
|
|
|
while ((ret = RegEnumKeyEx(hKey, index++, buffer, &cch, NULL, NULL, NULL, NULL)) != ERROR_NO_MORE_ITEMS)
|
|
|
|
{
|
|
|
|
if (ret == ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
c_IniFileMappings.push_back(buffer);
|
|
|
|
}
|
|
|
|
cch = MAX_PATH;
|
|
|
|
}
|
2011-11-14 14:32:11 +00:00
|
|
|
|
|
|
|
delete [] buffer;
|
2011-11-10 13:44:19 +00:00
|
|
|
}
|
|
|
|
|
2010-08-03 15:10:42 +00:00
|
|
|
RegCloseKey(hKey);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-29 19:21:57 +00:00
|
|
|
/*
|
2010-08-03 15:10:42 +00:00
|
|
|
** GetTemporaryFile
|
|
|
|
**
|
|
|
|
** Prepares a temporary file if iniFile is included in the "IniFileMapping" entries.
|
2011-11-08 17:21:29 +00:00
|
|
|
** If iniFile is not included, returns a empty string. If error occurred, returns "?".
|
2010-08-03 15:10:42 +00:00
|
|
|
** Note that a temporary file must be deleted by caller.
|
|
|
|
**
|
|
|
|
*/
|
2011-11-10 13:44:19 +00:00
|
|
|
std::wstring CSystem::GetTemporaryFile(const std::wstring& iniFile)
|
2010-08-03 15:10:42 +00:00
|
|
|
{
|
|
|
|
std::wstring temporary;
|
|
|
|
|
2011-11-10 13:44:19 +00:00
|
|
|
if (!c_IniFileMappings.empty())
|
2010-08-03 15:10:42 +00:00
|
|
|
{
|
2011-11-08 10:32:57 +00:00
|
|
|
std::wstring::size_type pos = iniFile.find_last_of(L"\\/");
|
2011-11-10 13:44:19 +00:00
|
|
|
const WCHAR* filename = iniFile.c_str() + ((pos != std::wstring::npos) ? pos + 1 : 0);
|
2010-08-03 15:10:42 +00:00
|
|
|
|
2011-11-10 13:44:19 +00:00
|
|
|
std::vector<std::wstring>::const_iterator iter = c_IniFileMappings.begin();
|
|
|
|
for ( ; iter != c_IniFileMappings.end(); ++iter)
|
2010-08-03 15:10:42 +00:00
|
|
|
{
|
2011-11-10 13:44:19 +00:00
|
|
|
if (_wcsicmp((*iter).c_str(), filename) == 0)
|
2010-08-03 15:10:42 +00:00
|
|
|
{
|
2011-11-14 14:32:11 +00:00
|
|
|
WCHAR* buffer = new WCHAR[MAX_PATH];
|
2010-08-03 15:10:42 +00:00
|
|
|
|
2011-11-14 14:32:11 +00:00
|
|
|
if (GetTempPath(MAX_PATH, buffer) != 0 &&
|
|
|
|
GetTempFileName(buffer, L"cfg", 0, buffer) != 0)
|
2010-08-03 15:10:42 +00:00
|
|
|
{
|
|
|
|
temporary = buffer;
|
|
|
|
|
2011-11-10 13:44:19 +00:00
|
|
|
std::wstring tmp = GetTemporaryFile(temporary);
|
2011-11-14 14:32:11 +00:00
|
|
|
if (!tmp.empty() || !CopyFiles(iniFile, temporary)) // temporary is reserved or failed
|
2010-08-03 15:10:42 +00:00
|
|
|
{
|
|
|
|
RemoveFile(temporary);
|
2011-11-14 14:32:11 +00:00
|
|
|
|
|
|
|
if (tmp.empty())
|
|
|
|
{
|
|
|
|
temporary = L"?";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
temporary.swap(tmp);
|
|
|
|
}
|
2010-08-03 15:10:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else // failed
|
|
|
|
{
|
2011-09-09 16:31:55 +00:00
|
|
|
LogWithArgs(LOG_ERROR, L"Unable to create temporary file to: %s", temporary.c_str());
|
2011-11-14 14:32:11 +00:00
|
|
|
temporary = L"?";
|
2010-08-03 15:10:42 +00:00
|
|
|
}
|
2011-11-14 14:32:11 +00:00
|
|
|
|
|
|
|
delete [] buffer;
|
|
|
|
break;
|
2010-08-03 15:10:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return temporary;
|
|
|
|
}
|