190 lines
7.7 KiB
C
190 lines
7.7 KiB
C
#include <windows.h>
|
|
#include <windowsx.h>
|
|
#include <prsht.h>
|
|
|
|
#define MAX_FUNCTION_COUNT 8
|
|
|
|
struct ReportedVersion {
|
|
LPCSTR name;
|
|
DWORD major;
|
|
DWORD minor;
|
|
DWORD build;
|
|
DWORD platform;
|
|
};
|
|
typedef struct ReportedVersion ReportedVersion;
|
|
struct FunctionVersion {
|
|
LPCSTR name;
|
|
LPCSTR functions[MAX_FUNCTION_COUNT];
|
|
};
|
|
typedef struct FunctionVersion FunctionVersion;
|
|
|
|
ReportedVersion reportedVersions[] = {
|
|
{ "Win32s", 4, 0, 950, VER_PLATFORM_WIN32s },
|
|
{ "Windows NT 3.1", 3, 10, 511, VER_PLATFORM_WIN32_NT },
|
|
{ "Windows NT 3.50", 3, 50, 807, VER_PLATFORM_WIN32_NT },
|
|
{ "Windows NT 3.51", 3, 51, 1057, VER_PLATFORM_WIN32_NT },
|
|
{ "Windows 95", 4, 0, 950, VER_PLATFORM_WIN32_WINDOWS },
|
|
{ "Windows NT 4.0", 4, 0, 1381, VER_PLATFORM_WIN32_NT }
|
|
};
|
|
FunctionVersion functionVersions[] = {
|
|
{ "Windows NT 4.0", "kernel32.dllGetVersionEx", "kernel32.dllGetVersion"}
|
|
};
|
|
|
|
BOOL reportedChanged;
|
|
BOOL functionChanged ;
|
|
|
|
INT_PTR CALLBACK GlobalPageProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
|
|
switch (uMsg) {
|
|
case WM_INITDIALOG:
|
|
reportedChanged = FALSE;
|
|
functionChanged = FALSE;
|
|
|
|
HWND reportedBox = GetDlgItem(hWnd, 1);
|
|
for (int i = 0; i < ARRAYSIZE(reportedVersions); i++) {
|
|
ListBox_AddString(reportedBox, reportedVersions[i].name);
|
|
}
|
|
HWND functionBox = GetDlgItem(hWnd, 2);
|
|
for (int i = 0; i < ARRAYSIZE(functionVersions); i++) {
|
|
ListBox_AddString(functionBox, functionVersions[i].name);
|
|
}
|
|
|
|
HKEY key;
|
|
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, TEXT("SOFTWARE\\BCompat"), 0, KEY_READ, &key) == ERROR_SUCCESS) {
|
|
DWORD size;
|
|
DWORD major = 0;
|
|
RegQueryValueEx(key, TEXT("ReportedMajor"), NULL, NULL, (LPBYTE) &major, &size);
|
|
DWORD minor = 0;
|
|
RegQueryValueEx(key, TEXT("ReportedMinor"), NULL, NULL, (LPBYTE) &minor, &size);
|
|
DWORD build = 0;
|
|
RegQueryValueEx(key, TEXT("ReportedBuild"), NULL, NULL, (LPBYTE) &build, &size);
|
|
DWORD platform = 0;
|
|
RegQueryValueEx(key, TEXT("ReportedPlatform"), NULL, NULL, (LPBYTE) &platform, &size);
|
|
RegCloseKey(key);
|
|
for (int i = 0; i < ARRAYSIZE(reportedVersions); i++) {
|
|
ReportedVersion version = reportedVersions[i];
|
|
if (major == version.major && minor == version.minor && build == version.build && platform == version.platform) {
|
|
ListBox_SetCurSel(reportedBox, i);
|
|
}
|
|
}
|
|
}
|
|
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, TEXT("SOFTWARE\\BCompat\\Functions"), 0, KEY_READ, &key) == ERROR_SUCCESS) {
|
|
TCHAR functions[MAX_FUNCTION_COUNT][64];
|
|
DWORD nameLength = 64;
|
|
int count = 0;
|
|
while (RegEnumKeyEx(key, count, functions[count], &nameLength, NULL, NULL, NULL, NULL) == ERROR_SUCCESS) {
|
|
count++;
|
|
}
|
|
for (int i = 0; i < ARRAYSIZE(functionVersions); i++) {
|
|
FunctionVersion version = functionVersions[i];
|
|
int x;
|
|
for (x = 0; x < ARRAYSIZE(version.functions) && version.functions[x] != NULL; x++) {
|
|
BOOL found = FALSE;
|
|
for (int y = 0; y < count; ++y) {
|
|
if (strcmp(functions[y], version.functions[x]) == 0) {
|
|
found = TRUE;
|
|
break;
|
|
}
|
|
}
|
|
if (!found) {
|
|
goto outer;
|
|
}
|
|
}
|
|
if (x == count) {
|
|
ListBox_SetCurSel(functionBox, i);
|
|
}
|
|
outer:
|
|
}
|
|
RegCloseKey(key);
|
|
}
|
|
break;
|
|
case WM_COMMAND:
|
|
switch (LOWORD(wParam)) {
|
|
case 1:
|
|
switch (HIWORD(wParam)) {
|
|
case LBN_SELCHANGE:
|
|
PropSheet_Changed(GetParent(hWnd), hWnd);
|
|
reportedChanged = TRUE;
|
|
break;
|
|
}
|
|
break;
|
|
case 2:
|
|
switch (HIWORD(wParam)) {
|
|
case LBN_SELCHANGE:
|
|
PropSheet_Changed(GetParent(hWnd), hWnd);
|
|
functionChanged = TRUE;
|
|
break;
|
|
}
|
|
break;
|
|
}
|
|
break;
|
|
case WM_NOTIFY:
|
|
switch (((NMHDR *)lParam)->code) {
|
|
case PSN_APPLY:
|
|
if (reportedChanged) {
|
|
reportedChanged = FALSE;
|
|
ReportedVersion version = reportedVersions[ListBox_GetCurSel(GetDlgItem(hWnd, 1))];
|
|
HKEY key;
|
|
RegCreateKeyEx(HKEY_LOCAL_MACHINE, TEXT("SOFTWARE\\BCompat"), 0, NULL, 0, KEY_WRITE, NULL, &key, NULL);
|
|
RegSetValueEx(key, "ReportedMajor", 0, REG_DWORD, (LPBYTE) &version.major, sizeof(DWORD));
|
|
RegSetValueEx(key, "ReportedMinor", 0, REG_DWORD, (LPBYTE) &version.minor, sizeof(DWORD));
|
|
RegSetValueEx(key, "ReportedBuild", 0, REG_DWORD, (LPBYTE) &version.build, sizeof(DWORD));
|
|
RegSetValueEx(key, "ReportedPlatform", 0, REG_DWORD, (LPBYTE) &version.platform, sizeof(DWORD));
|
|
RegCloseKey(key);
|
|
}
|
|
if (functionChanged) {
|
|
functionChanged = FALSE;
|
|
FunctionVersion version = functionVersions[ListBox_GetCurSel(GetDlgItem(hWnd, 2))];
|
|
HKEY key;
|
|
RegDeleteKey(HKEY_LOCAL_MACHINE, TEXT("SOFTWARE\\BCompat\\Functions"));
|
|
RegCreateKeyEx(HKEY_LOCAL_MACHINE, TEXT("SOFTWARE\\BCompat\\Functions"), 0, NULL, 0, KEY_WRITE, NULL, &key, NULL);
|
|
for (int i = 0; i < ARRAYSIZE(version.functions) && version.functions[i] != NULL; i++) {
|
|
DWORD value = 0;
|
|
RegSetValueEx(key, version.functions[i], 0, REG_DWORD, (LPBYTE) &value, sizeof(DWORD));
|
|
}
|
|
RegCloseKey(key);
|
|
}
|
|
}
|
|
}
|
|
return FALSE;
|
|
}
|
|
|
|
int main() {
|
|
HMODULE instance = GetModuleHandle(NULL);
|
|
|
|
PROPSHEETPAGE psp[1];
|
|
|
|
PROPSHEETHEADER psh;
|
|
|
|
psp[0].dwSize = sizeof(PROPSHEETPAGE);
|
|
psp[0].dwFlags = PSP_USETITLE;
|
|
psp[0].hInstance = instance;
|
|
psp[0].pszTemplate = MAKEINTRESOURCE(1);
|
|
psp[0].pszIcon = NULL;
|
|
psp[0].pfnDlgProc = GlobalPageProc;
|
|
psp[0].pszTitle = "Global";
|
|
psp[0].lParam = 0;
|
|
psp[0].pfnCallback = NULL;
|
|
/*psp[1].dwSize = sizeof(PROPSHEETPAGE);
|
|
psp[1].dwFlags = PSP_USETITLE;
|
|
psp[1].hInstance = instance;
|
|
psp[1].pszTemplate = MAKEINTRESOURCE(2);
|
|
psp[1].pszIcon = NULL;
|
|
psp[1].pfnDlgProc = AboutPageProc;
|
|
psp[1].pszTitle = "About";
|
|
psp[1].lParam = 0;
|
|
psp[1].pfnCallback = NULL;*/
|
|
|
|
psh.dwSize = sizeof(PROPSHEETHEADER);
|
|
psh.dwFlags = PSH_PROPSHEETPAGE;
|
|
psh.hwndParent = NULL;
|
|
psh.hInstance = instance;
|
|
psh.pszIcon = NULL;
|
|
psh.pszCaption = "BCompat Settings";
|
|
psh.nPages = sizeof(psp) / sizeof(PROPSHEETPAGE);
|
|
psh.nStartPage = 0;
|
|
psh.ppsp = (LPCPROPSHEETPAGE) &psp;
|
|
psh.pfnCallback = NULL;
|
|
|
|
PropertySheet(&psh);
|
|
}
|