ReactOS  0.4.15-dev-1203-g0e5a4d5
CStartMenu.cpp File Reference
#include "shellmenu.h"
#include "CMergedFolder.h"
Include dependency graph for CStartMenu.cpp:

Go to the source code of this file.

Classes

class  CShellMenuCallback
 

Macros

#define IDM_RUN   401
 
#define IDM_LOGOFF   402
 
#define IDM_UNDOCKCOMPUTER   410
 
#define IDM_TASKBARANDSTARTMENU   413
 
#define IDM_LASTSTARTMENU_SEPARATOR   450
 
#define IDM_DOCUMENTS   501
 
#define IDM_HELPANDSUPPORT   503
 
#define IDM_PROGRAMS   504
 
#define IDM_CONTROLPANEL   505
 
#define IDM_SHUTDOWN   506
 
#define IDM_FAVORITES   507
 
#define IDM_SETTINGS   508
 
#define IDM_PRINTERSANDFAXES   510
 
#define IDM_SEARCH   520
 
#define IDM_SYNCHRONIZE   553
 
#define IDM_NETWORKCONNECTIONS   557
 
#define IDM_DISCONNECT   5000
 
#define IDM_SECURITY   5001
 

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (CStartMenu)
 
HRESULT BindToDesktop (LPCITEMIDLIST pidl, IShellFolder **ppsfResult)
 
static HRESULT GetMergedFolder (int folder1, int folder2, IShellFolder **ppsfStartMenu)
 
static HRESULT GetStartMenuFolder (IShellFolder **ppsfStartMenu)
 
static HRESULT GetProgramsFolder (IShellFolder **ppsfStartMenu)
 
HRESULT WINAPI RSHELL_CStartMenu_CreateInstance (REFIID riid, void **ppv)
 

Macro Definition Documentation

◆ IDM_CONTROLPANEL

#define IDM_CONTROLPANEL   505

Definition at line 40 of file CStartMenu.cpp.

◆ IDM_DISCONNECT

#define IDM_DISCONNECT   5000

Definition at line 48 of file CStartMenu.cpp.

◆ IDM_DOCUMENTS

#define IDM_DOCUMENTS   501

Definition at line 37 of file CStartMenu.cpp.

◆ IDM_FAVORITES

#define IDM_FAVORITES   507

Definition at line 42 of file CStartMenu.cpp.

◆ IDM_HELPANDSUPPORT

#define IDM_HELPANDSUPPORT   503

Definition at line 38 of file CStartMenu.cpp.

◆ IDM_LASTSTARTMENU_SEPARATOR

#define IDM_LASTSTARTMENU_SEPARATOR   450

Definition at line 36 of file CStartMenu.cpp.

◆ IDM_LOGOFF

#define IDM_LOGOFF   402

Definition at line 33 of file CStartMenu.cpp.

◆ IDM_NETWORKCONNECTIONS

#define IDM_NETWORKCONNECTIONS   557

Definition at line 47 of file CStartMenu.cpp.

◆ IDM_PRINTERSANDFAXES

#define IDM_PRINTERSANDFAXES   510

Definition at line 44 of file CStartMenu.cpp.

◆ IDM_PROGRAMS

#define IDM_PROGRAMS   504

Definition at line 39 of file CStartMenu.cpp.

◆ IDM_RUN

#define IDM_RUN   401

Definition at line 32 of file CStartMenu.cpp.

◆ IDM_SEARCH

#define IDM_SEARCH   520

Definition at line 45 of file CStartMenu.cpp.

◆ IDM_SECURITY

#define IDM_SECURITY   5001

Definition at line 49 of file CStartMenu.cpp.

◆ IDM_SETTINGS

#define IDM_SETTINGS   508

Definition at line 43 of file CStartMenu.cpp.

◆ IDM_SHUTDOWN

#define IDM_SHUTDOWN   506

Definition at line 41 of file CStartMenu.cpp.

◆ IDM_SYNCHRONIZE

#define IDM_SYNCHRONIZE   553

Definition at line 46 of file CStartMenu.cpp.

◆ IDM_TASKBARANDSTARTMENU

#define IDM_TASKBARANDSTARTMENU   413

Definition at line 35 of file CStartMenu.cpp.

◆ IDM_UNDOCKCOMPUTER

#define IDM_UNDOCKCOMPUTER   410

Definition at line 34 of file CStartMenu.cpp.

Function Documentation

◆ BindToDesktop()

HRESULT BindToDesktop ( LPCITEMIDLIST  pidl,
IShellFolder **  ppsfResult 
)

