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