// Copyright © 2017 Paddy Xu // // This file is part of QuickLook program. // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program. If not, see . #include "stdafx.h" #include "HelperMethods.h" void HelperMethods::GetSelectedInternal(CComQIPtr pwba, PWCHAR buffer) { CComQIPtr psp; if (FAILED(pwba->QueryInterface(IID_IServiceProvider, reinterpret_cast(&psp)))) return; CComPtr psb; if (FAILED(psp->QueryService(SID_STopLevelBrowser, IID_IShellBrowser, reinterpret_cast(&psb)))) return; CComPtr psv; if (FAILED(psb->QueryActiveShellView(&psv))) return; CComPtr dao; if (FAILED(psv->GetItemObject(SVGIO_SELECTION, IID_IDataObject, reinterpret_cast(&dao)))) return; return ObtainFirstItem(dao, buffer); } void HelperMethods::ObtainFirstItem(CComPtr dao, PWCHAR buffer) { FORMATETC formatetc; STGMEDIUM medium; formatetc.cfFormat = CF_HDROP; formatetc.ptd = nullptr; formatetc.dwAspect = DVASPECT_CONTENT; formatetc.lindex = -1; formatetc.tymed = TYMED_HGLOBAL; medium.tymed = TYMED_HGLOBAL; if (FAILED(dao->GetData(&formatetc, &medium))) return; int n = DragQueryFile(HDROP(medium.hGlobal), 0xFFFFFFFF, nullptr, 0); if (n < 1) return; DragQueryFile(HDROP(medium.hGlobal), 0, buffer, MAX_PATH - 1); } bool HelperMethods::IsCursorActivated(HWND hwnd) { auto tId = GetWindowThreadProcessId(hwnd, nullptr); GUITHREADINFO gui = {sizeof gui}; GetGUIThreadInfo(tId, &gui); return gui.flags || gui.hwndCaret; }