forked from QL-Win/QuickLook
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShell32.cpp
More file actions
176 lines (147 loc) · 4.21 KB
/
Shell32.cpp
File metadata and controls
176 lines (147 loc) · 4.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
// 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 <http://www.gnu.org/licenses/>.
#include "stdafx.h"
#include "Shell32.h"
#include "HelperMethods.h"
#include "DialogHook.h"
#include "Everything.h"
#include "DOpus.h"
using namespace std;
Shell32::FocusedWindowType Shell32::GetFocusedWindowType()
{
auto hwndfg = GetForegroundWindow();
if (HelperMethods::IsCursorActivated(hwndfg))
return INVALID;
WCHAR classBuffer[MAX_PATH] = { '\0' };
if (FAILED(GetClassName(hwndfg, classBuffer, MAX_PATH)))
return INVALID;
if (wcscmp(classBuffer, L"dopus.lister") == 0)
{
return DOPUS;
}
if (wcscmp(classBuffer, L"EVERYTHING") == 0 || wcscmp(classBuffer, L"EVERYTHING_SHELL_EXECUTE") == 0)
{
return EVERYTHING;
}
if (wcscmp(classBuffer, L"WorkerW") == 0 || wcscmp(classBuffer, L"Progman") == 0)
{
if (FindWindowEx(hwndfg, nullptr, L"SHELLDLL_DefView", nullptr) != nullptr)
{
return DESKTOP;
}
}
if (wcscmp(classBuffer, L"ExploreWClass") == 0 || wcscmp(classBuffer, L"CabinetWClass") == 0)
{
if (!HelperMethods::IsExplorerSearchBoxFocused())
{
return EXPLORER;
}
}
if (wcscmp(classBuffer, L"#32770") == 0)
{
if (FindWindowEx(hwndfg, nullptr, L"DUIViewWndClassName", nullptr) != nullptr)
{
if (!HelperMethods::IsExplorerSearchBoxFocused())
{
return DIALOG;
}
}
}
return INVALID;
}
void Shell32::GetCurrentSelection(PWCHAR buffer)
{
switch (GetFocusedWindowType())
{
case DESKTOP:
getSelectedFromDesktop(buffer);
break;
case EXPLORER:
getSelectedFromExplorer(buffer);
break;
case DIALOG:
DialogHook::GetSelected(buffer);
break;
case EVERYTHING:
Everything::GetSelected(buffer);
break;
case DOPUS:
DOpus::GetSelected(buffer);
break;
default:
break;
}
}
void Shell32::getSelectedFromExplorer(PWCHAR buffer)
{
CoInitialize(nullptr);
CComPtr<IShellWindows> psw;
if (FAILED(psw.CoCreateInstance(CLSID_ShellWindows)))
return;
auto hwndfgw = GetForegroundWindow();
auto hwndfgt = FindWindowEx(hwndfgw, nullptr, L"ShellTabWindowClass", nullptr);
auto count = 0L;
psw->get_Count(&count);
for (auto i = 0; i < count; i++)
{
VARIANT vi;
VariantInit(&vi);
V_VT(&vi) = VT_I4;
V_I4(&vi) = i;
CComPtr<IDispatch> pdisp;
if (S_OK != psw->Item(vi, &pdisp))
continue;
CComPtr<IServiceProvider> psp;
if (FAILED(pdisp->QueryInterface(IID_IServiceProvider, reinterpret_cast<void**>(&psp))))
continue;
CComPtr<IShellBrowser> psb;
if (FAILED(psp->QueryService(IID_IShellBrowser, IID_IShellBrowser, reinterpret_cast<LPVOID*>(&psb))))
continue;
HWND phwnd;
if (FAILED(psb->GetWindow(&phwnd)))
continue;
if (hwndfgw != phwnd && (hwndfgt != nullptr && hwndfgt != phwnd))
continue;
if (HelperMethods::IsCursorActivated(0))
continue;
HelperMethods::GetSelectedInternal(psb, buffer);
return;
}
}
void Shell32::getSelectedFromDesktop(PWCHAR buffer)
{
CoInitialize(nullptr);
CComPtr<IShellWindows> psw;
CComPtr<IWebBrowserApp> pwba;
if (FAILED(psw.CoCreateInstance(CLSID_ShellWindows)))
return;
VARIANT pvarLoc;
VariantInit(&pvarLoc);
long phwnd;
if (FAILED(psw->FindWindowSW(&pvarLoc, &pvarLoc, SWC_DESKTOP, &phwnd, SWFO_NEEDDISPATCH, reinterpret_cast<IDispatch**>(
&pwba))))
return;
if (HelperMethods::IsCursorActivated(reinterpret_cast<HWND>(LongToHandle(phwnd))))
return;
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);
}