mirror of
https://github.com/UzixLS/KernelEx.git
synced 2025-07-19 07:21:20 +03:00
import KernelEx-4.5-Beta1
This commit is contained in:
199
sheet/sheet.cpp
Normal file → Executable file
199
sheet/sheet.cpp
Normal file → Executable file
@ -27,16 +27,72 @@
|
||||
#include "resource.h"
|
||||
#include "KexLinkage.h"
|
||||
|
||||
struct CTips
|
||||
{
|
||||
char* _TIP_DISABLE;
|
||||
char* _TIP_COMPAT;
|
||||
char* _TIP_SYSTEM;
|
||||
char* _TIP_NOINHERIT;
|
||||
char* _TIP_OVERRIDE;
|
||||
char* _TIP_LOG;
|
||||
|
||||
CTips()
|
||||
{
|
||||
_TIP_DISABLE = _TIP_COMPAT = _TIP_SYSTEM = _TIP_NOINHERIT
|
||||
= _TIP_OVERRIDE = _TIP_LOG = NULL;
|
||||
loaded = false;
|
||||
}
|
||||
|
||||
~CTips()
|
||||
{
|
||||
if (loaded)
|
||||
{
|
||||
free(_TIP_DISABLE);
|
||||
free(_TIP_COMPAT);
|
||||
free(_TIP_SYSTEM);
|
||||
free(_TIP_NOINHERIT);
|
||||
free(_TIP_OVERRIDE);
|
||||
free(_TIP_LOG);
|
||||
}
|
||||
}
|
||||
|
||||
void load_tips()
|
||||
{
|
||||
if (loaded)
|
||||
return;
|
||||
loaded = true;
|
||||
_TIP_DISABLE = load_string(TIP_DISABLE);
|
||||
_TIP_COMPAT = load_string(TIP_COMPAT);
|
||||
_TIP_SYSTEM = load_string(TIP_SYSTEM);
|
||||
_TIP_NOINHERIT = load_string(TIP_NOINHERIT);
|
||||
_TIP_OVERRIDE = load_string(TIP_OVERRIDE);
|
||||
_TIP_LOG = load_string(TIP_LOG);
|
||||
}
|
||||
|
||||
private:
|
||||
bool loaded;
|
||||
|
||||
char* load_string(int sID)
|
||||
{
|
||||
char buf[512];
|
||||
LoadString(g_hModule, sID, buf, sizeof(buf));
|
||||
buf[sizeof(buf) - 1] = '\0';
|
||||
return strdup(buf);
|
||||
}
|
||||
} tips;
|
||||
|
||||
|
||||
|
||||
KexShlExt::KexShlExt()
|
||||
{
|
||||
g_LockCount++;
|
||||
m_RefCount = 0;
|
||||
m_cRef = 1;
|
||||
InterlockedIncrement(&g_LockCount);
|
||||
}
|
||||
|
||||
|
||||
KexShlExt::~KexShlExt()
|
||||
{
|
||||
g_LockCount--;
|
||||
InterlockedDecrement(&g_LockCount);
|
||||
}
|
||||
|
||||
|
||||
@ -61,18 +117,18 @@ STDMETHODIMP KexShlExt::QueryInterface(REFIID riid,LPVOID *ppv)
|
||||
|
||||
STDMETHODIMP_(ULONG) KexShlExt::AddRef()
|
||||
{
|
||||
return ++m_RefCount;
|
||||
return InterlockedIncrement(&m_cRef);
|
||||
}
|
||||
|
||||
|
||||
STDMETHODIMP_(ULONG) KexShlExt::Release()
|
||||
{
|
||||
if (!--m_RefCount)
|
||||
if (InterlockedDecrement(&m_cRef) == 0)
|
||||
{
|
||||
delete this;
|
||||
return 0;
|
||||
}
|
||||
return m_RefCount;
|
||||
return m_cRef;
|
||||
}
|
||||
|
||||
|
||||
@ -114,16 +170,16 @@ __end:
|
||||
|
||||
bool KexShlExt::ResolveShortcut(const char* shortcutPath, char* filePath)
|
||||
{
|
||||
HRESULT result;
|
||||
IShellLink* shellLink;
|
||||
HRESULT result;
|
||||
IShellLink* shellLink;
|
||||
IPersistFile* persistFile;
|
||||
char path[MAX_PATH];
|
||||
WCHAR tmp[MAX_PATH];
|
||||
char path[MAX_PATH];
|
||||
WCHAR tmp[MAX_PATH];
|
||||
|
||||
CoInitialize(NULL);
|
||||
|
||||
result = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
|
||||
IID_IShellLink, (void**) &shellLink);
|
||||
result = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
|
||||
IID_IShellLink, (void**) &shellLink);
|
||||
|
||||
if (FAILED(result))
|
||||
{
|
||||
@ -142,8 +198,7 @@ bool KexShlExt::ResolveShortcut(const char* shortcutPath, char* filePath)
|
||||
result = shellLink->Resolve(NULL, SLR_UPDATE);
|
||||
if (SUCCEEDED(result))
|
||||
{
|
||||
result = shellLink->GetPath(path,
|
||||
MAX_PATH, NULL, SLGP_RAWPATH);
|
||||
result = shellLink->GetPath(path, MAX_PATH, NULL, SLGP_RAWPATH);
|
||||
if (SUCCEEDED(result))
|
||||
lstrcpyn(filePath, path, MAX_PATH);
|
||||
}
|
||||
@ -156,7 +211,7 @@ bool KexShlExt::ResolveShortcut(const char* shortcutPath, char* filePath)
|
||||
|
||||
CoUninitialize();
|
||||
|
||||
return SUCCEEDED(result);
|
||||
return SUCCEEDED(result);
|
||||
}
|
||||
|
||||
STDMETHODIMP KexShlExt::Initialize(LPCITEMIDLIST pidlFolder,
|
||||
@ -172,13 +227,13 @@ STDMETHODIMP KexShlExt::Initialize(LPCITEMIDLIST pidlFolder,
|
||||
|
||||
InitCommonControls();
|
||||
|
||||
if (FAILED(pDataObj->GetData(&etc, &stg)))
|
||||
return E_INVALIDARG;
|
||||
if (FAILED(pDataObj->GetData(&etc, &stg)))
|
||||
return E_INVALIDARG;
|
||||
|
||||
// Get an HDROP handle.
|
||||
hdrop = (HDROP) GlobalLock (stg.hGlobal);
|
||||
// Get an HDROP handle.
|
||||
hdrop = (HDROP) GlobalLock(stg.hGlobal);
|
||||
|
||||
if (!hdrop)
|
||||
if (!hdrop)
|
||||
{
|
||||
ReleaseStgMedium(&stg);
|
||||
return E_INVALIDARG;
|
||||
@ -186,10 +241,14 @@ STDMETHODIMP KexShlExt::Initialize(LPCITEMIDLIST pidlFolder,
|
||||
|
||||
ms = new ModuleSetting;
|
||||
if (!ms)
|
||||
{
|
||||
GlobalUnlock(stg.hGlobal);
|
||||
ReleaseStgMedium(&stg);
|
||||
return E_OUTOFMEMORY;
|
||||
}
|
||||
|
||||
// Determine how many files are involved in this operation.
|
||||
UINT numFiles = DragQueryFile (hdrop, 0xFFFFFFFF, NULL, 0);
|
||||
UINT numFiles = DragQueryFile(hdrop, 0xFFFFFFFF, NULL, 0);
|
||||
|
||||
if (numFiles != 1)
|
||||
result = E_FAIL;
|
||||
@ -235,7 +294,7 @@ STDMETHODIMP KexShlExt::AddPages(LPFNADDPROPSHEETPAGE lpfnAddPageProc, LPARAM lP
|
||||
psp.pfnDlgProc = DlgProc;
|
||||
psp.pfnCallback = CallbackProc;
|
||||
psp.lParam = (LPARAM) ms;
|
||||
psp.pcRefParent = &g_LockCount;
|
||||
psp.pcRefParent = (UINT*) &g_LockCount;
|
||||
|
||||
hPage = CreatePropertySheetPage(&psp);
|
||||
if (hPage)
|
||||
@ -272,13 +331,20 @@ BOOL CALLBACK KexShlExt::DlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lPa
|
||||
|
||||
RECT r;
|
||||
POINT p;
|
||||
|
||||
GetWindowRect(GetDlgItem(hwnd, IDC_GADVAN), &r);
|
||||
p.x = r.left;
|
||||
p.y = r.top;
|
||||
ScreenToClient(hwnd, &p);
|
||||
MoveWindow(GetDlgItem(hwnd, IDC_GADVAN), p.x, p.y, w - 2 * p.x, r.bottom - r.top, TRUE);
|
||||
|
||||
GetWindowRect(GetDlgItem(hwnd, IDC_GCOMPAT), &r);
|
||||
p.x = r.left;
|
||||
p.y = r.top;
|
||||
ScreenToClient(hwnd, &p);
|
||||
MoveWindow(GetDlgItem(hwnd, IDC_GCOMPAT), p.x, p.y, w - 2 * p.x, r.bottom - r.top, TRUE);
|
||||
|
||||
//reposition horizontal spacer and version text
|
||||
MoveWindow(GetDlgItem(hwnd, IDC_GCOMPAT), p.x, p.y, w - 2 * p.x, r.bottom - r.top, TRUE);
|
||||
MoveWindow(GetDlgItem(hwnd, IDC_HORIZ1), p.x, h - 14 - p.x, w - 2 * p.x, 1, TRUE);
|
||||
MoveWindow(GetDlgItem(hwnd, IDC_KEXVER), p.x, h - 12 - p.x, w - 2 * p.x, 12, TRUE);
|
||||
GetWindowRect(GetDlgItem(hwnd, IDC_TCOMPAT), &r);
|
||||
@ -304,6 +370,7 @@ BOOL CALLBACK KexShlExt::DlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lPa
|
||||
EnableWindow(GetDlgItem(hwnd, IDC_COMPAT), FALSE);
|
||||
EnableWindow(GetDlgItem(hwnd, IDC_SYSTEM), FALSE);
|
||||
EnableWindow(GetDlgItem(hwnd, IDC_LOG), FALSE);
|
||||
EnableWindow(GetDlgItem(hwnd, IDC_NOINHERIT), FALSE);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -311,6 +378,7 @@ BOOL CALLBACK KexShlExt::DlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lPa
|
||||
EnableWindow(GetDlgItem(hwnd, IDC_SYSTEM),
|
||||
IsDlgButtonChecked(hwnd, IDC_COMPAT));
|
||||
EnableWindow(GetDlgItem(hwnd, IDC_LOG), TRUE);
|
||||
EnableWindow(GetDlgItem(hwnd, IDC_NOINHERIT), TRUE);
|
||||
}
|
||||
PropSheet_Changed(GetParent(hwnd), hwnd);
|
||||
break;
|
||||
@ -321,6 +389,7 @@ BOOL CALLBACK KexShlExt::DlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lPa
|
||||
break;
|
||||
case IDC_SYSTEM:
|
||||
case IDC_LOG:
|
||||
case IDC_NOINHERIT:
|
||||
PropSheet_Changed(GetParent(hwnd), hwnd);
|
||||
break;
|
||||
}
|
||||
@ -359,19 +428,22 @@ void KexShlExt::OnInitDialog(HWND hwnd, ModuleSetting* ms)
|
||||
SendMessage(GetDlgItem(hwnd, IDC_SYSTEM), CB_SETCURSEL, i, 0);
|
||||
break;
|
||||
}
|
||||
if (!(ms->flags & 128) && (KexLinkage::instance.disable_extensions || !default_index_valid))
|
||||
ms->flags |= 1;
|
||||
if (ms->flags & 1)
|
||||
if (!(ms->flags & KRF_VALID_FLAG) && (KexLinkage::instance.disable_extensions || !default_index_valid))
|
||||
ms->flags |= KRF_KEX_DISABLE;
|
||||
if (ms->flags & KRF_KEX_DISABLE)
|
||||
{
|
||||
CheckDlgButton(hwnd, IDC_DISABLE, BST_CHECKED);
|
||||
EnableWindow(GetDlgItem(hwnd, IDC_COMPAT), FALSE);
|
||||
EnableWindow(GetDlgItem(hwnd, IDC_SYSTEM), FALSE);
|
||||
EnableWindow(GetDlgItem(hwnd, IDC_LOG), FALSE);
|
||||
EnableWindow(GetDlgItem(hwnd, IDC_NOINHERIT), FALSE);
|
||||
}
|
||||
if (ms->flags & 4)
|
||||
{
|
||||
if (ms->flags & KRF_LOG_APIS)
|
||||
CheckDlgButton(hwnd, IDC_LOG, BST_CHECKED);
|
||||
}
|
||||
if (ms->flags & KRF_NO_INHERIT)
|
||||
CheckDlgButton(hwnd, IDC_NOINHERIT, BST_CHECKED);
|
||||
if (ms->flags & KRF_OVERRIDE_PROC_MOD)
|
||||
CheckDlgButton(hwnd, IDC_OVERRIDE, BST_CHECKED);
|
||||
|
||||
//set KernelEx version
|
||||
unsigned long ver = KexLinkage::instance.m_kexGetKEXVersion();
|
||||
@ -381,22 +453,45 @@ void KexShlExt::OnInitDialog(HWND hwnd, ModuleSetting* ms)
|
||||
ver>>24, (ver>>16) & 0xff, ver & 0xffff, debug ? "DEBUG" : "");
|
||||
SendMessage(GetDlgItem(hwnd, IDC_KEXVER), WM_SETTEXT, 0, (LPARAM) ver_s);
|
||||
|
||||
ShowWindow(GetDlgItem(hwnd, IDC_OVERRIDE), debug ? SW_SHOW : SW_HIDE);
|
||||
ShowWindow(GetDlgItem(hwnd, IDC_LOG), debug ? SW_SHOW : SW_HIDE);
|
||||
if (!debug)
|
||||
{
|
||||
RECT r;
|
||||
HWND h = GetDlgItem(hwnd, IDC_GADVAN);
|
||||
GetWindowRect(h, &r);
|
||||
r.bottom -= 40; //height between IDC_LOG and element above
|
||||
SetWindowPos(h, NULL, 0, 0, r.right - r.left, r.bottom - r.top, SWP_NOMOVE);
|
||||
}
|
||||
|
||||
tips.load_tips();
|
||||
|
||||
HWND hwndTip = CreateTooltipWindow(hwnd);
|
||||
CreateTooltip(hwndTip, hwnd, IDC_DISABLE, tips._TIP_DISABLE);
|
||||
CreateTooltip(hwndTip, hwnd, IDC_COMPAT, tips._TIP_COMPAT);
|
||||
CreateTooltip(hwndTip, hwnd, IDC_SYSTEM, tips._TIP_SYSTEM);
|
||||
CreateTooltip(hwndTip, hwnd, IDC_NOINHERIT, tips._TIP_NOINHERIT);
|
||||
CreateTooltip(hwndTip, hwnd, IDC_OVERRIDE, tips._TIP_OVERRIDE);
|
||||
CreateTooltip(hwndTip, hwnd, IDC_LOG, tips._TIP_LOG);
|
||||
}
|
||||
|
||||
|
||||
void KexShlExt::OnApply(HWND hwnd)
|
||||
{
|
||||
ModuleSetting* ms = (ModuleSetting*) GetWindowLong(hwnd, GWL_USERDATA);
|
||||
BYTE flags = 0;
|
||||
DWORD flags = 0;
|
||||
const char* conf = "";
|
||||
if (IsDlgButtonChecked(hwnd, IDC_DISABLE))
|
||||
flags |= 1;
|
||||
flags |= KRF_KEX_DISABLE;
|
||||
if (IsDlgButtonChecked(hwnd, IDC_COMPAT))
|
||||
conf = KexLinkage::instance.confs[SendMessage(
|
||||
GetDlgItem(hwnd, IDC_SYSTEM), CB_GETCURSEL, 0, 0)].name;
|
||||
if (IsDlgButtonChecked(hwnd, IDC_LOG))
|
||||
flags |= 4;
|
||||
flags |= KRF_LOG_APIS;
|
||||
if (IsDlgButtonChecked(hwnd, IDC_NOINHERIT))
|
||||
flags |= KRF_NO_INHERIT;
|
||||
if (IsDlgButtonChecked(hwnd, IDC_OVERRIDE))
|
||||
flags |= KRF_OVERRIDE_PROC_MOD;
|
||||
|
||||
if (flags != ms->flags || strcmp(conf, ms->conf) != 0)
|
||||
KexLinkage::instance.m_kexSetModuleSettings(ms->file, conf, flags);
|
||||
@ -405,8 +500,44 @@ void KexShlExt::OnApply(HWND hwnd)
|
||||
|
||||
UINT CALLBACK KexShlExt::CallbackProc(HWND hwnd, UINT uMsg, LPPROPSHEETPAGE ppsp)
|
||||
{
|
||||
if (uMsg == PSPCB_RELEASE)
|
||||
if (uMsg == PSPCB_RELEASE)
|
||||
delete (ModuleSetting*) ppsp->lParam;
|
||||
|
||||
return 1; // used for PSPCB_CREATE - let the page be created
|
||||
return 1; // used for PSPCB_CREATE - let the page be created
|
||||
}
|
||||
|
||||
HWND KexShlExt::CreateTooltipWindow(HWND parent)
|
||||
{
|
||||
HWND hwndTip;
|
||||
hwndTip = CreateWindow(TOOLTIPS_CLASS, NULL,
|
||||
WS_POPUP | TTS_ALWAYSTIP | TTS_BALLOON,
|
||||
CW_USEDEFAULT, CW_USEDEFAULT,
|
||||
CW_USEDEFAULT, CW_USEDEFAULT,
|
||||
parent, NULL, g_hModule, NULL);
|
||||
SendMessage(hwndTip, TTM_SETMAXTIPWIDTH, 0, 300);
|
||||
SendMessage(hwndTip, TTM_SETDELAYTIME, TTDT_AUTOPOP, MAKELONG(32767, 0));
|
||||
return hwndTip;
|
||||
}
|
||||
|
||||
bool KexShlExt::CreateTooltip(HWND hwndTip, HWND hDlg, int toolID, char* pText)
|
||||
{
|
||||
if (!hwndTip || !toolID || !hDlg || !pText)
|
||||
return false;
|
||||
|
||||
// Get the window of the tool.
|
||||
HWND hwndTool = GetDlgItem(hDlg, toolID);
|
||||
if (!hwndTool)
|
||||
return false;
|
||||
|
||||
// Associate the tooltip with the tool.
|
||||
TOOLINFO toolInfo;
|
||||
toolInfo.cbSize = sizeof(toolInfo);
|
||||
toolInfo.hwnd = hDlg;
|
||||
toolInfo.uFlags = TTF_IDISHWND | TTF_SUBCLASS;
|
||||
toolInfo.uId = (UINT_PTR) hwndTool;
|
||||
toolInfo.lpszText = pText;
|
||||
toolInfo.hinst = g_hModule;
|
||||
SendMessage(hwndTip, TTM_ADDTOOL, 0, (LPARAM) &toolInfo);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
Reference in New Issue
Block a user