Skip to content

Commit 4a7715c

Browse files
committed
Make it work on Windows 7
1 parent af67976 commit 4a7715c

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

src/WinWebDiffLib/WebWindow.hpp

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,7 @@ class CWebWindow
281281
WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP,
282282
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
283283
m_hWebViewParent, nullptr, hInstance, nullptr);
284+
bool bWin10orGreater = IsWin10OrGreater();
284285
HDC hDC = GetDC(m_hWnd);
285286
LOGFONT lfToolbar{};
286287
lfToolbar.lfHeight = MulDiv(-14, GetDeviceCaps(hDC, LOGPIXELSX), 72);
@@ -289,7 +290,7 @@ class CWebWindow
289290
lfToolbar.lfOutPrecision = OUT_TT_ONLY_PRECIS;
290291
lfToolbar.lfQuality = PROOF_QUALITY;
291292
lfToolbar.lfPitchAndFamily = VARIABLE_PITCH | FF_DECORATIVE;
292-
wcscpy_s(lfToolbar.lfFaceName, L"Segoe MDL2 Assets");
293+
wcscpy_s(lfToolbar.lfFaceName, bWin10orGreater ? L"Segoe MDL2 Assets" : L"Segoe UI Symbol");
293294
NONCLIENTMETRICS info{ sizeof(info) };
294295
SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(info), &info, 0);
295296
LOGFONT lfEdit = info.lfCaptionFont;
@@ -298,10 +299,10 @@ class CWebWindow
298299
m_hEditFont = CreateFontIndirect(&lfEdit);
299300
SendMessage(m_hToolbar, TB_BUTTONSTRUCTSIZE, sizeof(TBBUTTON), 0);
300301
TBBUTTON tbb[] = {
301-
{I_IMAGENONE, ID_GOBACK, TBSTATE_ENABLED, BTNS_BUTTON | BTNS_AUTOSIZE, {}, 0, (INT_PTR)L"\uE0A6"},
302-
{I_IMAGENONE, ID_GOFORWARD, TBSTATE_ENABLED, BTNS_BUTTON | BTNS_AUTOSIZE, {}, 0, (INT_PTR)L"\uE0AB"},
303-
{I_IMAGENONE, ID_RELOAD, TBSTATE_ENABLED, BTNS_BUTTON | BTNS_AUTOSIZE, {}, 0, (INT_PTR)L"\uE149"},
304-
{I_IMAGENONE, ID_STOP, TBSTATE_ENABLED, BTNS_BUTTON | BTNS_AUTOSIZE, {}, 0, (INT_PTR)L"\uE106"},
302+
{I_IMAGENONE, ID_GOBACK, TBSTATE_ENABLED, BTNS_BUTTON | BTNS_AUTOSIZE, {}, 0, (INT_PTR)(bWin10orGreater ? L"\uE0A6" : L"\u25C0")},
303+
{I_IMAGENONE, ID_GOFORWARD, TBSTATE_ENABLED, BTNS_BUTTON | BTNS_AUTOSIZE, {}, 0, (INT_PTR)(bWin10orGreater ? L"\uE0AB" : L"\u25B6")},
304+
{I_IMAGENONE, ID_RELOAD, TBSTATE_ENABLED, BTNS_BUTTON | BTNS_AUTOSIZE, {}, 0, (INT_PTR)(bWin10orGreater ? L"\uE149" : L"\u21BB")},
305+
{I_IMAGENONE, ID_STOP, TBSTATE_ENABLED, BTNS_BUTTON | BTNS_AUTOSIZE, {}, 0, (INT_PTR)(bWin10orGreater ? L"\uE106" : L"\u2715")},
305306
};
306307
m_hEdit = CreateWindowEx(0, TEXT("EDIT"), TEXT(""),
307308
WS_CHILD | WS_VISIBLE | WS_BORDER | ES_AUTOHSCROLL,
@@ -572,7 +573,7 @@ class CWebWindow
572573

573574
WDocument document;
574575
document.Parse(result.returnObjectAsJson);
575-
UINT dpi = GetDpiForWindow(m_hWnd);
576+
UINT dpi = MyGetDpiForWindow(m_hWnd);
576577
int width = document[L"cssContentSize"][L"width"].GetInt()
577578
* dpi / 96;
578579
int height = document[L"cssContentSize"][L"height"].GetInt()
@@ -1912,6 +1913,18 @@ class CWebWindow
19121913
return lResult;
19131914
}
19141915

1916+
static UINT MyGetDpiForWindow(HWND hWnd)
1917+
{
1918+
if (GetDpiForWindowFunc)
1919+
return GetDpiForWindowFunc(hWnd);
1920+
return GetDeviceCaps(GetDC(nullptr), LOGPIXELSX);
1921+
}
1922+
1923+
bool IsWin10OrGreater()
1924+
{
1925+
return GetDpiForWindowFunc != nullptr;
1926+
}
1927+
19151928
const int ID_TOOLTIP_TIMER = 1;
19161929
const int TOOLTIP_TIMEOUT = 5000;
19171930
HWND m_hWnd = nullptr;
@@ -1937,5 +1950,10 @@ class CWebWindow
19371950
std::wstring m_toolTipText = L"test";
19381951
bool m_showToolTip = false;
19391952
std::wstring m_webmessage;
1953+
inline static const auto GetDpiForWindowFunc = []() {
1954+
HMODULE hUser32 = GetModuleHandle(L"user32.dll");
1955+
return reinterpret_cast<decltype(&::GetDpiForWindow)>(
1956+
::GetProcAddress(hUser32, "GetDpiForWindow"));
1957+
}();
19401958
};
19411959

src/WinWebDiffLib/WinWebDiffLib.vcxproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@
237237
<GenerateDebugInformation>true</GenerateDebugInformation>
238238
<EnableUAC>false</EnableUAC>
239239
<ModuleDefinitionFile>WinWebDiffLib.def</ModuleDefinitionFile>
240+
<DelayLoadDLLs>advapi32.dll</DelayLoadDLLs>
240241
</Link>
241242
</ItemDefinitionGroup>
242243
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">

0 commit comments

Comments
 (0)