mirror of
https://github.com/QL-Win/QuickLook.git
synced 2025-09-11 17:59:17 +00:00
Run code cleanup
This commit is contained in:
@@ -20,114 +20,114 @@
|
||||
|
||||
void HelperMethods::GetSelectedInternal(CComPtr<IShellBrowser> psb, PWCHAR buffer)
|
||||
{
|
||||
CComPtr<IShellView> psv;
|
||||
if (FAILED(psb->QueryActiveShellView(&psv)))
|
||||
return;
|
||||
CComPtr<IShellView> psv;
|
||||
if (FAILED(psb->QueryActiveShellView(&psv)))
|
||||
return;
|
||||
|
||||
CComPtr<IDataObject> dao;
|
||||
if (FAILED(psv->GetItemObject(SVGIO_SELECTION, IID_IDataObject, reinterpret_cast<void**>(&dao))))
|
||||
return;
|
||||
CComPtr<IDataObject> dao;
|
||||
if (FAILED(psv->GetItemObject(SVGIO_SELECTION, IID_IDataObject, reinterpret_cast<void**>(&dao))))
|
||||
return;
|
||||
|
||||
return ObtainFirstItem(dao, buffer);
|
||||
return ObtainFirstItem(dao, buffer);
|
||||
}
|
||||
|
||||
void HelperMethods::ObtainFirstItem(CComPtr<IDataObject> dao, PWCHAR buffer)
|
||||
{
|
||||
FORMATETC formatetc;
|
||||
STGMEDIUM medium = {sizeof medium};
|
||||
FORMATETC formatetc;
|
||||
STGMEDIUM medium = {sizeof medium};
|
||||
|
||||
formatetc.cfFormat = CF_HDROP;
|
||||
formatetc.ptd = nullptr;
|
||||
formatetc.dwAspect = DVASPECT_CONTENT;
|
||||
formatetc.lindex = -1;
|
||||
formatetc.tymed = TYMED_HGLOBAL;
|
||||
formatetc.cfFormat = CF_HDROP;
|
||||
formatetc.ptd = nullptr;
|
||||
formatetc.dwAspect = DVASPECT_CONTENT;
|
||||
formatetc.lindex = -1;
|
||||
formatetc.tymed = TYMED_HGLOBAL;
|
||||
|
||||
medium.tymed = TYMED_HGLOBAL;
|
||||
medium.tymed = TYMED_HGLOBAL;
|
||||
|
||||
if (FAILED(dao->GetData(&formatetc, &medium)))
|
||||
return;
|
||||
if (FAILED(dao->GetData(&formatetc, &medium)))
|
||||
return;
|
||||
|
||||
int n = DragQueryFile(HDROP(medium.hGlobal), 0xFFFFFFFF, nullptr, 0);
|
||||
int n = DragQueryFile(HDROP(medium.hGlobal), 0xFFFFFFFF, nullptr, 0);
|
||||
|
||||
if (n < 1)
|
||||
return;
|
||||
if (n < 1)
|
||||
return;
|
||||
|
||||
WCHAR localBuffer[MAX_PATH] = { '\0' };
|
||||
DragQueryFile(HDROP(medium.hGlobal), 0, localBuffer, MAX_PATH);
|
||||
|
||||
GetLongPathName(localBuffer, buffer, MAX_PATH_EX);
|
||||
WCHAR localBuffer[MAX_PATH] = { '\0' };
|
||||
DragQueryFile(HDROP(medium.hGlobal), 0, localBuffer, MAX_PATH);
|
||||
|
||||
GetLongPathName(localBuffer, buffer, MAX_PATH_EX);
|
||||
}
|
||||
|
||||
bool HelperMethods::IsListaryToolbarVisible()
|
||||
{
|
||||
auto CALLBACK findListaryWindowProc = [](__in HWND hwnd, __in LPARAM lParam)-> BOOL
|
||||
{
|
||||
WCHAR classBuffer[MAX_PATH] = {'\0'};
|
||||
if (FAILED(GetClassName(hwnd, classBuffer, MAX_PATH)))
|
||||
return TRUE;
|
||||
auto CALLBACK findListaryWindowProc = [](__in HWND hwnd, __in LPARAM lParam)-> BOOL
|
||||
{
|
||||
WCHAR classBuffer[MAX_PATH] = {'\0'};
|
||||
if (FAILED(GetClassName(hwnd, classBuffer, MAX_PATH)))
|
||||
return TRUE;
|
||||
|
||||
if (wcsncmp(classBuffer, L"Listary_WidgetWin_", 18) == 0)
|
||||
{
|
||||
if (IsWindowVisible(hwnd))
|
||||
{
|
||||
*reinterpret_cast<bool*>(lParam) = true;
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
return TRUE;
|
||||
};
|
||||
if (wcsncmp(classBuffer, L"Listary_WidgetWin_", 18) == 0)
|
||||
{
|
||||
if (IsWindowVisible(hwnd))
|
||||
{
|
||||
*reinterpret_cast<bool*>(lParam) = true;
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
return TRUE;
|
||||
};
|
||||
|
||||
auto found = false;
|
||||
EnumWindows(findListaryWindowProc, reinterpret_cast<LPARAM>(&found));
|
||||
auto found = false;
|
||||
EnumWindows(findListaryWindowProc, reinterpret_cast<LPARAM>(&found));
|
||||
|
||||
return found;
|
||||
return found;
|
||||
}
|
||||
|
||||
// Windows 10 1909 replaced the search box in the File Explorer by a UWP control.
|
||||
// gti.flags is always 0 for UWP applications.
|
||||
bool HelperMethods::IsExplorerSearchBoxFocused()
|
||||
{
|
||||
auto* hwnd = GetFocusedControl();
|
||||
auto* hwnd = GetFocusedControl();
|
||||
|
||||
WCHAR classBuffer[MAX_PATH] = { '\0' };
|
||||
if (FAILED(GetClassName(hwnd, classBuffer, MAX_PATH)))
|
||||
return false;
|
||||
WCHAR classBuffer[MAX_PATH] = { '\0' };
|
||||
if (FAILED(GetClassName(hwnd, classBuffer, MAX_PATH)))
|
||||
return false;
|
||||
|
||||
return wcscmp(classBuffer, L"Windows.UI.Core.CoreWindow") == 0;
|
||||
return wcscmp(classBuffer, L"Windows.UI.Core.CoreWindow") == 0;
|
||||
}
|
||||
|
||||
bool HelperMethods::IsCursorActivated(HWND hwnd)
|
||||
{
|
||||
auto tId = GetWindowThreadProcessId(hwnd, nullptr);
|
||||
auto tId = GetWindowThreadProcessId(hwnd, nullptr);
|
||||
|
||||
GUITHREADINFO gti = { sizeof gti };
|
||||
GetGUIThreadInfo(tId, >i);
|
||||
GUITHREADINFO gti = { sizeof gti };
|
||||
GetGUIThreadInfo(tId, >i);
|
||||
|
||||
return gti.flags || gti.hwndCaret || IsListaryToolbarVisible();
|
||||
return gti.flags || gti.hwndCaret || IsListaryToolbarVisible();
|
||||
}
|
||||
|
||||
bool HelperMethods::IsUWP()
|
||||
{
|
||||
auto pGCPFN = decltype(&GetCurrentPackageFullName)(
|
||||
GetProcAddress(GetModuleHandle(L"kernel32.dll"), "GetCurrentPackageFullName"));
|
||||
auto pGCPFN = decltype(&GetCurrentPackageFullName)(
|
||||
GetProcAddress(GetModuleHandle(L"kernel32.dll"), "GetCurrentPackageFullName"));
|
||||
|
||||
if (!pGCPFN)
|
||||
return false;
|
||||
if (!pGCPFN)
|
||||
return false;
|
||||
|
||||
UINT32 pn = 0;
|
||||
return pGCPFN(&pn, nullptr) == ERROR_INSUFFICIENT_BUFFER;
|
||||
UINT32 pn = 0;
|
||||
return pGCPFN(&pn, nullptr) == ERROR_INSUFFICIENT_BUFFER;
|
||||
}
|
||||
|
||||
HWND HelperMethods::GetFocusedControl()
|
||||
{
|
||||
auto tid = GetWindowThreadProcessId(GetForegroundWindow(), nullptr);
|
||||
auto tid = GetWindowThreadProcessId(GetForegroundWindow(), nullptr);
|
||||
|
||||
if (0 == AttachThreadInput(GetCurrentThreadId(), tid, TRUE))
|
||||
return nullptr;
|
||||
if (0 == AttachThreadInput(GetCurrentThreadId(), tid, TRUE))
|
||||
return nullptr;
|
||||
|
||||
auto* hwnd = GetFocus();
|
||||
auto* hwnd = GetFocus();
|
||||
|
||||
AttachThreadInput(GetCurrentThreadId(), tid, FALSE);
|
||||
AttachThreadInput(GetCurrentThreadId(), tid, FALSE);
|
||||
|
||||
return hwnd;
|
||||
return hwnd;
|
||||
}
|
||||
|
Reference in New Issue
Block a user