mirror of
https://github.com/QL-Win/QuickLook.git
synced 2025-09-11 17:59:17 +00:00
Fix for Tabbed File Explorer in Windows 11 22H2
This commit is contained in:
@@ -18,16 +18,8 @@
|
||||
#include "stdafx.h"
|
||||
#include "HelperMethods.h"
|
||||
|
||||
void HelperMethods::GetSelectedInternal(CComQIPtr<IWebBrowserApp> pwba, PWCHAR buffer)
|
||||
void HelperMethods::GetSelectedInternal(CComPtr<IShellBrowser> psb, PWCHAR buffer)
|
||||
{
|
||||
CComQIPtr<IServiceProvider> psp;
|
||||
if (FAILED(pwba->QueryInterface(IID_IServiceProvider, reinterpret_cast<void**>(&psp))))
|
||||
return;
|
||||
|
||||
CComPtr<IShellBrowser> psb;
|
||||
if (FAILED(psp->QueryService(SID_STopLevelBrowser, IID_IShellBrowser, reinterpret_cast<LPVOID*>(&psb))))
|
||||
return;
|
||||
|
||||
CComPtr<IShellView> psv;
|
||||
if (FAILED(psb->QueryActiveShellView(&psv)))
|
||||
return;
|
||||
|
@@ -19,7 +19,7 @@
|
||||
class HelperMethods
|
||||
{
|
||||
public:
|
||||
static void GetSelectedInternal(CComQIPtr<IWebBrowserApp> pWebBrowserApp, PWCHAR buffer);
|
||||
static void GetSelectedInternal(CComPtr<IShellBrowser> psb, PWCHAR buffer);
|
||||
static void ObtainFirstItem(CComPtr<IDataObject> dao, PWCHAR buffer);
|
||||
static bool IsCursorActivated(HWND hwndfg);
|
||||
static bool IsExplorerSearchBoxFocused();
|
||||
|
@@ -104,7 +104,8 @@ void Shell32::getSelectedFromExplorer(PWCHAR buffer)
|
||||
if (FAILED(psw.CoCreateInstance(CLSID_ShellWindows)))
|
||||
return;
|
||||
|
||||
auto hwndfg = GetForegroundWindow();
|
||||
auto hwndfgw = GetForegroundWindow();
|
||||
auto hwndfgt = FindWindowEx(hwndfgw, nullptr, L"ShellTabWindowClass", nullptr);
|
||||
|
||||
auto count = 0L;
|
||||
psw->get_Count(&count);
|
||||
@@ -120,18 +121,26 @@ void Shell32::getSelectedFromExplorer(PWCHAR buffer)
|
||||
if (S_OK != psw->Item(vi, &pdisp))
|
||||
continue;
|
||||
|
||||
CComQIPtr<IWebBrowserApp> pwba;
|
||||
if (FAILED(pdisp->QueryInterface(IID_IWebBrowserApp, reinterpret_cast<void**>(&pwba))))
|
||||
CComPtr<IServiceProvider> psp;
|
||||
if (FAILED(pdisp->QueryInterface(IID_IServiceProvider, reinterpret_cast<void**>(&psp))))
|
||||
continue;
|
||||
|
||||
HWND hwndwba;
|
||||
if (FAILED(pwba->get_HWND(reinterpret_cast<LONG_PTR*>(&hwndwba))))
|
||||
CComPtr<IShellBrowser> psb;
|
||||
if (FAILED(psp->QueryService(IID_IShellBrowser, IID_IShellBrowser, reinterpret_cast<LPVOID*>(&psb))))
|
||||
continue;
|
||||
|
||||
if (hwndwba != hwndfg || HelperMethods::IsCursorActivated(hwndwba))
|
||||
HWND phwnd;
|
||||
if (FAILED(psb->GetWindow(&phwnd)))
|
||||
continue;
|
||||
|
||||
HelperMethods::GetSelectedInternal(pwba, buffer);
|
||||
if (hwndfgw != phwnd && (hwndfgt != nullptr && hwndfgt != phwnd))
|
||||
continue;
|
||||
|
||||
if (HelperMethods::IsCursorActivated(0))
|
||||
continue;
|
||||
|
||||
HelperMethods::GetSelectedInternal(psb, buffer);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -140,7 +149,7 @@ void Shell32::getSelectedFromDesktop(PWCHAR buffer)
|
||||
CoInitialize(nullptr);
|
||||
|
||||
CComPtr<IShellWindows> psw;
|
||||
CComQIPtr<IWebBrowserApp> pwba;
|
||||
CComPtr<IWebBrowserApp> pwba;
|
||||
|
||||
if (FAILED(psw.CoCreateInstance(CLSID_ShellWindows)))
|
||||
return;
|
||||
@@ -155,5 +164,13 @@ void Shell32::getSelectedFromDesktop(PWCHAR buffer)
|
||||
if (HelperMethods::IsCursorActivated(reinterpret_cast<HWND>(LongToHandle(phwnd))))
|
||||
return;
|
||||
|
||||
HelperMethods::GetSelectedInternal(pwba, buffer);
|
||||
CComPtr<IServiceProvider> psp;
|
||||
if (FAILED(pwba->QueryInterface(IID_IServiceProvider, reinterpret_cast<void**>(&psp))))
|
||||
return;
|
||||
|
||||
CComPtr<IShellBrowser> psb;
|
||||
if (FAILED(psp->QueryService(IID_IShellBrowser, IID_IShellBrowser, reinterpret_cast<LPVOID*>(&psb))))
|
||||
return;
|
||||
|
||||
HelperMethods::GetSelectedInternal(psb, buffer);
|
||||
}
|
||||
|
@@ -21,6 +21,7 @@ using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Runtime.InteropServices.ComTypes;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace QuickLook.NativeMethods
|
||||
@@ -83,24 +84,25 @@ namespace QuickLook.NativeMethods
|
||||
|
||||
internal static string GetCurrentSelection()
|
||||
{
|
||||
StringBuilder sb = null;
|
||||
try
|
||||
StringBuilder sb = new StringBuilder(MaxPath);
|
||||
// communicate with COM in a separate STA thread
|
||||
var thread = new Thread(() =>
|
||||
{
|
||||
// communicate with COM in a separate thread
|
||||
Task.Run(() =>
|
||||
try
|
||||
{
|
||||
sb = new StringBuilder(MaxPath);
|
||||
if (App.Is64Bit)
|
||||
GetCurrentSelectionNative_64(sb);
|
||||
else
|
||||
GetCurrentSelectionNative_32(sb);
|
||||
}).Wait();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.WriteLine(e);
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.WriteLine(e);
|
||||
}
|
||||
});
|
||||
thread.SetApartmentState(ApartmentState.STA);
|
||||
thread.Start();
|
||||
thread.Join();
|
||||
return ResolveShortcut(sb?.ToString() ?? string.Empty);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user