Skip to content

Commit

Permalink
add VersionHelper.h
Browse files Browse the repository at this point in the history
  • Loading branch information
katahiromz committed Jun 5, 2023
1 parent e9668fb commit 241cb92
Show file tree
Hide file tree
Showing 7 changed files with 612 additions and 45 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@
[submodule "LineNumEdit"]
path = LineNumEdit
url = https://github.com/katahiromz/LineNumEdit
[submodule "WonSetThreadUILanguage"]
path = WonSetThreadUILanguage
url = https://github.com/katahiromz/WonSetThreadUILanguage.git
1 change: 1 addition & 0 deletions WonSetThreadUILanguage
Submodule WonSetThreadUILanguage added at 45a577
3 changes: 3 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ cmake_policy(SET CMP0003 NEW)
# EGA
subdirs(../EGA)

# include directories
include_directories(.)

# libRisohEditor.a
add_library(libRisohEditor STATIC
AccelRes.cpp
Expand Down
46 changes: 1 addition & 45 deletions src/RisohEditor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,51 +53,7 @@

INT LogMessageBoxW(HWND hwnd, LPCWSTR text, LPCWSTR title, UINT uType);

inline BOOL IsWindowsVistaOrLater(VOID)
{
OSVERSIONINFOW osver = { sizeof(osver) };
return (GetVersionExW(&osver) && osver.dwMajorVersion >= 6);
}

static inline LANGID RE_GetThreadUILanguage()
{
typedef LANGID (WINAPI *FN_GetThreadUILanguage)(VOID);
static FN_GetThreadUILanguage s_fn = NULL;

if (IsWindowsVistaOrLater())
{
if (!s_fn)
s_fn =
reinterpret_cast<FN_GetThreadUILanguage>(GetProcAddress(GetModuleHandleA("kernel32"), "GetThreadUILanguage"));
if (s_fn)
return (*s_fn)();
}

return LANGIDFROMLCID(GetThreadLocale());
}
#undef GetThreadUILanguage
#define GetThreadUILanguage RE_GetThreadUILanguage

static inline LANGID RE_SetThreadUILanguage(LANGID LangID)
{
typedef LANGID (WINAPI *FN_SetThreadUILanguage)(LANGID);
static FN_SetThreadUILanguage s_fn = NULL;

if (IsWindowsVistaOrLater())
{
if (!s_fn)
s_fn =
reinterpret_cast<FN_SetThreadUILanguage>(GetProcAddress(GetModuleHandleA("kernel32"), "SetThreadUILanguage"));
if (s_fn)
return (*s_fn)(LangID);
}

if (SetThreadLocale(MAKELCID(LangID, SORT_DEFAULT)))
return LangID;
return 0;
}
#undef SetThreadUILanguage
#define SetThreadUILanguage RE_SetThreadUILanguage
#include "../WonSetThreadUILanguage/WonSetThreadUILanguage.h"

#include "resource.h"
#include "MWindowBase.hpp"
Expand Down
138 changes: 138 additions & 0 deletions src/VersionHelpers.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
/******************************************************************
* *
* VersionHelpers.h -- This module defines helper functions to *
* promote version check with proper *
* comparisons. *
* *
* Copyright (c) Microsoft Corp. All rights reserved. *
* *
******************************************************************/
#ifndef _versionhelpers_H_INCLUDED_
#define _versionhelpers_H_INCLUDED_

#include <winapifamily.h>

#ifdef _MSC_VER
#pragma once
#endif // _MSC_VER

#pragma region Application Family
#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)

#include <specstrings.h> // for _In_, etc.

#if !defined(__midl) && !defined(SORTPP_PASS)

#if (NTDDI_VERSION >= NTDDI_WINXP)

#ifdef __cplusplus

#define VERSIONHELPERAPI inline bool

#else // __cplusplus

#define VERSIONHELPERAPI FORCEINLINE BOOL

#endif // __cplusplus

VERSIONHELPERAPI
IsWindowsVersionOrGreater(WORD wMajorVersion, WORD wMinorVersion, WORD wServicePackMajor)
{
OSVERSIONINFOEXW osvi = { sizeof(osvi), 0, 0, 0, 0, {0}, 0, 0 };
DWORDLONG const dwlConditionMask = VerSetConditionMask(
VerSetConditionMask(
VerSetConditionMask(
0, VER_MAJORVERSION, VER_GREATER_EQUAL),
VER_MINORVERSION, VER_GREATER_EQUAL),
VER_SERVICEPACKMAJOR, VER_GREATER_EQUAL);

osvi.dwMajorVersion = wMajorVersion;
osvi.dwMinorVersion = wMinorVersion;
osvi.wServicePackMajor = wServicePackMajor;

return VerifyVersionInfoW(&osvi, VER_MAJORVERSION | VER_MINORVERSION | VER_SERVICEPACKMAJOR, dwlConditionMask) != FALSE;
}

VERSIONHELPERAPI
IsWindowsXPOrGreater()
{
return IsWindowsVersionOrGreater(HIBYTE(_WIN32_WINNT_WINXP), LOBYTE(_WIN32_WINNT_WINXP), 0);
}

VERSIONHELPERAPI
IsWindowsXPSP1OrGreater()
{
return IsWindowsVersionOrGreater(HIBYTE(_WIN32_WINNT_WINXP), LOBYTE(_WIN32_WINNT_WINXP), 1);
}

VERSIONHELPERAPI
IsWindowsXPSP2OrGreater()
{
return IsWindowsVersionOrGreater(HIBYTE(_WIN32_WINNT_WINXP), LOBYTE(_WIN32_WINNT_WINXP), 2);
}

VERSIONHELPERAPI
IsWindowsXPSP3OrGreater()
{
return IsWindowsVersionOrGreater(HIBYTE(_WIN32_WINNT_WINXP), LOBYTE(_WIN32_WINNT_WINXP), 3);
}

VERSIONHELPERAPI
IsWindowsVistaOrGreater()
{
return IsWindowsVersionOrGreater(HIBYTE(_WIN32_WINNT_VISTA), LOBYTE(_WIN32_WINNT_VISTA), 0);
}

VERSIONHELPERAPI
IsWindowsVistaSP1OrGreater()
{
return IsWindowsVersionOrGreater(HIBYTE(_WIN32_WINNT_VISTA), LOBYTE(_WIN32_WINNT_VISTA), 1);
}

VERSIONHELPERAPI
IsWindowsVistaSP2OrGreater()
{
return IsWindowsVersionOrGreater(HIBYTE(_WIN32_WINNT_VISTA), LOBYTE(_WIN32_WINNT_VISTA), 2);
}

VERSIONHELPERAPI
IsWindows7OrGreater()
{
return IsWindowsVersionOrGreater(HIBYTE(_WIN32_WINNT_WIN7), LOBYTE(_WIN32_WINNT_WIN7), 0);
}

VERSIONHELPERAPI
IsWindows7SP1OrGreater()
{
return IsWindowsVersionOrGreater(HIBYTE(_WIN32_WINNT_WIN7), LOBYTE(_WIN32_WINNT_WIN7), 1);
}

VERSIONHELPERAPI
IsWindows8OrGreater()
{
return IsWindowsVersionOrGreater(HIBYTE(_WIN32_WINNT_WIN8), LOBYTE(_WIN32_WINNT_WIN8), 0);
}

VERSIONHELPERAPI
IsWindows8Point1OrGreater()
{
return IsWindowsVersionOrGreater(HIBYTE(_WIN32_WINNT_WINBLUE), LOBYTE(_WIN32_WINNT_WINBLUE), 0);
}

VERSIONHELPERAPI
IsWindowsServer()
{
OSVERSIONINFOEXW osvi = { sizeof(osvi), 0, 0, 0, 0, {0}, 0, 0, 0, VER_NT_WORKSTATION };
DWORDLONG const dwlConditionMask = VerSetConditionMask( 0, VER_PRODUCT_TYPE, VER_EQUAL );

return !VerifyVersionInfoW(&osvi, VER_PRODUCT_TYPE, dwlConditionMask);
}

#endif // NTDDI_VERSION

#endif // defined(__midl)

#endif /* WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) */
#pragma endregion

#endif // _VERSIONHELPERS_H_INCLUDED_
Loading

0 comments on commit 241cb92

Please sign in to comment.