Skip to content

Commit

Permalink
bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Maplespe committed Jan 12, 2023
1 parent fb48809 commit 9eca65e
Show file tree
Hide file tree
Showing 4 changed files with 184 additions and 35 deletions.
1 change: 1 addition & 0 deletions ExplorerBlurMica/ExplorerBlurMica.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@
<ConformanceMode>true</ConformanceMode>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
Expand Down
93 changes: 60 additions & 33 deletions ExplorerBlurMica/HookDef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
* Copyright winmoes.com
*/
#include "HookDef.h"
#include "ShellLoader.h"
#include <unordered_map>
#include <functional>
#include <vssym32.h>
#include <dwmapi.h>
#include <mutex>
#include <iostream>
#pragma comment(lib, "dwmapi.lib")
#pragma comment(lib, "Comctl32.lib") //Win32 Controls

Expand All @@ -27,6 +29,7 @@ struct DUIData
SIZE size = { 0,0 };
bool treeDraw = false;
bool refresh = true;
std::wstring path; //当前打开路径
};
struct Config
{
Expand Down Expand Up @@ -87,8 +90,8 @@ class hashMap
hashMap<DWORD, DUIData> m_DUIList; //dui句柄列表
hashMap<DWORD, std::pair<HWND, HDC>> m_ribbonPaint; //用来记录win10 Ribbon区域是否绘制
hashMap<DWORD, bool> m_drawtextState; //用来记录drawText Alpha修复状态
HBRUSH m_clearBrush = 0; //用于清空DC的画刷
Config m_config; //配置文件
HBRUSH m_clearBrush = 0; //用于清空DC的画刷
Config m_config; //配置文件


inline COLORREF M_RGBA(BYTE r, BYTE g, BYTE b, BYTE a)
Expand Down Expand Up @@ -141,6 +144,14 @@ void RefreshConfig()
RefreshWin10BlurFrame(m_config.smallborder);
}

void OnDocComplete(std::wstring path, DWORD threadID)
{
//std::wcout << L"path[" << threadID << L"] " << path << L"\n";
auto iter = m_DUIList.find(threadID);
if (iter != m_DUIList.end())
iter->second.path = path;
}

namespace Hook
{
int hookIndex = 0;
Expand Down Expand Up @@ -182,6 +193,15 @@ namespace Hook

_DrawThemeBackgroundEx_.Attach();
_PatBlt_.Attach();

#ifdef _DEBUG
AllocConsole();
FILE* pOut = NULL;
freopen_s(&pOut, "conout$", "w", stdout);
freopen_s(&pOut, "conout$", "w", stderr);
std::wcout.imbue(std::locale("chs"));
#endif // _DEBUG

}

void HookDetachAll()
Expand All @@ -190,11 +210,16 @@ namespace Hook
MH_Uninitialize();
}

//是否为dui线程
bool IsDUIThread()
//检查排除路径和线程
bool IsExcludePath()
{
auto iter = m_DUIList.find(GetCurrentThreadId());
return iter != m_DUIList.end();
if (iter != m_DUIList.end())
{
if (iter->second.path.find(L"::{26EE0668-A00A-44D7-9371-BEB064C98683}") == -1)
return false;
}
return true;
}

//刷新22H2的窗口标题栏区域
Expand Down Expand Up @@ -349,7 +374,7 @@ namespace Hook
}

