2009-02-10 18:37:48 +00:00
|
|
|
/*
|
|
|
|
Copyright (C) 2002 Kimmo Pekkola + few lsapi developers
|
|
|
|
|
|
|
|
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.
|
2009-02-10 18:37:48 +00:00
|
|
|
*/
|
|
|
|
|
2009-10-07 16:45:14 +00:00
|
|
|
#include "StdAfx.h"
|
2009-02-10 18:37:48 +00:00
|
|
|
#include "Litestep.h"
|
2009-07-21 12:26:50 +00:00
|
|
|
#include "Rainmeter.h"
|
2011-09-08 17:05:48 +00:00
|
|
|
#include "DialogAbout.h"
|
2010-09-11 19:39:45 +00:00
|
|
|
#include "System.h"
|
2009-02-10 18:37:48 +00:00
|
|
|
|
2013-05-31 14:18:52 +00:00
|
|
|
extern Rainmeter* g_Rainmeter;
|
2009-07-21 12:26:50 +00:00
|
|
|
|
2012-04-09 16:45:54 +00:00
|
|
|
UINT GetUniqueID()
|
|
|
|
{
|
|
|
|
static UINT id = 0;
|
|
|
|
return id++;
|
|
|
|
}
|
|
|
|
|
2011-09-24 09:13:13 +00:00
|
|
|
WCHAR* GetString(UINT id)
|
2011-09-23 16:28:38 +00:00
|
|
|
{
|
|
|
|
LPWSTR pData;
|
2013-05-31 14:18:52 +00:00
|
|
|
int len = LoadString(g_Rainmeter->GetResourceInstance(), id, (LPWSTR)&pData, 0);
|
2011-09-24 09:13:13 +00:00
|
|
|
return len ? pData : L"";
|
2011-09-23 16:28:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::wstring GetFormattedString(UINT id, ...)
|
|
|
|
{
|
2013-05-31 14:28:39 +00:00
|
|
|
LPWSTR pBuffer = nullptr;
|
|
|
|
va_list args = nullptr;
|
2011-09-23 16:28:38 +00:00
|
|
|
va_start(args, id);
|
|
|
|
|
2011-09-24 13:41:07 +00:00
|
|
|
DWORD len = FormatMessage(FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_ALLOCATE_BUFFER,
|
2012-02-14 17:58:03 +00:00
|
|
|
GetString(id),
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
(LPWSTR)&pBuffer,
|
|
|
|
0,
|
|
|
|
&args);
|
2011-09-23 16:28:38 +00:00
|
|
|
|
|
|
|
va_end(args);
|
|
|
|
|
2012-09-08 17:09:14 +00:00
|
|
|
std::wstring tmpSz(len ? pBuffer : L"", len);
|
2011-09-24 13:41:07 +00:00
|
|
|
if (pBuffer) LocalFree(pBuffer);
|
2011-09-23 16:28:38 +00:00
|
|
|
return tmpSz;
|
|
|
|
}
|
|
|
|
|
2012-05-05 15:53:33 +00:00
|
|
|
HICON GetIcon(UINT id, bool large)
|
|
|
|
{
|
|
|
|
typedef HRESULT (WINAPI * FPLOADICONMETRIC)(HINSTANCE hinst, PCWSTR pszName, int lims, HICON* phico);
|
|
|
|
|
2013-05-31 14:28:39 +00:00
|
|
|
HINSTANCE hExe = GetModuleHandle(nullptr);
|
2012-05-05 15:53:33 +00:00
|
|
|
HINSTANCE hComctl = GetModuleHandle(L"Comctl32");
|
|
|
|
if (hComctl)
|
|
|
|
{
|
|
|
|
// Try LoadIconMetric for better quality with high DPI
|
|
|
|
FPLOADICONMETRIC loadIconMetric = (FPLOADICONMETRIC)GetProcAddress(hComctl, "LoadIconMetric");
|
|
|
|
if (loadIconMetric)
|
|
|
|
{
|
|
|
|
HICON icon;
|
|
|
|
HRESULT hr = loadIconMetric(hExe, MAKEINTRESOURCE(id), large ? LIM_LARGE : LIM_SMALL, &icon);
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
|
|
|
return icon;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (HICON)LoadImage(
|
|
|
|
hExe,
|
|
|
|
MAKEINTRESOURCE(id),
|
|
|
|
IMAGE_ICON,
|
|
|
|
GetSystemMetrics(large ? SM_CXICON : SM_CXSMICON),
|
|
|
|
GetSystemMetrics(large ? SM_CYICON : SM_CYSMICON),
|
|
|
|
LR_SHARED);
|
|
|
|
}
|
|
|
|
|
2012-02-14 17:58:03 +00:00
|
|
|
void RmNullCRTInvalidParameterHandler(const wchar_t* expression, const wchar_t* function, const wchar_t* file, unsigned int line, uintptr_t pReserved)
|
2011-08-28 10:58:26 +00:00
|
|
|
{
|
|
|
|
// Do nothing.
|
|
|
|
}
|