Definition at line 385 of file CStartMenu.cpp.

386 {
387  HRESULT hr;
388  CComPtr<IShellFolder> psfDesktop;
389 
390  *ppsfResult = NULL;
391 
392  hr = SHGetDesktopFolder(&psfDesktop);
393  if (FAILED(hr))
394  return hr;
395 
396  hr = psfDesktop->BindToObject(pidl, NULL, IID_PPV_ARG(IShellFolder, ppsfResult));
397 
398  return hr;
399 }
HRESULT hr
Definition: shlfolder.c:183
#define IID_PPV_ARG(Itype, ppType)
smooth NULL
Definition: ftsmooth.c:416
HRESULT WINAPI SHGetDesktopFolder(IShellFolder **psf)
LONG HRESULT
Definition: typedefs.h:79

Referenced by GetMergedFolder().

◆ GetMergedFolder()

static HRESULT GetMergedFolder ( int  folder1,
int  folder2,
IShellFolder **  ppsfStartMenu 
)
static

Definition at line 401 of file CStartMenu.cpp.

402 {
403  HRESULT hr;
404  LPITEMIDLIST pidlUserStartMenu;
405  LPITEMIDLIST pidlCommonStartMenu;
406  CComPtr<IShellFolder> psfUserStartMenu;
407  CComPtr<IShellFolder> psfCommonStartMenu;
408  CComPtr<IAugmentedShellFolder> pasf;
409 
410  *ppsfStartMenu = NULL;
411 
412  hr = SHGetSpecialFolderLocation(NULL, folder1, &pidlUserStartMenu);
413  if (FAILED(hr))
414  {
415  WARN("Failed to get the USER start menu folder. Trying to run with just the COMMON one.\n");
416 
417  hr = SHGetSpecialFolderLocation(NULL, folder2, &pidlCommonStartMenu);
418  if (FAILED_UNEXPECTEDLY(hr))
419  return hr;
420 
421  TRACE("COMMON start menu obtained.\n");
422  hr = BindToDesktop(pidlCommonStartMenu, ppsfStartMenu);
423  ILFree(pidlCommonStartMenu);
424  return hr;
425  }
426 #if MERGE_FOLDERS
427  hr = SHGetSpecialFolderLocation(NULL, folder2, &pidlCommonStartMenu);
428  if (FAILED_UNEXPECTEDLY(hr))
429 #else
430  else
431 #endif
432  {
433  WARN("Failed to get the COMMON start menu folder. Will use only the USER contents.\n");
434  hr = BindToDesktop(pidlUserStartMenu, ppsfStartMenu);
435  ILFree(pidlUserStartMenu);
436  return hr;
437  }
438 
439  TRACE("Both COMMON and USER statr menu folders obtained, merging them...\n");
440 
441  hr = BindToDesktop(pidlUserStartMenu, &psfUserStartMenu);
442  if (FAILED_UNEXPECTEDLY(hr))
443  return hr;
444 
445  hr = BindToDesktop(pidlCommonStartMenu, &psfCommonStartMenu);
446  if (FAILED_UNEXPECTEDLY(hr))
447  return hr;
448 
449  hr = CMergedFolder_CreateInstance(IID_PPV_ARG(IAugmentedShellFolder, &pasf));
450  if (FAILED_UNEXPECTEDLY(hr))
451  {
452  *ppsfStartMenu = psfUserStartMenu.Detach();
453  ILFree(pidlCommonStartMenu);
454  ILFree(pidlUserStartMenu);
455  return hr;
456  }
457 
458  hr = pasf->AddNameSpace(NULL, psfUserStartMenu, pidlUserStartMenu, 0xFF00);
459  if (FAILED_UNEXPECTEDLY(hr))
460  return hr;
461 
462  hr = pasf->AddNameSpace(NULL, psfCommonStartMenu, pidlCommonStartMenu, 0);
463  if (FAILED_UNEXPECTEDLY(hr))
464  return hr;
465 
466  hr = pasf->QueryInterface(IID_PPV_ARG(IShellFolder, ppsfStartMenu));
467  pasf.Release();
468 
469  ILFree(pidlCommonStartMenu);
470  ILFree(pidlUserStartMenu);
471 
472  return hr;
473 }
void WINAPI ILFree(LPITEMIDLIST pidl)
Definition: pidl.c:925
HRESULT hr
Definition: shlfolder.c:183
#define WARN(fmt,...)
Definition: debug.h:112
#define IID_PPV_ARG(Itype, ppType)
smooth NULL
Definition: ftsmooth.c:416
#define CMergedFolder_CreateInstance
Definition: shellmenu.h:93
#define TRACE(s)
Definition: solgame.cpp:4
HRESULT WINAPI SHGetSpecialFolderLocation(HWND hwndOwner, INT nFolder, LPITEMIDLIST *ppidl)
Definition: shellpath.c:2830
LONG HRESULT
Definition: typedefs.h:79
#define FAILED_UNEXPECTEDLY(hr)
Definition: shellutils.h:71
HRESULT BindToDesktop(LPCITEMIDLIST pidl, IShellFolder **ppsfResult)
Definition: CStartMenu.cpp:385
ITEMIDLIST UNALIGNED * LPITEMIDLIST
Definition: shtypes.idl:41

