WinCE 开始菜单StartMenu_Create()函数代码分析

//=====================================================================================================
//AUTHOR:
//  norains
//DATE:
//  Saturday 4-Mar-2006
//=====================================================================================================
windows ce 的开始菜单的子项可以通过更改注册表来更改,但只能对有限的子项进行更改.如果想要对开始菜单进行更为详尽的设置,必须要对代码下手.开始菜单位于"$(_WINCEROOT)/PUBLIC/SHELL/OAK/HPC/EXPLORER/TASKBAR/stmenu.cpp.由于代码众多,再此只对菜单的创建函数StartMenu_Create()做一个注释.下面这个例子的菜单只有"设置"和"程序"两个子项
HMENU StartMenu_Create(VOID)
/*---------------------------------------------------------------------------*/
 *
/*---------------------------------------------------------------------------*/
{
 BOOL fOK= FALSE;
 HMENU hmenu;
 BITMAP bm;
 HDC hdc;
 int i;
 
 //创建"设置"菜单
 HMENU hmenuSettings = StartMenu_CreateSettingsMenu();
 if (!hmenuSettings) {
  return NULL;
 }

 //如果无法创建下级弹出菜单,则跳出此函数
    hmenu = CreatePopupMenu();
 if (!hmenu) {
  FileMenu_Destroy(hmenuSettings);
  return 0;
 }
  

 // 开始菜单
 for (i=0; i<START_NUM_STATIC_ITEMS; i++) {

  //如果不存在peghelp.exe文件,将去掉"Help"子项
  if((IDM_START_HELP == stmenuData[i].idMenuCmd) && (GetFileAttributes(L"//Windows//peghelp.exe") == -1))
   continue;
 
  //如果注册表设置不采用挂起,则将"挂起"子项去掉(是否采用分隔符也可以在注册表设定)
  if ((IDM_START_SUSPEND == stmenuData[i].idMenuCmd) || (0 == stmenuData[i].idMenuCmd))
        {
            DWORD dwLen;
            DWORD dwValue;
            HKEY  hkey;
           
            dwValue = TRUE; // 设置默认值
            dwLen = sizeof(dwValue);
            if( RegOpenKeyEx( HKEY_LOCAL_MACHINE, L"Explorer", 0, KEY_READ, &hkey ) == ERROR_SUCCESS )
            {
                RegQueryValueEx(hkey, L"Suspend", NULL, NULL, (LPBYTE)&dwValue, &dwLen );
                RegCloseKey( hkey );
            }
            if (FALSE == dwValue) {
                continue;
            }
  }

  if (0 == idFirstMenu) {
   idFirstMenu = stmenuData[i].idMenuCmd;
  }
  idLastMenu = stmenuData[i].idMenuCmd;
 
  if (stmenuData[i].idMenuIcon) {
   if (stmenuData[i].idMenuCmd == IDM_START_SETTINGS){
    // 插入"设置"菜单
    fOK = AppendMenu(hmenu,  MF_OWNERDRAW | MF_POPUP,
         (UINT)hmenuSettings, (LPCTSTR)&stmenuData[i]);
   }
   
   //*--------------------------------------------------------------------------------------------------------------
   //此段代码管理"运行","挂起"   
   else if (!stmenuData[i].nSpecialFolder ||
        (stmenuData[i].nSpecialFolder == STATIC_ITEM)) {
    // insert standard menu item
    //if(stmenuData[i].idMenuCmd!=IDM_START_RUN ||stmenuData[i].idMenuCmd!=IDM_START_SUSPEND )  //my adding:不添加"运行","挂起"选项
    //ori: {fOK = AppendMenu(hmenu, MF_OWNERDRAW, stmenuData[i].idMenuCmd,(LPCTSTR) &stmenuData[i]);}
   }
   //--------------------------------------------------------------------------------------------------------------*/
   
   
   //*----------------------------------------------------------------------------------------------------- 
   //此段代码管理:"程序","收藏","文档";
   
   //++++++++++++++++++++++++++
   //:my adding
   //不添加"收藏","文档"选项
   else if(stmenuData[i].idMenuCmd == IDM_START_FAVORITES ||stmenuData[i].idMenuCmd == IDM_START_DOCUMENTS)
    {;}
   //++++++++++++++++++++++++++
   
   else{
    // insert cascade item
    // my explanation:cascade menu指的是带有下级弹出菜单的,standard menu是单独的,没有下级弹出菜单的    
    HMENU hmenuSubMenu;
    LPITEMIDLIST pidl;

    if (SUCCEEDED(SHGetSpecialFolderLocation(NULL, stmenuData[i].nSpecialFolder, &pidl))) {
        hmenuSubMenu = FileMenu_CreatePopupWithPIDL(pidl);//创建弹出的下级菜单
        fOK = AppendMenu(hmenu,  MF_OWNERDRAW | MF_POPUP,
             (UINT)hmenuSubMenu,
             (LPCTSTR)&stmenuData[i]);
                }            
   }
   //-------------------------------------------------------------------------------------------------------*/
   
  }else{
    //fOK = AppendMenu(hmenu,MF_SEPARATOR, 0,0); //创建一个菜单分割符
  }
  ASSERT(fOK);

 }

 if (g_fUseSTBitmap)
 {
  hdc = GetDC(NULL);
  if (GetDeviceCaps(hdc, BITSPIXEL) == 2) {
   hbmSTPegasus = LoadBitmap(g_hInstance, MAKEINTRESOURCE(IDB_STPEGASUSG));
  }else{
   hbmSTPegasus = LoadBitmap(g_hInstance, MAKEINTRESOURCE(IDB_STPEGASUS));
  }
  ReleaseDC(NULL, hdc);

  GetObject(hbmSTPegasus, sizeof(BITMAP), &bm);

  sizeSTPegasus.cx = bm.bmWidth;
  sizeSTPegasus.cy = bm.bmHeight;
 }
 else
 {
  hbmSTPegasus = NULL;
  sizeSTPegasus.cx = 0;
  sizeSTPegasus.cy = 0;
 }

 return hmenu;
 
} /* StartMenu_Create() */

posted @ 2006-03-04 10:14  我的一天  阅读(302)  评论(0编辑  收藏  举报