- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 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
bool getSelectedFile(wchar_t *out, bool skip) {
HWND hwndFind = GetForegroundWindow();
TCHAR g_szPath[BUF_SIZE];
TCHAR g_szItem[BUF_SIZE];
//g_szPath[0] = TEXT('\0');
//g_szItem[0] = TEXT('\0');
memset(g_szPath, 0, sizeof(TCHAR) * BUF_SIZE);
memset(g_szItem, 0, sizeof(TCHAR) * BUF_SIZE);
IShellWindows *psw;
if(CoCreateInstance(CLSID_ShellWindows, NULL, CLSCTX_ALL, IID_IShellWindows, (void**)&psw) != S_OK) return false;
VARIANT v;
v.vt = VT_I4;
IDispatch *pdisp;
bool fFound = false;
bool pExtracted = false;
bool nExtracted = false;
for (V_I4(&v) = 0; !fFound && psw->Item(v, &pdisp) == S_OK; V_I4(&v)++) {
IWebBrowserApp *pwba;
if(SUCCEEDED(pdisp->QueryInterface(IID_IWebBrowserApp, (void**)&pwba))) {
HWND hwndWBA;
if (SUCCEEDED(pwba->get_HWND((LONG_PTR*)&hwndWBA)) && hwndWBA == hwndFind) {
fFound = true;
IServiceProvider *psp;
if(SUCCEEDED(pwba->QueryInterface(IID_IServiceProvider, (void**)&psp))) {
IShellBrowser *psb;
if(SUCCEEDED(psp->QueryService(SID_STopLevelBrowser, IID_IShellBrowser, (void**)&psb))) {
IShellView *psv;
if(SUCCEEDED(psb->QueryActiveShellView(&psv))) {
IFolderView *pfv;
if(SUCCEEDED(psv->QueryInterface(IID_IFolderView, (void**)&pfv))) {
IPersistFolder2 *ppf2;
if(SUCCEEDED(pfv->GetFolder(IID_IPersistFolder2, (void**)&ppf2))) {
LPITEMIDLIST pidlFolder;
if(SUCCEEDED(ppf2->GetCurFolder(&pidlFolder))) {
if(SHGetPathFromIDList(pidlFolder, g_szPath)) {
pExtracted = true;
if(skip) {
lstrcpy(out, g_szPath);
out[lstrlen(g_szPath)] = 0;
return true;
}
}
int iFocus;
if(SUCCEEDED(pfv->GetFocusedItem(&iFocus))) {
LPITEMIDLIST pidlItem;
if (SUCCEEDED(pfv->Item(iFocus, &pidlItem))) {
IShellFolder *psf;
if (SUCCEEDED(ppf2->QueryInterface(IID_IShellFolder, (void**)&psf))) {
STRRET str;
if(SUCCEEDED(psf->GetDisplayNameOf(pidlItem, SHGDN_INFOLDER, &str))) {
StrRetToBuf(&str, pidlItem, g_szItem, 1024);
nExtracted = true;
int psz = lstrlen(g_szPath);
int isz = lstrlen(g_szItem);
if(pExtracted) {
lstrcpy(out, g_szPath);
out[psz] = '\\';
}
lstrcpy(out+psz+1, g_szItem);
out[psz + isz + 2] = 0;
}
psf->Release();
}
CoTaskMemFree(pidlItem);
}
}
CoTaskMemFree(pidlFolder);
}
ppf2->Release();
}
pfv->Release();
}
psv->Release();
}
psb->Release();
}
psp->Release();
}
}
pwba->Release();
}
pdisp->Release();
}
psw->Release();
return (pExtracted && nExtracted);
}
Две очаровательных (говно) лестницы из какой-то очередной переназначалки горячих клавиш в Windows.
Оригинал тут: https://github.com/mapseamoff/KeyBinder/blob/master/ShellHelper/ShellHelper/main.cpp