Created
May 18, 2014 23:26
-
-
Save kumatti1/cdd8dd4639b1003986ca to your computer and use it in GitHub Desktop.
エクスプローラ制御
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Windows.h> | |
#include <Shlwapi.h> | |
#include <Shlobj.h> | |
#include <Shobjidl.h> | |
#include <Propkey.h> | |
#include <comdef.h> | |
_COM_SMARTPTR_TYPEDEF(IFolderView, __uuidof(IFolderView)); | |
_COM_SMARTPTR_TYPEDEF(IFolderView2, __uuidof(IFolderView2)); | |
_COM_SMARTPTR_TYPEDEF(IShellWindows, __uuidof(IShellWindows)); | |
int CALLBACK WinMain( | |
_In_ HINSTANCE hInstance, | |
_In_ HINSTANCE hPrevInstance, | |
_In_ LPSTR lpCmdLine, | |
_In_ int nCmdShow | |
) | |
{ | |
try { | |
HRESULT hr = CoInitialize(NULL); | |
IShellWindowsPtr pShellWindows; | |
hr = CoCreateInstance(CLSID_ShellWindows, NULL, CLSCTX_ALL, IID_PPV_ARGS(&pShellWindows)); | |
LPITEMIDLIST piidlDesktop; | |
hr = SHGetSpecialFolderLocation(NULL, CSIDL_DESKTOP, &piidlDesktop); | |
SHOpenFolderAndSelectItems(piidlDesktop, 0, NULL, 0); | |
MessageBoxA(0,"","Explorer起動待ち", MB_OK); | |
VARIANT varRoot; | |
HWND hwnd; | |
IDispatchPtr pDispatch; | |
UINT size = ILGetSize(piidlDesktop); | |
BYTE *byt = (BYTE*) CoTaskMemAlloc(size); | |
RtlMoveMemory(byt, piidlDesktop, size); | |
_variant_t var = byt; | |
VariantInit(&varRoot); | |
hr = pShellWindows->FindWindowSW(&var, &varRoot, SWC_BROWSER, (LONG *) &hwnd, SWFO_NEEDDISPATCH, &pDispatch); | |
CoTaskMemFree(byt); | |
CoTaskMemFree(piidlDesktop); | |
IFolderViewPtr pFolderView = NULL; | |
hr = IUnknown_QueryService(pDispatch, IID_IFolderView, IID_PPV_ARGS(&pFolderView)); | |
IFolderView2Ptr pView; | |
pFolderView->QueryInterface(IID_PPV_ARGS(&pView)); | |
REFPROPERTYKEY key = { 0 }; | |
BOOL fAscending; | |
hr = pView->SetGroupBy(key, fAscending); | |
if (S_OK == hr) | |
MessageBoxA(0, "", "Sort", MB_OK); | |
} | |
catch (_com_error& e) { | |
MessageBoxA(0, "", (LPCSTR) e.ErrorMessage(), MB_OK); | |
} | |
CoUninitialize(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment