Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions grepWinNP3/sktoolslib_mod/AeroControls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -530,9 +530,9 @@ LRESULT AeroControlBase::ButtonWindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, L
m_theme.GetThemeBackgroundContentRect(hTheme, hdcPaint, iPartId, iState, &rcPaint, &rc);

if (dwButtonStyle & BS_LEFTTEXT)
rc.right -= bmWidth + 2 * GetSystemMetrics(SM_CXEDGE);
rc.right -= bmWidth + 2 * GetSystemMetricsForDpi(SM_CXEDGE, GetDpiForWindow(hWnd));
else
rc.left += bmWidth + 2 * GetSystemMetrics(SM_CXEDGE);
rc.left += bmWidth + 2 * GetSystemMetricsForDpi(SM_CXEDGE, GetDpiForWindow(hWnd));

DTTOPTS dttOpts = {sizeof(DTTOPTS)};
dttOpts.dwFlags = DTT_COMPOSITED | DTT_GLOWSIZE;
Expand Down
2 changes: 1 addition & 1 deletion grepWinNP3/sktoolslib_mod/BaseDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ void CDialog::AdjustControlSize(UINT nID)
{
// we're dealing with radio buttons and check boxes,
// which means we have to add a little space for the checkbox
const int checkWidth = GetSystemMetrics(SM_CXMENUCHECK) + 2 * GetSystemMetrics(SM_CXEDGE) + CDPIAware::Instance().Scale(*this, 3);
const int checkWidth = GetSystemMetricsForDpi(SM_CXMENUCHECK, GetDpiForWindow(*this)) + 2 * GetSystemMetricsForDpi(SM_CXEDGE, GetDpiForWindow(*this)) + CDPIAware::Instance().Scale(*this, 3);
controlRect.right += checkWidth;
// now we have the rectangle the control really needs
if ((controlRectOrig.right - controlRectOrig.left) > (controlRect.right - controlRect.left))
Expand Down
4 changes: 2 additions & 2 deletions grepWinNP3/sktoolslib_mod/BrowseFolder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ void CBrowseFolder::SetFont(HWND hwnd, LPCWSTR fontName, int fontSize)
GetObject(GetWindowFont(hwnd), sizeof(lf), &lf);
lf.lfWeight = FW_REGULAR;
lf.lfHeight = static_cast<LONG>(fontSize);
lstrcpyn(lf.lfFaceName, fontName, _countof(lf.lfFaceName));
wcscpy_s(lf.lfFaceName, _countof(lf.lfFaceName), fontName);
HFONT hf = CreateFontIndirect(&lf);
SetBkMode(hdc, OPAQUE);
SendMessage(hwnd, WM_SETFONT, reinterpret_cast<WPARAM>(hf), TRUE);
Expand Down Expand Up @@ -407,7 +407,7 @@ int CBrowseFolder::BrowseCallBackProc(HWND hwnd, UINT uMsg, LPARAM lParam, LPARA
return 0;

//Gets the dimensions of the windows
const int controlHeight = ::GetSystemMetrics(SM_CYMENUCHECK) + 4;
const int controlHeight = ::GetSystemMetricsForDpi(SM_CYMENUCHECK, GetDpiForWindow(hwnd)) + 4;
GetWindowRect(hwnd, &dialog);
GetWindowRect(m_listView, &listViewRect);
POINT pt;
Expand Down
66 changes: 15 additions & 51 deletions grepWinNP3/sktoolslib_mod/DPIAware.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,7 @@ class CDPIAware
{
private:
CDPIAware()
: pfnGetDpiForWindow(nullptr)
, pfnGetDpiForSystem(nullptr)
, pfnGetSystemMetricsForDpi(nullptr)
, pfnSystemParametersInfoForDpi(nullptr)
, m_fInitialized(false)
: m_fInitialized(false)
, m_dpi(96)
{
}
Expand All @@ -43,9 +39,9 @@ class CDPIAware
int GetDPI(HWND hWnd)
{
_Init();
if (pfnGetDpiForWindow && hWnd)
if (hWnd)
{
return pfnGetDpiForWindow(hWnd);
return ::GetDpiForWindow(hWnd);
}
return m_dpi;
}
Expand Down Expand Up @@ -98,15 +94,19 @@ class CDPIAware
}

// returns the system parameters info. If possible adjusted for dpi.
// SystemParametersInfoForDpi only supports SPI_GETNONCLIENTMETRICS,
// SPI_GETICONMETRICS, and SPI_GETICONTITLELOGFONT. For all others,
// fall back to regular SystemParametersInfo.
UINT SystemParametersInfo(UINT uiAction, UINT uiParam, PVOID pvParam, UINT fWinIni)
{
_Init();
UINT ret = 0;
if (pfnSystemParametersInfoForDpi)
ret = pfnSystemParametersInfoForDpi(uiAction, uiParam, pvParam, fWinIni, m_dpi);
if (ret == 0)
ret = ::SystemParametersInfo(uiAction, uiParam, pvParam, fWinIni);
return ret;
if (uiAction == SPI_GETNONCLIENTMETRICS ||
uiAction == SPI_GETICONMETRICS ||
uiAction == SPI_GETICONTITLELOGFONT)
{
return ::SystemParametersInfoForDpi(uiAction, uiParam, pvParam, fWinIni, m_dpi);
}
return ::SystemParametersInfoW(uiAction, uiParam, pvParam, fWinIni);
}

// Invalidate any cached metrics.
Expand All @@ -118,31 +118,7 @@ class CDPIAware
{
if (!m_fInitialized)
{
auto hUser = ::GetModuleHandle(L"user32.dll");
if (hUser)
{
pfnGetDpiForWindow = reinterpret_cast<GetDpiForWindowFn *>(GetProcAddress(hUser, "GetDpiForWindow"));
pfnGetDpiForSystem = reinterpret_cast<GetDpiForSystemFn *>(GetProcAddress(hUser, "GetDpiForSystem"));
pfnGetSystemMetricsForDpi = reinterpret_cast<GetSystemMetricsForDpiFn *>(GetProcAddress(hUser, "GetSystemMetricsForDpi"));
pfnSystemParametersInfoForDpi = reinterpret_cast<SystemParametersInfoForDpiFn *>(GetProcAddress(hUser, "SystemParametersInfoForDpi"));
}

if (pfnGetDpiForSystem)
{
m_dpi = pfnGetDpiForSystem();
}
else
{
HDC hdc = GetDC(nullptr);
if (hdc)
{
// Initialize the DPI member variable
// This will correspond to the DPI setting
// With all Windows OS's to date the X and Y DPI will be identical
m_dpi = GetDeviceCaps(hdc, LOGPIXELSX);
ReleaseDC(nullptr, hdc);
}
}
m_dpi = ::GetDpiForSystem();
m_fInitialized = true;
}
}
Expand All @@ -154,22 +130,10 @@ class CDPIAware
int _ScaledSystemMetric(int nIndex)
{
_Init();
if (pfnGetSystemMetricsForDpi)
return pfnGetSystemMetricsForDpi(nIndex, m_dpi);
return MulDiv(::GetSystemMetrics(nIndex), 96, m_dpi);
return ::GetSystemMetricsForDpi(nIndex, m_dpi);
}

private:
using GetDpiForWindowFn = UINT STDAPICALLTYPE(HWND hWnd);
using GetDpiForSystemFn = UINT STDAPICALLTYPE();
using GetSystemMetricsForDpiFn = UINT STDAPICALLTYPE(int nIndex, UINT dpi);
using SystemParametersInfoForDpiFn = UINT STDAPICALLTYPE(UINT uiAction, UINT uiParam, PVOID pvParam, UINT fWinIni, UINT dpi);

GetDpiForWindowFn * pfnGetDpiForWindow;
GetDpiForSystemFn * pfnGetDpiForSystem;
GetSystemMetricsForDpiFn * pfnGetSystemMetricsForDpi;
SystemParametersInfoForDpiFn *pfnSystemParametersInfoForDpi;

// Member variable indicating whether the class has been initialized
bool m_fInitialized;

Expand Down
4 changes: 2 additions & 2 deletions grepWinNP3/sktoolslib_mod/DlgResizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ void CDlgResizer::Init(HWND hWndDlg)
GetWindowRect(hWndDlg, &m_dlgRectScreen);
OffsetRect(&m_dlgRectScreen, -m_dlgRectScreen.left, -m_dlgRectScreen.top);

m_sizeGrip.cx = GetSystemMetrics(SM_CXVSCROLL);
m_sizeGrip.cy = GetSystemMetrics(SM_CYHSCROLL);
m_sizeGrip.cx = GetSystemMetricsForDpi(SM_CXVSCROLL, GetDpiForWindow(hWndDlg));
m_sizeGrip.cy = GetSystemMetricsForDpi(SM_CYHSCROLL, GetDpiForWindow(hWndDlg));

RECT rect = {0, 0, m_sizeGrip.cx, m_sizeGrip.cy};

Expand Down
2 changes: 1 addition & 1 deletion grepWinNP3/sktoolslib_mod/DropFiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ STDMETHODIMP FileDataObject::GetData(FORMATETC* pformatetcIn, STGMEDIUM* pmedium
wchar_t* pszBuff = reinterpret_cast<wchar_t*>(reinterpret_cast<LPBYTE>(pDrop) + sizeof(DROPFILES));
for (auto it = m_allPaths.begin(); it != m_allPaths.end(); ++it)
{
lstrcpy(pszBuff, it->c_str());
wcscpy_s(pszBuff, it->size() + 1, it->c_str());
pszBuff += it->size();
*pszBuff = 0;
pszBuff++;
Expand Down
8 changes: 4 additions & 4 deletions grepWinNP3/sktoolslib_mod/IconBitmapUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ HBITMAP IconBitmapUtils::IconToBitmap(HINSTANCE hInst, UINT uIcon)

RECT rect;

rect.right = ::GetSystemMetrics(SM_CXMENUCHECK);
rect.bottom = ::GetSystemMetrics(SM_CYMENUCHECK);
rect.right = ::GetSystemMetricsForDpi(SM_CXMENUCHECK, GetDpiForSystem());
rect.bottom = ::GetSystemMetricsForDpi(SM_CYMENUCHECK, GetDpiForSystem());

rect.left = rect.top = 0;

Expand Down Expand Up @@ -137,8 +137,8 @@ HBITMAP IconBitmapUtils::IconToBitmapPARGB32(HICON hIcon)
return NULL;

SIZE sizIcon;
sizIcon.cx = GetSystemMetrics(SM_CXSMICON);
sizIcon.cy = GetSystemMetrics(SM_CYSMICON);
sizIcon.cx = GetSystemMetricsForDpi(SM_CXSMICON, GetDpiForSystem());
sizIcon.cy = GetSystemMetricsForDpi(SM_CYSMICON, GetDpiForSystem());

RECT rcIcon;
SetRect(&rcIcon, 0, 0, sizIcon.cx, sizIcon.cy);
Expand Down
2 changes: 1 addition & 1 deletion grepWinNP3/sktoolslib_mod/Language.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ BOOL CALLBACK CLanguage::TranslateWindowProc(HWND hwnd, LPARAM lParam)
{
// we're dealing with radio buttons and check boxes,
// which means we have to add a little space for the checkbox
const int checkWidth = GetSystemMetrics(SM_CXMENUCHECK) + 2 * GetSystemMetrics(SM_CXEDGE) + CDPIAware::Instance().Scale(hwnd, 3);
const int checkWidth = GetSystemMetricsForDpi(SM_CXMENUCHECK, GetDpiForWindow(hwnd)) + 2 * GetSystemMetricsForDpi(SM_CXEDGE, GetDpiForWindow(hwnd)) + CDPIAware::Instance().Scale(hwnd, 3);
controlRect.right += checkWidth;
// now we have the rectangle the control really needs
if ((controlRectOrig.right - controlRectOrig.left) > (controlRect.right - controlRect.left))
Expand Down
2 changes: 1 addition & 1 deletion grepWinNP3/sktoolslib_mod/RichStatusBar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ bool CRichStatusBar::Init(HWND hParent, bool drawGrip)
{
NONCLIENTMETRICS ncm;
ncm.cbSize = sizeof(NONCLIENTMETRICS);
SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICS), &ncm, 0U);
SystemParametersInfoForDpi(SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICS), &ncm, 0U, GetDpiForWindow(*this));
m_fonts[0] = CreateFontIndirect(&ncm.lfStatusFont);
ncm.lfStatusFont.lfItalic = TRUE;
m_fonts[1] = CreateFontIndirect(&ncm.lfStatusFont);
Expand Down
5 changes: 3 additions & 2 deletions grepWinNP3/sktoolslib_mod/hyperlink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,10 @@ BOOL CHyperLink::ConvertStaticToHyperlink(HWND hwndParent, UINT uiCtlId,
*/
BOOL CHyperLink::setURL(LPCWSTR strURL)
{
m_strURL = std::make_unique<wchar_t[]>(lstrlen(strURL) + 1);
size_t len = wcslen(strURL);
m_strURL = std::make_unique<wchar_t[]>(len + 1);

lstrcpy(m_strURL.get(), strURL);
wcscpy_s(m_strURL.get(), len + 1, strURL);

return TRUE;
}
Expand Down
9 changes: 7 additions & 2 deletions grepWinNP3/src/Bookmarks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "Bookmarks.h"
#include "maxpath.h"
#include <shlobj.h>
#include <KnownFolders.h>
#include <memory>

CBookmarks::CBookmarks()
Expand All @@ -44,8 +45,12 @@ void CBookmarks::InitPath()
}
else
{
SHGetFolderPath(nullptr, CSIDL_APPDATA, nullptr, SHGFP_TYPE_CURRENT, path.get());
m_iniPath = path.get();
PWSTR pszPath = nullptr;
if (SUCCEEDED(SHGetKnownFolderPath(FOLDERID_RoamingAppData, 0, nullptr, &pszPath)))
{
m_iniPath = pszPath;
CoTaskMemFree(pszPath);
}
m_iniPath += L"\\grepWinNP3";
}
CreateDirectory(m_iniPath.c_str(), nullptr);
Expand Down
12 changes: 6 additions & 6 deletions grepWinNP3/src/ShellContextMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,15 @@ BOOL CShellContextMenu::GetContextMenu(HWND hWnd, void** ppContextMenu, int& iMe
HKEY ahkeys[16];
SecureZeroMemory(ahkeys, _countof(ahkeys) * sizeof(HKEY));
int numkeys = 0;
if (RegOpenKey(HKEY_CLASSES_ROOT, L"*", &ahkeys[numkeys++]) != ERROR_SUCCESS)
if (RegOpenKeyEx(HKEY_CLASSES_ROOT, L"*", 0, KEY_READ, &ahkeys[numkeys++]) != ERROR_SUCCESS)
numkeys--;
if (RegOpenKey(HKEY_CLASSES_ROOT, L"AllFileSystemObjects", &ahkeys[numkeys++]) != ERROR_SUCCESS)
if (RegOpenKeyEx(HKEY_CLASSES_ROOT, L"AllFileSystemObjects", 0, KEY_READ, &ahkeys[numkeys++]) != ERROR_SUCCESS)
numkeys--;
if (PathIsDirectory(m_strVector[0].filePath.c_str()))
{
if (RegOpenKey(HKEY_CLASSES_ROOT, L"Folder", &ahkeys[numkeys++]) != ERROR_SUCCESS)
if (RegOpenKeyEx(HKEY_CLASSES_ROOT, L"Folder", 0, KEY_READ, &ahkeys[numkeys++]) != ERROR_SUCCESS)
numkeys--;
if (RegOpenKey(HKEY_CLASSES_ROOT, L"Directory", &ahkeys[numkeys++]) != ERROR_SUCCESS)
if (RegOpenKeyEx(HKEY_CLASSES_ROOT, L"Directory", 0, KEY_READ, &ahkeys[numkeys++]) != ERROR_SUCCESS)
numkeys--;
}
// find extension
Expand All @@ -100,13 +100,13 @@ BOOL CShellContextMenu::GetContextMenu(HWND hWnd, void** ppContextMenu, int& iMe
if (dotPos != std::string::npos)
{
ext = m_strVector[0].filePath.substr(dotPos);
if (RegOpenKey(HKEY_CLASSES_ROOT, ext.c_str(), &ahkeys[numkeys++]) == ERROR_SUCCESS)
if (RegOpenKeyEx(HKEY_CLASSES_ROOT, ext.c_str(), 0, KEY_READ, &ahkeys[numkeys++]) == ERROR_SUCCESS)
{
WCHAR buf[MAX_PATH] = {0};
DWORD dwSize = MAX_PATH;
if (RegQueryValueEx(ahkeys[numkeys - 1], L"", nullptr, nullptr, reinterpret_cast<LPBYTE>(buf), &dwSize) == ERROR_SUCCESS)
{
if (RegOpenKey(HKEY_CLASSES_ROOT, buf, &ahkeys[numkeys++]) != ERROR_SUCCESS)
if (RegOpenKeyEx(HKEY_CLASSES_ROOT, buf, 0, KEY_READ, &ahkeys[numkeys++]) != ERROR_SUCCESS)
numkeys--;
}
}
Expand Down
8 changes: 4 additions & 4 deletions grepWinNP3/src/Theme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ bool CTheme::RemoveRegisteredCallback(int id)

void CTheme::SetDlgFontFaceName(LPCWSTR FontFaceName, int size)
{
(void)lstrcpyn(m_DlgFontFace, FontFaceName, _countof(m_DlgFontFace));
(void)wcscpy_s(m_DlgFontFace, _countof(m_DlgFontFace), FontFaceName);
m_DlgFontSize = size;
}

Expand All @@ -150,7 +150,7 @@ void CTheme::SetFontForDialog(HWND hwnd, LPCWSTR FontFaceName, int FontSize)
GetObject(GetWindowFont(hwnd), sizeof(lf), &lf);
lf.lfWeight = FW_REGULAR;
lf.lfHeight = (LONG)FontSize;
(void)lstrcpyn(lf.lfFaceName, FontFaceName, _countof(lf.lfFaceName));
(void)wcscpy_s(lf.lfFaceName, _countof(lf.lfFaceName), FontFaceName);
HFONT const hf = CreateFontIndirect(&lf);
HDC const hdc = GetDC(hwnd);
SetBkMode(hdc, OPAQUE);
Expand Down Expand Up @@ -789,9 +789,9 @@ LRESULT CTheme::ButtonSubclassProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM l
GetThemeBackgroundContentRect(hTheme, hdcPaint, iPartId, iState, &rcPaint, &rc);

if (dwButtonStyle & BS_LEFTTEXT)
rc.right -= bmWidth + 2 * GetSystemMetrics(SM_CXEDGE);
rc.right -= bmWidth + 2 * GetSystemMetricsForDpi(SM_CXEDGE, GetDpiForWindow(hWnd));
else
rc.left += bmWidth + 2 * GetSystemMetrics(SM_CXEDGE);
rc.left += bmWidth + 2 * GetSystemMetricsForDpi(SM_CXEDGE, GetDpiForWindow(hWnd));

DTTOPTS dttOpts = {sizeof(DTTOPTS)};
dttOpts.dwFlags = DTT_COMPOSITED | DTT_GLOWSIZE;
Expand Down
24 changes: 17 additions & 7 deletions grepWinNP3/src/grepWin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
//
#include "stdafx.h"
#include "strsafe.h"
#include <pathcch.h>
#pragma comment(lib, "pathcch.lib")
#include "resource.h"
#include "SearchDlg.h"
#include "AboutDlg.h"
Expand Down Expand Up @@ -348,8 +350,9 @@ int APIENTRY wWinMain(HINSTANCE hInstance,
{
WCHAR absPath[MAX_PATH] = {L'\0'};
StringCchCopy(absPath, MAX_PATH, moduleDir.c_str());
PathAppend(absPath, g_iniPath.c_str());
g_iniPath = absPath;
if (SUCCEEDED(PathCchAppend(absPath, MAX_PATH, g_iniPath.c_str()))) {
g_iniPath = absPath;
}
}
g_iniFile.SetUnicode();
g_iniFile.SetMultiLine();
Expand Down Expand Up @@ -417,11 +420,18 @@ int APIENTRY wWinMain(HINSTANCE hInstance,
{
TCHAR wchAppPath[MAX_PATH] = {L'\0'};
GetModuleFileName(nullptr, wchAppPath, MAX_PATH);
PathRemoveFileSpec(wchAppPath);
PathAppend(wchAppPath, languagefile.c_str());
TCHAR wchLngPath[MAX_PATH] = {L'\0'};
PathCanonicalize(wchLngPath, wchAppPath);
CLanguage::Instance().LoadFile(wchLngPath);
if (SUCCEEDED(PathCchRemoveFileSpec(wchAppPath, MAX_PATH)) &&
SUCCEEDED(PathCchAppend(wchAppPath, MAX_PATH, languagefile.c_str())))
{
TCHAR wchLngPath[MAX_PATH] = {L'\0'};
if (SUCCEEDED(PathCchCanonicalize(wchLngPath, MAX_PATH, wchAppPath))) {
CLanguage::Instance().LoadFile(wchLngPath);
} else {
CLanguage::Instance().LoadFile(wchAppPath);
}
}
else
CLanguage::Instance().LoadFile(languagefile);
}
else
CLanguage::Instance().LoadFile(languagefile);
Expand Down
Loading
Loading