1. Список говнокодов пользователя kovnogod

    Всего: 1

  2. Си / Говнокод #13069

    +108

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    70. 70
    71. 71
    72. 72
    73. 73
    74. 74
    75. 75
    76. 76
    77. 77
    78. 78
    79. 79
    80. 80
    81. 81
    82. 82
    83. 83
    84. 84
    85. 85
    86. 86
    87. 87
    88. 88
    89. 89
    90. 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

    kovnogod, 29 Мая 2013

    Комментарии (66)