Referenced by GetProgramsFolder(), and GetStartMenuFolder().

◆ GetProgramsFolder()

static HRESULT GetProgramsFolder ( IShellFolder **  ppsfStartMenu)
static

Definition at line 480 of file CStartMenu.cpp.

481 {
482  return GetMergedFolder(CSIDL_PROGRAMS, CSIDL_COMMON_PROGRAMS, ppsfStartMenu);
483 }
#define CSIDL_COMMON_PROGRAMS
Definition: shlobj.h:2034
static HRESULT GetMergedFolder(int folder1, int folder2, IShellFolder **ppsfStartMenu)
Definition: CStartMenu.cpp:401
#define CSIDL_PROGRAMS
Definition: shlobj.h:2014

Referenced by RSHELL_CStartMenu_CreateInstance().

◆ GetStartMenuFolder()

static HRESULT GetStartMenuFolder ( IShellFolder **  ppsfStartMenu)
static

Definition at line 475 of file CStartMenu.cpp.

476 {
478 }
#define CSIDL_COMMON_STARTMENU
Definition: shlobj.h:2033
static HRESULT GetMergedFolder(int folder1, int folder2, IShellFolder **ppsfStartMenu)
Definition: CStartMenu.cpp:401
#define CSIDL_STARTMENU
Definition: shlobj.h:2023

Referenced by RSHELL_CStartMenu_CreateInstance().

◆ RSHELL_CStartMenu_CreateInstance()

HRESULT WINAPI RSHELL_CStartMenu_CreateInstance ( REFIID  riid,
void **  ppv 
)

Definition at line 487 of file CStartMenu.cpp.

