@@ -104,7 +104,8 @@ void Shell32::getSelectedFromExplorer(PWCHAR buffer)
104
104
if (FAILED (psw.CoCreateInstance (CLSID_ShellWindows)))
105
105
return ;
106
106
107
- auto hwndfg = GetForegroundWindow ();
107
+ auto hwndfgw = GetForegroundWindow ();
108
+ auto hwndfgt = FindWindowEx (hwndfgw, nullptr , L" ShellTabWindowClass" , nullptr );
108
109
109
110
auto count = 0L ;
110
111
psw->get_Count (&count);
@@ -120,18 +121,26 @@ void Shell32::getSelectedFromExplorer(PWCHAR buffer)
120
121
if (S_OK != psw->Item (vi, &pdisp))
121
122
continue ;
122
123
123
- CComQIPtr<IWebBrowserApp> pwba;
124
- if (FAILED (pdisp->QueryInterface (IID_IWebBrowserApp, reinterpret_cast <void **>(&pwba))))
124
+ CComPtr<IServiceProvider> psp;
125
+ if (FAILED (pdisp->QueryInterface (IID_IServiceProvider, reinterpret_cast <void **>(&psp))))
126
+ continue ;
127
+
128
+ CComPtr<IShellBrowser> psb;
129
+ if (FAILED (psp->QueryService (IID_IShellBrowser, IID_IShellBrowser, reinterpret_cast <LPVOID*>(&psb))))
130
+ continue ;
131
+
132
+ HWND phwnd;
133
+ if (FAILED (psb->GetWindow (&phwnd)))
125
134
continue ;
126
135
127
- HWND hwndwba;
128
- if (FAILED (pwba->get_HWND (reinterpret_cast <LONG_PTR*>(&hwndwba))))
136
+ if (hwndfgw != phwnd && (hwndfgt != nullptr && hwndfgt != phwnd))
129
137
continue ;
130
138
131
- if (hwndwba != hwndfg || HelperMethods::IsCursorActivated (hwndwba ))
139
+ if (HelperMethods::IsCursorActivated (0 ))
132
140
continue ;
133
141
134
- HelperMethods::GetSelectedInternal (pwba, buffer);
142
+ HelperMethods::GetSelectedInternal (psb, buffer);
143
+ return ;
135
144
}
136
145
}
137
146
@@ -140,7 +149,7 @@ void Shell32::getSelectedFromDesktop(PWCHAR buffer)
140
149
CoInitialize (nullptr );
141
150
142
151
CComPtr<IShellWindows> psw;
143
- CComQIPtr <IWebBrowserApp> pwba;
152
+ CComPtr <IWebBrowserApp> pwba;
144
153
145
154
if (FAILED (psw.CoCreateInstance (CLSID_ShellWindows)))
146
155
return ;
@@ -155,5 +164,13 @@ void Shell32::getSelectedFromDesktop(PWCHAR buffer)
155
164
if (HelperMethods::IsCursorActivated (reinterpret_cast <HWND>(LongToHandle (phwnd))))
156
165
return ;
157
166
158
- HelperMethods::GetSelectedInternal (pwba, buffer);
167
+ CComPtr<IServiceProvider> psp;
168
+ if (FAILED (pwba->QueryInterface (IID_IServiceProvider, reinterpret_cast <void **>(&psp))))
169
+ return ;
170
+
171
+ CComPtr<IShellBrowser> psb;
172
+ if (FAILED (psp->QueryService (IID_IShellBrowser, IID_IShellBrowser, reinterpret_cast <LPVOID*>(&psb))))
173
+ return ;
174
+
175
+ HelperMethods::GetSelectedInternal (psb, buffer);
159
176
}
0 commit comments