📄 slayer.c
字号:
/*
* ReactOS Compatibility Layer Shell Extension
* Copyright (C) 2004 - 2005 ReactOS Team
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/* $Id: slayer.c 23933 2006-09-06 20:00:41Z weiden $
*
* PROJECT: ReactOS Compatibility Layer Shell Extension
* FILE: lib/shellext/cplsample/cplsample.c
* PURPOSE: ReactOS Compatibility Layer Shell Extension
* PROGRAMMER: Thomas Weidenmueller <w3seek@reactos.com>
* UPDATE HISTORY:
* 09/25/2004 Created
*/
#include <precomp.h>
HINSTANCE hInstance = NULL;
static LONG dllrefs = 0;
static ifaceICompatibilityPageVbtl efvt =
{
/* IUnknown methods */
ICompatibilityPage_fnQueryInterface,
ICompatibilityPage_fnAddRef,
ICompatibilityPage_fnRelease,
};
static ifaceIShellPropSheetExtVbtl efvtIShellPropSheetExt =
{
/* IShellPropSheetExt */
ICompatibilityPage_fnAddPages,
ICompatibilityPage_fnReplacePage,
};
static ifaceIShellExtInitVbtl efvtIShellExtInit =
{
/* IShellExtInit */
ICompatibilityPage_fnInitialize,
};
static ifaceIClassFactoryVbtl efvtIClassFactory =
{
/* IClassFactory */
ICompatibilityPage_fnCreateInstance,
ICompatibilityPage_fnLockServer,
};
/******************************************************************************
ICompatibilityPage
******************************************************************************/
static VOID
ClearCItemList(LPCOMPATIBILITYPAGE info)
{
PCITEM item, next;
for (item = info->CItems;
item != NULL;
item = next)
{
next = item->next;
HeapFree(GetProcessHeap(),
0,
item);
}
info->CSelectedItem = NULL;
info->CItems = NULL;
info->nItems = 0;
}
static BOOL
ReadDWORDFlag(HKEY hk,
LPTSTR szValueName,
LPDWORD lpOutValue,
DWORD dwDefault)
{
DWORD dwType, dwSize = sizeof(DWORD);
LONG e = RegQueryValueEx(hk,
szValueName,
0,
&dwType,
(LPBYTE)lpOutValue,
&dwSize);
if (e != ERROR_SUCCESS || dwSize != sizeof(DWORD))
{
*lpOutValue = dwDefault;
return TRUE;
}
return FALSE;
}
static BOOL
LoadAndParseAppCompatibilityFlags(LPCOMPATIBILITYPAGE info,
LPTSTR szValueName)
{
LONG e;
HKEY hk;
DWORD dwType, dwSize;
TCHAR szStr[256];
e = RegOpenKey(HKEY_CURRENT_USER,
TEXT("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\AppCompatFlags\\Layers"),
&hk);
if (e == ERROR_SUCCESS)
{
dwSize = sizeof(szStr);
e = RegQueryValueEx(hk,
szValueName,
0,
&dwType,
(LPBYTE)szStr,
&dwSize);
if (e == ERROR_SUCCESS)
{
/* FIXME - make sure the string is NULL-terminated! */
TCHAR *c;
for (c = szStr;
*c != TEXT('\0');
c++)
{
/* only the first word represents the compatibility mode */
/* FIXME - parse all words! */
if (*c == TEXT(' '))
{
*c = TEXT('\0');
break;
}
}
info->CSelectedItem = NULL;
if (_tcslen(szStr) > 0)
{
PCITEM item;
for (item = info->CItems;
item != NULL;
item = item->next)
{
if (!_tcsicmp(szStr, item->szKeyName))
{
info->CSelectedItem = item;
break;
}
}
}
}
RegCloseKey(hk);
}
return FALSE;
}
static BOOL
LoadCompatibilityModes(LPCOMPATIBILITYPAGE info)
{
BOOL Ret;
LONG e;
HKEY hk, hk2;
TCHAR szKey[256];
ClearCItemList(info);
e = RegOpenKey(HKEY_CURRENT_USER,
TEXT("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\AppCompatFlags\\Layers"),
&hk);
if (e == ERROR_SUCCESS)
{
DWORD i;
PCITEM lastitem = NULL;
for(i = 0;
(RegEnumKey(hk, i,szKey, sizeof(szKey) / sizeof(szKey[0])) == ERROR_SUCCESS);
i++)
{
e = RegOpenKey(hk,
szKey,
&hk2);
if (e == ERROR_SUCCESS)
{
DWORD dwType;
e = RegQueryValueEx(hk2,
NULL,
0,
&dwType,
NULL,
NULL);
if (e != ERROR_SUCCESS || (e == ERROR_SUCCESS && dwType == REG_SZ))
{
PCITEM item;
item = HeapAlloc(GetProcessHeap(),
0,
sizeof(CITEM));
if (item != NULL)
{
DWORD cdb = sizeof(item->szName);
/* description */
e = RegQueryValueEx(hk2,
NULL,
0,
NULL,
(LPBYTE)item->szName,
&cdb);
/* make sure it is null-terminated */
if (cdb > sizeof(item->szName) - sizeof(item->szName[0]))
{
item->szName[(sizeof(item->szName) / sizeof(item->szName[0])) - 1] = TEXT('\0');
}
if (e != ERROR_SUCCESS ||
cdb < sizeof(item->szName[0]))
{
_tcscpy(item->szName, szKey);
e = ERROR_SUCCESS;
}
_tcscpy(item->szKeyName, szKey);
info->nItems++;
ReadDWORDFlag(hk2,
TEXT("MajorVersion"),
&item->MajorVersion,
0);
ReadDWORDFlag(hk2,
TEXT("MinorVersion"),
&item->MinorVersion,
0);
ReadDWORDFlag(hk2,
TEXT("BuildNumber"),
&item->BuildNumber,
0);
ReadDWORDFlag(hk2,
TEXT("PlatformId"),
&item->PlatformId,
0);
ReadDWORDFlag(hk2,
TEXT("SPMajorVersion"),
&item->SPMajorVersion,
0);
ReadDWORDFlag(hk2,
TEXT("SPMinorVersion"),
&item->SPMinorVersion,
0);
if (e == ERROR_SUCCESS)
{
item->next = NULL;
if (lastitem != NULL)
{
lastitem->next = item;
}
else
{
info->CItems = item;
}
lastitem = item;
}
else
{
HeapFree(GetProcessHeap(),
0,
item);
}
}
}
RegCloseKey(hk2);
}
if (e != ERROR_SUCCESS)
{
e = ERROR_SUCCESS;
}
}
RegCloseKey(hk);
}
Ret = ((e == ERROR_SUCCESS || e == ERROR_NO_MORE_ITEMS) ? TRUE : FALSE);
return Ret;
}
static VOID
FillComboBoxWithCompatibilityModes(LPCOMPATIBILITYPAGE info,
HWND hwndDlg,
HWND hCombo,
BOOL bSelectItem,
BOOL bDisableControlsIfEmpty)
{
PCITEM item;
int i = 0;
BOOL sel = FALSE;
SendMessage(hCombo,
CB_RESETCONTENT,
0,
0);
for (item = info->CItems;
item != NULL;
item = item->next)
{
int iIndex = (int)SendMessage(hCombo,
CB_ADDSTRING,
0,
(LPARAM)item->szName);
if (item == info->CSelectedItem && bSelectItem)
{
SendMessage(hCombo,
CB_SETCURSEL,
(WPARAM)iIndex,
0);
sel = TRUE;
}
i++;
}
if (!sel && bSelectItem && i > 0)
{
/* select the first item */
SendMessage(hCombo,
CB_SETCURSEL,
0,
0);
}
if (bDisableControlsIfEmpty)
{
BOOL enable = (i > 0);
EnableWindow(GetDlgItem(hwndDlg,
IDC_COMPATGROUP),
enable);
EnableWindow(hCombo,
(enable && sel));
EnableWindow(GetDlgItem(hwndDlg,
IDC_CHKRUNCOMPATIBILITY),
enable);
CheckDlgButton(hwndDlg,
IDC_CHKRUNCOMPATIBILITY,
((enable && sel) ? BST_CHECKED : BST_UNCHECKED));
}
}
static VOID
FillEditListBoxWithCompatibilityModes(LPCOMPATIBILITYPAGE info,
HWND hwndDlg,
HWND hListBox,
BOOL bDisableControlsIfEmpty)
{
PCITEM item;
int i;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -