mru.cpp

来自「quake3工具源码。包括生成bsp文件」· C++ 代码 · 共 651 行 · 第 1/2 页

CPP
651
字号
             lpMruMenu->lpMRU + (lpMruMenu->wMaxSizeLruItem * (UINT)(i+1)));
  return TRUE;
}
                           
//*************************************************************
//
//  PlaceMenuMRUItem()
//
//  Purpose:
//              Add MRU at the end of a menu
//
//  Parameters:
//      LPMRUMENU lpMruMenu -      pointer on MRUMENU
//      HMENU hMenu -              Handle of menu where MRU must be added
//      UINT uiItem -              Item of menu entry where MRU must be added
//
//  Return: void
//
//
//  Comments:
//      Used MRU is modified, for refresh the File menu
//
//  History:    Date       Author       Comment
//              09/24/94   G. Vollant   Created
//
//*************************************************************
void PlaceMenuMRUItem(LPMRUMENU lpMruMenu,HMENU hMenu,UINT uiItem)
{
int  i;   
WORD wNbShow;
  if (hMenu == NULL) 
    return;
  // remove old MRU in menu
  for (i=0;i<=(int)(lpMruMenu->wNbLruMenu);i++)
    RemoveMenu(hMenu,i+lpMruMenu->wIdMru,MF_BYCOMMAND);

  if (lpMruMenu->wNbItemFill == 0) 
    return;

  // If they are item, insert a separator before the files
  InsertMenu(hMenu,uiItem,MF_SEPARATOR,lpMruMenu->wIdMru,NULL);

  wNbShow = min(lpMruMenu->wNbItemFill,lpMruMenu->wNbLruShow);
  for (i=(int)wNbShow-1;i>=0;i--)
  {
  LPSTR lpTxt;
    if (lpTxt = (LPSTR)GlobalAllocPtr(GHND,lpMruMenu->wMaxSizeLruItem + 20))
      {
        wsprintf(lpTxt,"&%lu %s",
                 (DWORD)(i+1),lpMruMenu->lpMRU + (lpMruMenu->wMaxSizeLruItem*(UINT)i));
        InsertMenu(hMenu,(((WORD)i)!=(wNbShow-1)) ? (lpMruMenu->wIdMru+i+2) : lpMruMenu->wIdMru,
                   MF_STRING,lpMruMenu->wIdMru+i+1,lpTxt);   
        GlobalFreePtr(lpTxt);
      }
  }

}

///////////////////////////////////////////



//*************************************************************
//
//  SaveMruInIni()
//
//  Purpose:
//              Save MRU in a private .INI
//
//  Parameters:
//      LPMRUMENU lpMruMenu -      pointer on MRUMENU
//      LPSTR lpszSection  -       Points to a null-terminated string containing
//                                      the name of the section 
//      LPSTR lpszFile -           Points to a null-terminated string that names 
//                                      the initialization file. 
//
//  Return: (BOOL)
//      TRUE  - Function run successfully
//      FALSE - Function don't run successfully
//
//
//  Comments:
//      See WritePrivateProfileString API for more info on lpszSection and lpszFile
//
//  History:    Date       Author       Comment
//              09/24/94   G. Vollant   Created
//
//*************************************************************
BOOL SaveMruInIni(LPMRUMENU lpMruMenu,LPSTR lpszSection,LPSTR lpszFile)
{
LPSTR lpTxt;
WORD i;

  lpTxt = (LPSTR)GlobalAllocPtr(GHND,lpMruMenu->wMaxSizeLruItem + 20);
  if (lpTxt == NULL) 
    return FALSE;

  for (i=0;i<lpMruMenu->wNbLruMenu;i++)
    {
    char szEntry[16];
      wsprintf(szEntry,"File%lu",(DWORD)i+1);
      if (!GetMenuItem(lpMruMenu,i,FALSE,lpTxt,lpMruMenu->wMaxSizeLruItem + 10))
        *lpTxt = '\0';
      WritePrivateProfileString(lpszSection,szEntry,lpTxt,lpszFile);
    }
  GlobalFreePtr(lpTxt);
  WritePrivateProfileString(NULL,NULL,NULL,lpszFile); // flush cache 
  return TRUE;
}


//*************************************************************
//
//  LoadMruInIni()
//
//  Purpose:
//              Load MRU from a private .INI
//
//  Parameters:
//      LPMRUMENU lpMruMenu -      pointer on MRUMENU
//      LPSTR lpszSection  -       Points to a null-terminated string containing
//                                      the name of the section 
//      LPSTR lpszFile -           Points to a null-terminated string that names 
//                                      the initialization file. 
//
//  Return: (BOOL)
//      TRUE  - Function run successfully
//      FALSE - Function don't run successfully
//
//
//  Comments:
//      See GetPrivateProfileString API for more info on lpszSection and lpszFile
//
//  History:    Date       Author       Comment
//              09/24/94   G. Vollant   Created
//
//*************************************************************
BOOL LoadMruInIni(LPMRUMENU lpMruMenu,LPSTR lpszSection,LPSTR lpszFile)
{
LPSTR lpTxt;
WORD i;
  lpTxt = (LPSTR)GlobalAllocPtr(GHND,lpMruMenu->wMaxSizeLruItem + 20);
  if (lpTxt == NULL) 
    return FALSE;

  for (i=0;i<lpMruMenu->wNbLruMenu;i++)
    {
    char szEntry[16];
      
      wsprintf(szEntry,"File%lu",(DWORD)i+1);
      GetPrivateProfileString(lpszSection,szEntry,"",lpTxt,
                              lpMruMenu->wMaxSizeLruItem + 10,lpszFile);
      if (*lpTxt == '\0')
        break;
      SetMenuItem(lpMruMenu,i,lpTxt);
    }
  GlobalFreePtr(lpTxt);
  return TRUE;
}