//修复Blur下Edit的Alpha
if (IsDUIThread()) {
if (!IsExcludePath()) {
if (ConvertTolower(ClassName) == L"edit")
{
SetWindowLongW(hWnd, GWL_EXSTYLE, GetWindowLongW(hWnd, GWL_EXSTYLE) | WS_EX_LAYERED);
Expand Down Expand Up @@ -482,7 +507,7 @@ namespace Hook
{
SetWindowBlur(iter->second.mainWnd);
}

InvalidateRect(iter->second.hWnd, nullptr, TRUE);
iter->second.refresh = false;
}
//判断树列表颜色是否被改变
Expand Down Expand Up @@ -522,7 +547,7 @@ namespace Hook
BOOL MyPatBlt(HDC hdc, int x, int y, int w, int h, DWORD rop)
{
//修复选择矩形框的Alpha
if (IsDUIThread() && rop == PATCOPY) {
if (!IsExcludePath() && rop == PATCOPY) {
//检测调用线程
static std::unordered_map<DWORD, bool> thList;

Expand Down Expand Up @@ -640,7 +665,7 @@ namespace Hook
static std::unordered_map<DWORD, bool> thList;
DWORD curTh = GetCurrentThreadId();

if (IsDUIThread() && !(option & ETO_GLYPH_INDEX) && !(option & ETO_IGNORELANGUAGE)
if (IsExcludePath() && !(CheckCaller(L"msctf.dll")) && !(option & ETO_GLYPH_INDEX) && !(option & ETO_IGNORELANGUAGE)
&& thList.find(curTh) == thList.end() && str != L"" && m_drawtextState.find(curTh) == m_drawtextState.end())
{
thList.insert(std::make_pair(curTh, true));
Expand Down Expand Up @@ -769,7 +794,7 @@ namespace Hook
std::wstring kname = GetThemeClassName(hTheme);

//将主要控件的背景色设置为黑色 以供API透明化Blur效果
if (iPropId == TMT_FILLCOLOR && IsDUIThread())
if (iPropId == TMT_FILLCOLOR && !IsExcludePath())
{
//DUI视图、底部状态栏、导航栏
if (((kname == L"ItemsView" || kname == L"ExplorerStatusBar" || kname == L"ExplorerNavPane")
Expand Down Expand Up @@ -859,35 +884,37 @@ namespace Hook
)
{
std::wstring kname = GetThemeClassName(hTheme);

//Blur模式下 透明化 Header、Rebar、预览面板、命令模块
if (kname == L"Header") {
if ((iPartId == HP_HEADERITEM && iStateId == HIS_NORMAL)
|| (iPartId == HP_HEADERITEM && iStateId == HIS_SORTEDNORMAL)
|| (iPartId == 0 && iStateId == HIS_NORMAL))
return S_OK;
}
else if (kname == L"Rebar")
if (!IsExcludePath())
{
if ((iPartId == RP_BACKGROUND || iPartId == RP_BAND) && iStateId == 0)
//Blur模式下 透明化 Header、Rebar、预览面板、命令模块
if (kname == L"Header") {
if ((iPartId == HP_HEADERITEM && iStateId == HIS_NORMAL)
|| (iPartId == HP_HEADERITEM && iStateId == HIS_SORTEDNORMAL)
|| (iPartId == 0 && iStateId == HIS_NORMAL))
return S_OK;
}
else if (kname == L"Rebar")
{
return S_OK;
if ((iPartId == RP_BACKGROUND || iPartId == RP_BAND) && iStateId == 0)
{
return S_OK;
}
}
}
else if (kname == L"CommandModule" && IsDUIThread())
{
if (iPartId == 1 && iStateId == 0) {
else if (kname == L"PreviewPane")
{
if (iPartId == 1 && iStateId == 1)
return S_OK;
}
else if (kname == L"CommandModule")
{
if (iPartId == 1 && iStateId == 0) {

FillRect(hdc, pRect, m_clearBrush);
return S_OK;
FillRect(hdc, pRect, m_clearBrush);
return S_OK;
}
}
}
else if (kname == L"PreviewPane")
{
if (iPartId == 1 && iStateId == 1)
return S_OK;
}

End:
return _DrawThemeBackgroundEx_.Org(hTheme, hdc, iPartId, iStateId, pRect, pOptions);
}
}
96 changes: 95 additions & 1 deletion ExplorerBlurMica/ShellLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,79 @@ long g_cDllRef = 0;
const std::wstring CLSID_SHELL_BHO_STR = L"{B44BD3C8-E597-4E08-AE43-246CE24698E7}";
const CLSID CLSID_SHELL_BHO = { 0xb44bd3c8, 0xe597, 0x4e08, { 0xae, 0x43, 0x24, 0x6c, 0xe2, 0x46, 0x98, 0xe7 } };

#pragma region IDispatch

CIDispatch::~CIDispatch()
{
}

STDMETHODIMP CIDispatch::QueryInterface(REFIID riid, void** ppv)
{
if (riid == IID_IUnknown || riid == DIID_DWebBrowserEvents2)
*ppv = static_cast<CIDispatch*>(this);
else if (riid == IID_IDispatch)
*ppv = static_cast<IDispatch*>(this);
else
return E_NOINTERFACE;
AddRef();
return S_OK;
}

ULONG __stdcall CIDispatch::AddRef()
{
InterlockedIncrement(&g_cDllRef);
return InterlockedIncrement(&m_ref);
}

ULONG __stdcall CIDispatch::Release()
{
int tmp = InterlockedDecrement(&m_ref);
if (tmp == 0)
delete this;
InterlockedDecrement(&g_cDllRef);
return tmp;
}

STDMETHODIMP CIDispatch::Invoke(DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS* pDispParams, VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr)
{
if (!pDispParams)
return E_INVALIDARG;

switch (dispIdMember)
{
case DISPID_BEFORENAVIGATE2:
break;
case DISPID_NAVIGATECOMPLETE2:
break;
case DISPID_DOCUMENTCOMPLETE:
{
std::wstring path = (wchar_t*)pDispParams->rgvarg->pvarVal->bstrVal;
if (path != m_lastpath)
{
m_lastpath = path;
OnDocComplete(path, GetCurrentThreadId());
}
}
break;
case DISPID_DOWNLOADBEGIN:
break;
case DISPID_DOWNLOADCOMPLETE:
break;
case DISPID_NEWWINDOW2:
break;
case DISPID_WINDOWREGISTERED:
break;
case DISPID_ONQUIT:
break;
default:
break;
}

return S_OK;
}

#pragma endregion

#pragma region CObjectWithSite

CObjectWithSite::CObjectWithSite()
Expand Down Expand Up @@ -60,13 +133,34 @@ STDMETHODIMP CObjectWithSite::SetSite(IUnknown* pUnkSite)
HRESULT hr = pUnkSite->QueryInterface(IID_IWebBrowser2, (void**)&m_web);
if (FAILED(hr))
ReleaseRes();

IConnectionPointContainer* cpoint = nullptr;

hr = m_web->QueryInterface(IID_IConnectionPointContainer, (void**)&cpoint);
if (FAILED(hr)) return E_FAIL;

hr = cpoint->FindConnectionPoint(DIID_DWebBrowserEvents2, &m_cpoint);
if (FAILED(hr))
{
cpoint->Release();
return E_FAIL;
}

m_cpoint->Advise((IUnknown*)new CIDispatch(), &m_cookie);

return hr;
}

void CObjectWithSite::ReleaseRes()
{
if (m_web) m_web->Release();
m_web = 0;
if (m_cpoint)
{
m_cpoint->Unadvise(m_cookie);
m_cpoint->Release();
}
m_web = nullptr;
m_cpoint = nullptr;
}

#pragma endregion
Expand Down
29 changes: 28 additions & 1 deletion ExplorerBlurMica/ShellLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,32 @@ extern const std::wstring CLSID_SHELL_BHO_STR;
extern const CLSID CLSID_SHELL_BHO;

extern void OnWindowLoad();
extern void OnDocComplete(std::wstring, DWORD);

/*
* IDispatch 接口实现 浏览器事件
*/
class CIDispatch : public IDispatch
{
public:
CIDispatch() = default;
~CIDispatch();

//IUnknown
STDMETHODIMP QueryInterface(REFIID riid, void** ppv);
ULONG STDMETHODCALLTYPE AddRef();
ULONG STDMETHODCALLTYPE Release();

//IDispatch
STDMETHODIMP GetTypeInfoCount(UINT* pctinfo) { return E_NOTIMPL; }
STDMETHODIMP GetTypeInfo(UINT iTInfo, LCID lcid, ITypeInfo** ppTInfo) { return E_NOTIMPL; }
STDMETHODIMP GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames, UINT cNames, LCID lcid, DISPID* rgDispId) { return E_NOTIMPL; }
STDMETHODIMP Invoke(DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS* pDispParams, VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr);

protected:
long m_ref = 0;
std::wstring m_lastpath;
};

/*
* 一个基本的COM浏览器类 只实现基本接口
Expand All @@ -40,7 +66,8 @@ class CObjectWithSite : public IObjectWithSite
protected:
long m_ref = 0;
IWebBrowser2* m_web = nullptr;

IConnectionPoint* m_cpoint = nullptr;
DWORD m_cookie = 0;
void ReleaseRes();
};

Expand Down

0 comments on commit 9eca65e

Please sign in to comment.