488 {
489  CComPtr<IShellMenu> pShellMenu;
490  CComPtr<IBandSite> pBandSite;
491  CComPtr<IDeskBar> pDeskBar;
492 
493  HRESULT hr;
494  IShellFolder * psf;
495 
496  LPITEMIDLIST pidlProgramsAbsolute;
497  LPITEMIDLIST pidlPrograms;
498  CComPtr<IShellFolder> psfPrograms;
499 
501  if (FAILED_UNEXPECTEDLY(hr))
502  return hr;
503 
505  if (FAILED_UNEXPECTEDLY(hr))
506  return hr;
507 
509  if (FAILED_UNEXPECTEDLY(hr))
510  return hr;
511 
512  CComObject<CShellMenuCallback> *pCallback;
513  hr = CComObject<CShellMenuCallback>::CreateInstance(&pCallback);
514  if (FAILED_UNEXPECTEDLY(hr))
515  return hr;
516 
517  pCallback->AddRef(); // CreateInstance returns object with 0 ref count */
518  pCallback->Initialize(pShellMenu, pBandSite, pDeskBar);
519 
520  hr = pShellMenu->Initialize(pCallback, (UINT) -1, 0, SMINIT_TOPLEVEL | SMINIT_VERTICAL);
521  if (FAILED_UNEXPECTEDLY(hr))
522  return hr;
523 
524  hr = GetStartMenuFolder(&psf);
525  if (FAILED_UNEXPECTEDLY(hr))
526  return hr;
527 
528  /* psf is a merged folder, so now we want to get the pidl of the programs item from the merged folder */
529  {
530  hr = SHGetSpecialFolderLocation(NULL, CSIDL_PROGRAMS, &pidlProgramsAbsolute);
531  if (FAILED_UNEXPECTEDLY(hr))
532  {
533  WARN("USER Programs folder not found.");
534  hr = SHGetSpecialFolderLocation(NULL, CSIDL_COMMON_PROGRAMS, &pidlProgramsAbsolute);
535  if (FAILED_UNEXPECTEDLY(hr))
536  return hr;
537  }
538 
539  LPCITEMIDLIST pcidlPrograms;
540  CComPtr<IShellFolder> psfParent;
541  STRRET str;
542  TCHAR szDisplayName[MAX_PATH];
543 
544  hr = SHBindToParent(pidlProgramsAbsolute, IID_PPV_ARG(IShellFolder, &psfParent), &pcidlPrograms);
545  if (FAILED_UNEXPECTEDLY(hr))
546  return hr;
547 
548  hr = psfParent->GetDisplayNameOf(pcidlPrograms, SHGDN_FORPARSING | SHGDN_INFOLDER, &str);
549  if (FAILED_UNEXPECTEDLY(hr))
550  return hr;
551 
552  StrRetToBuf(&str, pcidlPrograms, szDisplayName, _countof(szDisplayName));
553  ILFree(pidlProgramsAbsolute);
554 
555  /* We got the display name from the fs folder and we parse it with the merged folder here */
556  hr = psf->ParseDisplayName(NULL, NULL, szDisplayName, NULL, &pidlPrograms, NULL);
557  if (FAILED_UNEXPECTEDLY(hr))
558  return hr;
559  }
560 
561  hr = GetProgramsFolder(&psfPrograms);
562  if (FAILED_UNEXPECTEDLY(hr))
563  return hr;
564 
565  hr = pCallback->_SetProgramsFolder(psfPrograms, pidlPrograms);
566  if (FAILED_UNEXPECTEDLY(hr))
567  return hr;
568 
569  hr = pShellMenu->SetShellFolder(psf, NULL, NULL, SMSET_TOP);
570  if (FAILED_UNEXPECTEDLY(hr))
571  return hr;
572 
573  hr = pDeskBar->SetClient(pBandSite);
574  if (FAILED_UNEXPECTEDLY(hr))
575  return hr;
576 
577  hr = pBandSite->AddBand(pShellMenu);
578  if (FAILED_UNEXPECTEDLY(hr))
579  return hr;
580 
581  return pDeskBar->QueryInterface(riid, ppv);
582 }
void WINAPI ILFree(LPITEMIDLIST pidl)
Definition: pidl.c:925
HRESULT hr
Definition: shlfolder.c:183
HRESULT ParseDisplayName([in] HWND hwndOwner, [in] LPBC pbcReserved, [in, string] LPOLESTR lpszDisplayName, [out] ULONG *pchEaten, [out] PIDLIST_RELATIVE *ppidl, [in, out, unique] ULONG *pdwAttributes)
REFIID riid
Definition: precomp.h:44
static HRESULT GetStartMenuFolder(IShellFolder **ppsfStartMenu)
Definition: CStartMenu.cpp:475
#define WARN(fmt,...)
Definition: debug.h:112
const ITEMIDLIST UNALIGNED * LPCITEMIDLIST
Definition: shtypes.idl:42
REFIID LPVOID * ppv
Definition: atlbase.h:39
#define CMenuDeskBar_CreateInstance
Definition: shellmenu.h:75
#define IID_PPV_ARG(Itype, ppType)
#define CSIDL_COMMON_PROGRAMS
Definition: shlobj.h:2034
static HRESULT GetProgramsFolder(IShellFolder **ppsfStartMenu)
Definition: CStartMenu.cpp:480
#define StrRetToBuf
Definition: shlwapi.h:1769
const WCHAR * str
smooth NULL
Definition: ftsmooth.c:416
#define CMenuSite_CreateInstance
Definition: shellmenu.h:87
char TCHAR
Definition: xmlstorage.h:189
HRESULT WINAPI SHGetSpecialFolderLocation(HWND hwndOwner, INT nFolder, LPITEMIDLIST *ppidl)
Definition: shellpath.c:2830
LONG HRESULT
Definition: typedefs.h:79
#define _countof(array)
Definition: sndvol32.h:68
#define FAILED_UNEXPECTEDLY(hr)
Definition: shellutils.h:71
#define MAX_PATH
Definition: compat.h:34
HRESULT WINAPI SHBindToParent(LPCITEMIDLIST pidl, REFIID riid, LPVOID *ppv, LPCITEMIDLIST *ppidlLast)
Definition: pidl.c:1337
#define CMenuBand_CreateInstance
Definition: shellmenu.h:81
unsigned int UINT
Definition: ndis.h:50
#define CSIDL_PROGRAMS
Definition: shlobj.h:2014
ITEMIDLIST UNALIGNED * LPITEMIDLIST
Definition: shtypes.idl:41

Referenced by CRShellClassFactory::CreateInstance(), and CStartMenuDummy::_CreatorClass::CreateInstance().

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( CStartMenu  )