Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <windows.h>
- #include <shellapi.h>
- #include <shlwapi.h>
- #include <shlobj.h>
- #include <shobjidl.h>
- void PinToTaskbar(LPCWSTR path, BOOL reg){
- WCHAR dir[MAX_PATH];
- WCHAR file[MAX_PATH];
- LPWSTR lpFilePart;
- IShellFolder *pdf;
- LPITEMIDLIST pidl;
- HWND hwnd = GetDesktopWindow();
- GetFullPathName(path, MAX_PATH,dir, &lpFilePart);
- StrCpyW(file, lpFilePart);
- PathRemoveFileSpec(dir);
- if (FAILED(SHGetDesktopFolder(&pdf))) return;
- if (SUCCEEDED(pdf->lpVtbl->ParseDisplayName(pdf, NULL, NULL, dir, NULL, &pidl, NULL))){
- IShellFolder *psf;
- if (SUCCEEDED(pdf->lpVtbl->BindToObject(pdf, pidl, NULL, &IID_IShellFolder, &psf))){
- LPENUMIDLIST pei;
- if (SUCCEEDED(psf->lpVtbl->EnumObjects(psf, hwnd, SHCONTF_NONFOLDERS, &pei))){
- LPITEMIDLIST pitm;
- while (pei->lpVtbl->Next(pei, 1, &pitm, NULL) == NO_ERROR){
- STRRET sr = { STRRET_WSTR, } ;
- psf->lpVtbl->GetDisplayNameOf(psf, pitm, SHGDN_INFOLDER | SHGDN_FORPARSING, &sr);
- if (sr.uType == STRRET_WSTR && StrCmpIW(sr.pOleStr, file) == 0){
- LPCONTEXTMENU pcm;
- if (SUCCEEDED(psf->lpVtbl->GetUIObjectOf(psf, hwnd, 1, &pitm, &IID_IContextMenu, NULL, &pcm))){
- HMENU hmenu = CreatePopupMenu();
- if (SUCCEEDED(pcm->lpVtbl->QueryContextMenu(pcm, hmenu, 0, 1, 0x7fff, CMF_EXPLORE))){
- CMINVOKECOMMANDINFO ici;
- ici.cbSize = sizeof(ici);
- ici.fMask = 0;
- ici.hwnd = hwnd;
- ici.lpVerb = reg ? "taskbarpin" : "taskbarunpin";
- ici.lpParameters = NULL;
- ici.lpDirectory = NULL;
- ici.nShow = SW_SHOW;
- pcm->lpVtbl->InvokeCommand(pcm, &ici);
- }
- DestroyMenu(hmenu);
- pcm->lpVtbl->Release(pcm);
- }
- }
- CoTaskMemFree(pitm);
- }
- pei->lpVtbl->Release(pei);
- }
- psf->lpVtbl->Release(psf);
- }
- CoTaskMemFree(pidl);
- }
- pdf->lpVtbl->Release(pdf);
- }
- int WINAPI WinMain(HINSTANCE hinst, HINSTANCE hinstPrev, LPSTR lpszCmdLine, int nCmdShow){
- int i, argc;
- LPCWSTR *argv = CommandLineToArgvW(GetCommandLineW(), &argc);
- CoInitialize(NULL);
- for (i = 1; i < argc; i++) PinToTaskbar(argv[i], TRUE);
- CoUninitialize();
- GlobalFree((HGLOBAL)argv);
- ExitProcess(0);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement