ReactOS  0.4.14-dev-599-g2d4d3f5
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 316 of file CStartMenu.cpp.

317 {
318  HRESULT hr;
319  CComPtr<IShellFolder> psfDesktop;
320 
321  *ppsfResult = NULL;
322 
323  hr = SHGetDesktopFolder(&psfDesktop);
324  if (FAILED(hr))
325  return hr;
326 
327  hr = psfDesktop->BindToObject(pidl, NULL, IID_PPV_ARG(IShellFolder, ppsfResult));
328 
329  return hr;
330 }
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:77

Referenced by GetMergedFolder().

◆ GetMergedFolder()

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

Definition at line 332 of file CStartMenu.cpp.

333 {
334  HRESULT hr;
335  LPITEMIDLIST pidlUserStartMenu;
336  LPITEMIDLIST pidlCommonStartMenu;
337  CComPtr<IShellFolder> psfUserStartMenu;
338  CComPtr<IShellFolder> psfCommonStartMenu;
339  CComPtr<IAugmentedShellFolder> pasf;
340 
341  *ppsfStartMenu = NULL;
342 
343  hr = SHGetSpecialFolderLocation(NULL, folder1, &pidlUserStartMenu);
344  if (FAILED(hr))
345  {
346  WARN("Failed to get the USER start menu folder. Trying to run with just the COMMON one.\n");
347 
348  hr = SHGetSpecialFolderLocation(NULL, folder2, &pidlCommonStartMenu);
349  if (FAILED_UNEXPECTEDLY(hr))
350  return hr;
351 
352  TRACE("COMMON start menu obtained.\n");
353  hr = BindToDesktop(pidlCommonStartMenu, ppsfStartMenu);
354  ILFree(pidlCommonStartMenu);
355  return hr;
356  }
357 #if MERGE_FOLDERS
358  hr = SHGetSpecialFolderLocation(NULL, folder2, &pidlCommonStartMenu);
359  if (FAILED_UNEXPECTEDLY(hr))
360 #else
361  else
362 #endif
363  {
364  WARN("Failed to get the COMMON start menu folder. Will use only the USER contents.\n");
365  hr = BindToDesktop(pidlUserStartMenu, ppsfStartMenu);
366  ILFree(pidlUserStartMenu);
367  return hr;
368  }
369 
370  TRACE("Both COMMON and USER statr menu folders obtained, merging them...\n");
371 
372  hr = BindToDesktop(pidlUserStartMenu, &psfUserStartMenu);
373  if (FAILED_UNEXPECTEDLY(hr))
374  return hr;
375 
376  hr = BindToDesktop(pidlCommonStartMenu, &psfCommonStartMenu);
377  if (FAILED_UNEXPECTEDLY(hr))
378  return hr;
379 
380  hr = CMergedFolder_CreateInstance(IID_PPV_ARG(IAugmentedShellFolder, &pasf));
381  if (FAILED_UNEXPECTEDLY(hr))
382  {
383  *ppsfStartMenu = psfUserStartMenu.Detach();
384  ILFree(pidlCommonStartMenu);
385  ILFree(pidlUserStartMenu);
386  return hr;
387  }
388 
389  hr = pasf->AddNameSpace(NULL, psfUserStartMenu, pidlUserStartMenu, 0xFF00);
390  if (FAILED_UNEXPECTEDLY(hr))
391  return hr;
392 
393  hr = pasf->AddNameSpace(NULL, psfCommonStartMenu, pidlCommonStartMenu, 0);
394  if (FAILED_UNEXPECTEDLY(hr))
395  return hr;
396 
397  hr = pasf->QueryInterface(IID_PPV_ARG(IShellFolder, ppsfStartMenu));
398  pasf.Release();
399 
400  ILFree(pidlCommonStartMenu);
401  ILFree(pidlUserStartMenu);
402 
403  return hr;
404 }
void WINAPI ILFree(LPITEMIDLIST pidl)
Definition: pidl.c:925
HRESULT hr
Definition: shlfolder.c:183
#define WARN(fmt,...)
Definition: debug.h:111
#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:2695
LONG HRESULT
Definition: typedefs.h:77
#define FAILED_UNEXPECTEDLY(hr)
Definition: shellutils.h:71
HRESULT BindToDesktop(LPCITEMIDLIST pidl, IShellFolder **ppsfResult)
Definition: CStartMenu.cpp:316
ITEMIDLIST UNALIGNED * LPITEMIDLIST
Definition: shtypes.idl:41

Referenced by GetProgramsFolder(), and GetStartMenuFolder().

◆ GetProgramsFolder()

static HRESULT GetProgramsFolder ( IShellFolder **  ppsfStartMenu)
static

Definition at line 411 of file CStartMenu.cpp.

412 {
413  return GetMergedFolder(CSIDL_PROGRAMS, CSIDL_COMMON_PROGRAMS, ppsfStartMenu);
414 }
#define CSIDL_COMMON_PROGRAMS
Definition: shlobj.h:2025
static HRESULT GetMergedFolder(int folder1, int folder2, IShellFolder **ppsfStartMenu)
Definition: CStartMenu.cpp:332
#define CSIDL_PROGRAMS
Definition: shlobj.h:2005

Referenced by RSHELL_CStartMenu_CreateInstance().

◆ GetStartMenuFolder()

static HRESULT GetStartMenuFolder ( IShellFolder **  ppsfStartMenu)
static

Definition at line 406 of file CStartMenu.cpp.

