www.pudn.com > FTP¿Í»§¶Ë³ÌÐòµÄÔ´³ÌÐò.zip > FPMenu.h
// FPMenu.h : Declaration of the CFPMenu // Copyright © 1999 Ziff-Davis, Inc. // Written by Ignacio Alvarez #ifndef __FPMENU_H_ #define __FPMENU_H_ #include "resource.h" // main symbols #include "About.h" ///////////////////////////////////////////////////////////////////////////// // CFPMenu class ATL_NO_VTABLE CFPMenu : public CComObjectRootEx, public CComCoClass , public IFPMenu, public IShellExtInit, public IContextMenu { public: CFPMenu() { PopupMenu = CreatePopupMenu(); } ~CFPMenu() { DestroyMenu(PopupMenu); } DECLARE_REGISTRY_RESOURCEID(IDR_FPMENU) DECLARE_NOT_AGGREGATABLE(CFPMenu) DECLARE_PROTECT_FINAL_CONSTRUCT() BEGIN_COM_MAP(CFPMenu) COM_INTERFACE_ENTRY(IFPMenu) COM_INTERFACE_ENTRY(IShellExtInit) COM_INTERFACE_ENTRY(IContextMenu) END_COM_MAP() // IFPMenu private: BOOL IsFPointer, DefaultItems; char Folder[MAX_PATH]; HMENU PopupMenu; public: // The Initialize method gets called for every folder, but it only succeeds // if the folder is a Folder Pointer, or if it is located inside the Start Menu STDMETHOD(Initialize)(LPCITEMIDLIST pidlFolder, LPDATAOBJECT lpdobj, HKEY hkeyProgID) { __try { ReadFolders(); IsFPointer = FALSE; DefaultItems = FALSE; char Desktop[MAX_PATH]; wsprintf(Desktop, "%s\\Desktop", StartDir); if(IsFolderPointer(Desktop)) // Checks if a Folder Pointer named Desktop exists { LPITEMIDLIST FolderID; LPMALLOC ShellMalloc; IShellLink* psl; LPPERSISTFILE ppf; char Path[MAX_PATH], Path2[MAX_PATH], Path3[MAX_PATH]; WCHAR Shortcut[MAX_PATH]; SHGetMalloc(&ShellMalloc); __try { wsprintf(Path, "%s\\Desktop\\Folder.lnk", StartDir); MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, Path, strlen(Path) + 1, Shortcut, MAX_PATH); CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (void**)&psl); psl->QueryInterface(IID_IPersistFile, (void**)&ppf); ppf->Load(Shortcut, STGM_READ); // Loads the shortcut hidden inside the folder psl->GetIDList(&FolderID); // Gets the PIDL of the target folder from the shortcut if(sizeofPIDL(FolderID) == 2) // If the PIDL doesn't contain any entries, it is the Desktop folder { if(IsIE4()) // Checks for Internet Explorer 4 { wsprintf(Path, "%s\\Refresh Start Menu.lnk", StartDir); MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, Path, strlen(Path) + 1, Shortcut, MAX_PATH); ppf->Load(Shortcut, STGM_READ); // Loads the Refresh Start Menu shortcut psl->GetPath(Path, MAX_PATH, NULL, 0); if(IsWinNT()) strcpy(Path2, SysDir); else strcpy(Path2, WinDir); wsprintf(Path3, "%s\\RunDLL32.exe", Path2); if(!strcmpi(Path, Path3)) // Checks for RunDLL32 { int icon; psl->GetIconLocation(Path, MAX_PATH, &icon); if(!strcmpi(Path, dllName) && !icon)// Checks the icon location and index { WORD Hotkey, Hotkey2; Hotkey = ((HOTKEYF_CONTROL | HOTKEYF_SHIFT) << 8) | (byte)'R'; // Set the default shortcut key to Ctrl + Shift + R psl->GetHotkey(&Hotkey2); if(Hotkey == Hotkey2) // Checks the Hotkey { psl->GetArguments(Path, MAX_PATH); wsprintf(Path2, "%s,RefreshMenu", dllName); if(!strcmpi(Path, Path2)) // Checks the arguments DefaultItems = TRUE; // If everything is correct, DefaultItems is set to TRUE } } } } else DefaultItems = TRUE; // If everything is correct, and IE4 is not installed, DefaultItems is set to TRUE } ShellMalloc->Free(FolderID); ppf->Release(); psl->Release(); } __finally { ShellMalloc->Release(); } } STGMEDIUM medium; FORMATETC fe = {CF_HDROP, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL}; if(SUCCEEDED(lpdobj->GetData(&fe, &medium))) // Requests the Data in the HDROP format { if(DragQueryFile((HDROP)medium.hGlobal, 0xFFFFFFFF, NULL, 0)) if(DragQueryFile((HDROP)medium.hGlobal, 0, Folder, MAX_PATH)) // Retrieves the name of the clicked folder if(IsFolderPointer(Folder)) // If it is a Folder Pointer { // the Initialize method succeeds IsFPointer = TRUE; ReleaseStgMedium(&medium); return NOERROR; } else if(InStartMenu(Folder)) // Or if it is a folder inside the Start Menu { // it also succeeds ReleaseStgMedium(&medium); return NOERROR; } ReleaseStgMedium(&medium); } ATLTRACENOTIMPL(_T("Initialize")); // If it is none of the above, return E_NOTIMPL } __except(1) { ATLTRACENOTIMPL(_T("Initialize")); } }; STDMETHOD(QueryContextMenu)(HMENU hmenu, UINT indexMenu, UINT idCmdFirst, UINT idCmdLast, UINT uFlags) { char* MenuText0 = "&Folder Pointers"; char* MenuText1 = "&About..."; char* MenuText2 = "&Help"; char* MenuText3 = "Add &default items"; char* MenuText4 = "&New folder pointer"; MENUITEMINFO l_menu_info; l_menu_info.cbSize = sizeof (MENUITEMINFO); l_menu_info.fMask = MIIM_TYPE | MIIM_ID | MIIM_STATE; l_menu_info.fType = MFT_STRING; l_menu_info.fState = MFS_ENABLED; l_menu_info.dwTypeData= MenuText1; l_menu_info.cch = strlen(MenuText1); l_menu_info.wID = idCmdFirst++; InsertMenuItem (PopupMenu, 0, TRUE, &l_menu_info); // Adds the "About..." item to the Folder Pointers submenu l_menu_info.dwTypeData= MenuText2; l_menu_info.cch = strlen(MenuText2); l_menu_info.wID = idCmdFirst++; InsertMenuItem(PopupMenu, 1, TRUE, &l_menu_info); // Adds the "Help" item to the Folder Pointers submenu InsertMenu(PopupMenu, 2, MF_SEPARATOR | MF_BYPOSITION, 0, NULL); l_menu_info.dwTypeData= MenuText3; l_menu_info.cch = strlen(MenuText3); l_menu_info.wID = idCmdFirst++; if(DefaultItems) // Disable the Add default items command, if they are already installed l_menu_info.fState = MFS_DISABLED; InsertMenuItem(PopupMenu, 3, TRUE, &l_menu_info); // Adds the "Add Default Items" item to the Folder Pointers submenu InsertMenu(PopupMenu, 4, MF_SEPARATOR | MF_BYPOSITION, 0, NULL); if(IsFPointer) // The following item is only enabled if it's not a Folder Pointer l_menu_info.fState = MFS_DISABLED; else l_menu_info.fState = MFS_ENABLED; l_menu_info.dwTypeData= MenuText4; l_menu_info.cch = strlen(MenuText4); l_menu_info.wID = idCmdFirst++; InsertMenuItem (PopupMenu, 5, TRUE, &l_menu_info); // Adds the "New Folder Pointer" item to the Folder Pointers submenu InsertMenu(hmenu, indexMenu++, MF_SEPARATOR | MF_BYPOSITION, 0, NULL); l_menu_info.dwTypeData= MenuText0; l_menu_info.cch = strlen(MenuText0); l_menu_info.fMask = MIIM_TYPE | MIIM_STATE | MIIM_CHECKMARKS | MIIM_SUBMENU; l_menu_info.fState = MFS_UNCHECKED; l_menu_info.hbmpChecked = NULL; l_menu_info.hbmpUnchecked = LoadBitmap(_Module.m_hInst, MAKEINTRESOURCE(IDB_BITMAP1));; l_menu_info.hSubMenu = PopupMenu; InsertMenuItem(hmenu, indexMenu++, TRUE, &l_menu_info); // Finally, the Folder Pointers submenu is inserted into the context menu return MAKE_HRESULT(SEVERITY_SUCCESS, 0, idCmdFirst); }; STDMETHOD(InvokeCommand)(LPCMINVOKECOMMANDINFO lpici) { int Command = 0; if(!HIWORD(lpici->lpVerb)) // If the command was called using MAKEINTRESOURCE Command = LOWORD(lpici->lpVerb);// there is no need for a conversion else if(!stricmp("about", lpici->lpVerb)) // Otherwise, it checks for each verb Command = 0; else if(!stricmp("help", lpici->lpVerb)) Command = 1; else if(!stricmp("icons", lpici->lpVerb)) Command = 2; else if(!stricmp("new", lpici->lpVerb)) Command = 3; if(!Command) // If the about command was selected, it displays the About dialog { CAbout * AboutDlg = new CAbout; // Creates a new instance AboutDlg->DoModal(); // Shows it modally delete AboutDlg; // Disposes of it } char Path[MAX_PATH]; switch(Command) { case 1: // If the help command was selected, it opens the help file ReadFolders(); wsprintf(Path, "%sFPointer.hlp", dllPath); ShellExecute(0, "open", Path, NULL, NULL, SW_SHOWNORMAL); break; case 2: // If the icons command was selected, the CreateIcons() function is called CreateIcons(FALSE); break; case 3: // If the new command was selected, the NewPointer() function is called wsprintf(Path, "%s\\NewPointer", Folder); typedef void (CALLBACK *RunDll32Proc)(HWND, HINSTANCE, LPSTR, int); RunDll32Proc RunProc; RunProc = (RunDll32Proc)GetProcAddress(_Module.m_hInst, "NewPointer"); RunProc(0, 0, Path, 0); } return NOERROR; }; STDMETHOD(GetCommandString)(UINT idCmd, UINT uType, UINT * pwReserved, LPSTR pszName, UINT cchMax) { if(uType == GCS_VERB) // If the request was for the language independent { // name, it returns the requested verb switch(idCmd) { case 0: strcpy(pszName, "about"); break; case 1: strcpy(pszName, "help"); break; case 2: strcpy(pszName, "icons"); break; case 3: strcpy(pszName, "new"); } } else if(uType == GCS_HELPTEXT)// Else, the string being requested is for the { // status bar in Explorer switch(idCmd) { case 0: strcpy(pszName, "Displays information about Folder Pointers"); break; case 1: strcpy(pszName, "Displays Help on using Folder Pointers"); break; case 2: strcpy(pszName, "Adds the Refresh Start Menu shortcut and Desktop Folder Pointer to the Start Menu"); break; case 3: strcpy(pszName, "Creates a Folder Pointer inside the selected folder"); } } return NOERROR; }; }; #endif //__FPMENU_H_