#ifdef WIN32

BOOL IsWin395OrHigher(void)
{
  WORD wVer;

  wVer = LOWORD(GetVersion());
  wVer = (((WORD)LOBYTE(wVer)) << 8) | (WORD)HIBYTE(wVer);

  return (wVer >= 0x035F);              // 5F = 95 dec
}


//*************************************************************
//
//  SaveMruInReg()
//
//  Purpose:
//              Save MRU in the registry
//
//  Parameters:
//      LPMRUMENU lpMruMenu -      pointer on MRUMENU
//      LPSTR lpszKey  -           Points to a null-terminated string 
//                                      specifying  the name of a key that 
//                                      this function opens or creates.
//
//  Return: (BOOL)
//      TRUE  - Function run successfully
//      FALSE - Function don't run successfully
//
//
//  Comments:
//      Win32 function designed for Windows NT and Windows 95
//      See RegCreateKeyEx API for more info on lpszKey
//
//  History:    Date       Author       Comment
//              09/24/94   G. Vollant   Created
//
//*************************************************************
BOOL SaveMruInReg(LPMRUMENU lpMruMenu,LPSTR lpszKey)
{
LPSTR lpTxt;
WORD i;
HKEY hCurKey;
DWORD dwDisp;

  lpTxt = (LPSTR)GlobalAllocPtr(GHND,lpMruMenu->wMaxSizeLruItem + 20);
  if (lpTxt == NULL) 
    return FALSE;

  RegCreateKeyEx(HKEY_CURRENT_USER,lpszKey,0,NULL,
                  REG_OPTION_NON_VOLATILE,KEY_ALL_ACCESS,NULL,&hCurKey,&dwDisp);

  for (i=0;i<lpMruMenu->wNbLruMenu;i++)
    {
    char szEntry[16];
      wsprintf(szEntry,"File%lu",(DWORD)i+1);
      if (!GetMenuItem(lpMruMenu,i,FALSE,lpTxt,lpMruMenu->wMaxSizeLruItem + 10))
        *lpTxt = '\0';
      RegSetValueEx(hCurKey,szEntry,0,REG_SZ,(unsigned char*)lpTxt,lstrlen(lpTxt));
    }
  RegCloseKey(hCurKey);
  GlobalFreePtr(lpTxt);
  return TRUE;
}

//*************************************************************
//
//  LoadMruInReg()
//
//  Purpose:
//              Load MRU from the registry
//
//  Parameters:
//      LPMRUMENU lpMruMenu -      pointer on MRUMENU
//      LPSTR lpszKey  -           Points to a null-terminated string 
//                                      specifying  the name of a key that 
//                                      this function opens or creates.
//
//  Return: (BOOL)
//      TRUE  - Function run successfully
//      FALSE - Function don't run successfully
//
//
//  Comments:
//      Win32 function designed for Windows NT and Windows 95
//      See RegOpenKeyEx API for more info on lpszKey
//
//  History:    Date       Author       Comment
//              09/24/94   G. Vollant   Created
//
//*************************************************************
BOOL LoadMruInReg(LPMRUMENU lpMruMenu,LPSTR lpszKey)
{
LPSTR lpTxt;
WORD i;
HKEY hCurKey;
DWORD dwType;
  lpTxt = (LPSTR)GlobalAllocPtr(GHND,lpMruMenu->wMaxSizeLruItem + 20);
  if (lpTxt == NULL) 
    return FALSE;

  RegOpenKeyEx(HKEY_CURRENT_USER,lpszKey,0,KEY_READ,&hCurKey);


  for (i=0;i<lpMruMenu->wNbLruMenu;i++)
    {
    char szEntry[16];
    DWORD dwSizeBuf;  
      wsprintf(szEntry,"File%lu",(DWORD)i+1);
      *lpTxt = '\0';
      dwSizeBuf = lpMruMenu->wMaxSizeLruItem + 10;
      RegQueryValueEx(hCurKey,szEntry,NULL,&dwType,(LPBYTE)lpTxt,&dwSizeBuf);
      *(lpTxt+dwSizeBuf)='\0';
      if (*lpTxt == '\0')
        break;
      SetMenuItem(lpMruMenu,i,lpTxt);
    }
  RegCloseKey(hCurKey);
  GlobalFreePtr(lpTxt);
  return TRUE;
}


//*************************************************************
//
//  GetWin32Kind()
//
//  Purpose:
//              Get the Win32 platform
//
//  Parameters:
//
//  Return: (WIN32KIND)
//      WINNT -           Run under Windows NT
//      WIN32S -          Run under Windows 3.1x + Win32s
//      WIN95ORGREATHER - Run under Windows 95
//
//
//  Comments:
//      Win32 function designed for Windows NT and Windows 95
//      See RegOpenKeyEx API for more info on lpszKey
//
//  History:    Date       Author       Comment
//              09/24/94   G. Vollant   Created
//
//*************************************************************
WIN32KIND GetWin32Kind()
{
BOOL IsWin395OrHigher(void);

  WORD wVer;

  if ((GetVersion() & 0x80000000) == 0)
    return WINNT;
  wVer = LOWORD(GetVersion());
  wVer = (((WORD)LOBYTE(wVer)) << 8) | (WORD)HIBYTE(wVer);

  if (wVer >= 0x035F)
    return WIN95ORGREATHER;
  else
    return WIN32S;
}
#endif

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?