407 {
409 }
#define CSIDL_COMMON_STARTMENU
Definition: shlobj.h:2024
static HRESULT GetMergedFolder(int folder1, int folder2, IShellFolder **ppsfStartMenu)
Definition: CStartMenu.cpp:332
#define CSIDL_STARTMENU
Definition: shlobj.h:2014

Referenced by RSHELL_CStartMenu_CreateInstance().

◆ RSHELL_CStartMenu_CreateInstance()

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

Definition at line 418 of file CStartMenu.cpp.

419 {
420  CComPtr<IShellMenu> pShellMenu;
421  CComPtr<IBandSite> pBandSite;
422  CComPtr<IDeskBar> pDeskBar;
423 
424  HRESULT hr;
425  IShellFolder * psf;
426 
427  LPITEMIDLIST pidlProgramsAbsolute;
428  LPITEMIDLIST pidlPrograms;
429  CComPtr<IShellFolder> psfPrograms;
430 
432  if (FAILED_UNEXPECTEDLY(hr))
433  return hr;
434 
436  if (FAILED_UNEXPECTEDLY(hr))
437  return hr;
438 
440  if (FAILED_UNEXPECTEDLY(hr))
441  return hr;
442 
443  CComObject<CShellMenuCallback> *pCallback;
444  hr = CComObject<CShellMenuCallback>::CreateInstance(&pCallback);
445  if (FAILED_UNEXPECTEDLY(hr))
446  return hr;
447 
448  pCallback->AddRef(); // CreateInstance returns object with 0 ref count */
449  pCallback->Initialize(pShellMenu, pBandSite, pDeskBar);
450 
451  pShellMenu->Initialize(pCallback, (UINT) -1, 0, SMINIT_TOPLEVEL | SMINIT_VERTICAL);
452  if (FAILED_UNEXPECTEDLY(hr))
453  return hr;
454 
455  hr = GetStartMenuFolder(&psf);
456  if (FAILED_UNEXPECTEDLY(hr))
457  return hr;
458 
459  /* psf is a merged folder, so now we want to get the pidl of the programs item from the merged folder */
460  {
461  hr = SHGetSpecialFolderLocation(NULL, CSIDL_PROGRAMS, &pidlProgramsAbsolute);
462  if (FAILED_UNEXPECTEDLY(hr))
463  {
464  WARN("USER Programs folder not found.");
465  hr = SHGetSpecialFolderLocation(NULL, CSIDL_COMMON_PROGRAMS, &pidlProgramsAbsolute);
466  if (FAILED_UNEXPECTEDLY(hr))
467  return hr;
468  }
469 
470  LPCITEMIDLIST pcidlPrograms;
471  CComPtr<IShellFolder> psfParent;
472  STRRET str;
473  TCHAR szDisplayName[MAX_PATH];
474 
475  hr = SHBindToParent(pidlProgramsAbsolute, IID_PPV_ARG(IShellFolder, &psfParent), &pcidlPrograms);
476  if (FAILED_UNEXPECTEDLY(hr))
477  return hr;
478 
479  hr = psfParent->GetDisplayNameOf(pcidlPrograms, SHGDN_FORPARSING | SHGDN_INFOLDER, &str);
480  if (FAILED_UNEXPECTEDLY(hr))
481  return hr;
482 
483  StrRetToBuf(&str, pcidlPrograms, szDisplayName, _countof(szDisplayName));
484  ILFree(pidlProgramsAbsolute);
485 
486  /* We got the display name from the fs folder and we parse it with the merged folder here */
487  hr = psf->ParseDisplayName(NULL, NULL, szDisplayName, NULL, &pidlPrograms, NULL);
488  if (FAILED_UNEXPECTEDLY(hr))
489  return hr;
490  }
491 
492  hr = GetProgramsFolder(&psfPrograms);
493  if (FAILED_UNEXPECTEDLY(hr))
494  return hr;
495 
496  hr = pCallback->_SetProgramsFolder(psfPrograms, pidlPrograms);
497  if (FAILED_UNEXPECTEDLY(hr))
498  return hr;
499 
500  hr = pShellMenu->SetShellFolder(psf, NULL, NULL, 0);
501  if (FAILED_UNEXPECTEDLY(hr))
502  return hr;
503 
504  hr = pDeskBar->SetClient(pBandSite);
505  if (FAILED_UNEXPECTEDLY(hr))
506  return hr;
507 
508  hr = pBandSite->AddBand(pShellMenu);
509  if (FAILED_UNEXPECTEDLY(hr))
510  return hr;
511 
512  return pDeskBar->QueryInterface(riid, ppv);
513 }
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:406
#define _countof(array)
Definition: fontsub.cpp:30
#define WARN(fmt,...)
Definition: debug.h:111
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:2025
static HRESULT GetProgramsFolder(IShellFolder **ppsfStartMenu)
Definition: CStartMenu.cpp:411
#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:2695
LONG HRESULT
Definition: typedefs.h:77
#define FAILED_UNEXPECTEDLY(hr)
Definition: shellutils.h:71
#define MAX_PATH
Definition: compat.h:26
HRESULT WINAPI SHBindToParent(LPCITEMIDLIST pidl, REFIID riid, LPVOID *ppv, LPCITEMIDLIST *ppidlLast)
Definition: pidl.c:1323
#define CMenuBand_CreateInstance
Definition: shellmenu.h:81
unsigned int UINT
Definition: ndis.h:50
#define CSIDL_PROGRAMS
Definition: shlobj.h:2005
ITEMIDLIST UNALIGNED * LPITEMIDLIST
Definition: shtypes.idl:41

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

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( CStartMenu  )