mru.cpp
来自「quake3工具源码。包括生成bsp文件」· C++ 代码 · 共 651 行 · 第 1/2 页
CPP
651 行
//*************************************************************
// File name: mru.c
//
// Description:
//
// Routines for MRU support
//
// Development Team:
//
// Gilles Vollant (100144.2636@compuserve.com)
//
//*************************************************************
#include "stdafx.h"
#include <windows.h>
#include <windowsx.h>
#include <string.h>
#include "mru.h"
// CreateMruMenu : MRUMENU constructor
// wNbLruShowInit : nb of item showed in menu
// wNbLruMenuInit : nb of item stored in memory
// wMaxSizeLruItemInit : size max. of filename
//*************************************************************
//
// CreateMruMenu()
//
// Purpose:
//
// Allocate and Initialize an MRU and return a pointer on it
//
//
// Parameters:
//
// WORD wNbLruShowInit - Maximum number of item displayed on menu
// WORD wNbLruMenuInit - Maximum number of item stored in memory
// WORD wMaxSizeLruItemInit - Maximum size of an item (ie size of pathname)
// WORD wIdMruInit - ID of the first item in the menu (default:IDMRU)
//
//
// Return: (LPMRUMENU)
//
// Pointer on a MRUMENU structure, used by other function
//
//
// Comments:
// wNbLruShowInit <= wNbLruMenuInit
//
//
// History: Date Author Comment
// 09/24/94 G. Vollant Created
//
//*************************************************************
LPMRUMENU CreateMruMenu (WORD wNbLruShowInit,
WORD wNbLruMenuInit,WORD wMaxSizeLruItemInit,WORD wIdMruInit)
{
LPMRUMENU lpMruMenu;
lpMruMenu = (LPMRUMENU)GlobalAllocPtr(GHND,sizeof(MRUMENU));
lpMruMenu->wNbItemFill = 0;
lpMruMenu->wNbLruMenu = wNbLruMenuInit;
lpMruMenu->wNbLruShow = wNbLruShowInit;
lpMruMenu->wIdMru = wIdMruInit;
lpMruMenu->wMaxSizeLruItem = wMaxSizeLruItemInit;
lpMruMenu->lpMRU = (LPSTR)GlobalAllocPtr(GHND,
lpMruMenu->wNbLruMenu*(UINT)lpMruMenu->wMaxSizeLruItem);
if (lpMruMenu->lpMRU == NULL)
{
GlobalFreePtr(lpMruMenu);
lpMruMenu = NULL;
}
return lpMruMenu;
}
//*************************************************************
//
// CreateMruMenuDefault()
//
// Purpose:
//
// Allocate and Initialize an MRU and return a pointer on it
// Use default parameter
//
//
// Parameters:
//
//
// Return: (LPMRUMENU)
//
// Pointer on a MRUMENU structure, used by other function
//
//
// Comments:
//
//
// History: Date Author Comment
// 09/24/94 G. Vollant Created
//
//*************************************************************
LPMRUMENU CreateMruMenuDefault()
{
return CreateMruMenu (NBMRUMENUSHOW,NBMRUMENU,MAXSIZEMRUITEM,IDMRU);
}
//*************************************************************
//
// DeleteMruMenu()
//
// Purpose:
// Destructor :
// Clean and free a MRUMENU structure
//
// Parameters:
//
// LPMRUMENU lpMruMenu - pointer on MRUMENU, allocated
// by CreateMruMenu() or CreateMruMenuDefault()
//
//
// Return: void
//
//
// Comments:
//
//
// History: Date Author Comment
// 09/24/94 G. Vollant Created
//
//*************************************************************
void DeleteMruMenu(LPMRUMENU lpMruMenu)
{
GlobalFreePtr(lpMruMenu->lpMRU);
GlobalFreePtr(lpMruMenu);
}
//*************************************************************
//
// SetNbLruShow()
//
// Purpose:
// Change the maximum number of item displayed on menu
//
// Parameters:
// LPMRUMENU lpMruMenu - pointer on MRUMENU
// WORD wNbLruShowInit - Maximum number of item displayed on menu
//
//
// Return: void
//
//
// Comments:
//
//
// History: Date Author Comment
// 09/24/94 G. Vollant Created
//
//*************************************************************
void SetNbLruShow (LPMRUMENU lpMruMenu,WORD wNbLruShowInit)
{
lpMruMenu->wNbLruShow = min(wNbLruShowInit,lpMruMenu->wNbLruMenu);
}
//*************************************************************
//
// SetMenuItem()
//
// Purpose:
// Set the filename of an item
//
// Parameters:
// LPMRUMENU lpMruMenu - pointer on MRUMENU
// WORD wItem - Number of Item to set, zero based
// LPSTR lpItem - String, contain the filename of the item
//
//
// Return: (BOOL)
// TRUE - Function run successfully
// FALSE - Function don't run successfully
//
//
// Comments:
// used when load .INI or reg database
//
// History: Date Author Comment
// 09/24/94 G. Vollant Created
//
//*************************************************************
BOOL SetMenuItem (LPMRUMENU lpMruMenu,WORD wItem,LPSTR lpItem)
{
if (wItem >= NBMRUMENU)
return FALSE;
_fstrncpy((lpMruMenu->lpMRU) +
((lpMruMenu->wMaxSizeLruItem) * (UINT)wItem),
lpItem,lpMruMenu->wMaxSizeLruItem-1);
lpMruMenu->wNbItemFill = max(lpMruMenu->wNbItemFill,wItem+1);
return TRUE;
}
//*************************************************************
//
// GetMenuItem()
//
// Purpose:
// Get the filename of an item
//
// Parameters:
// LPMRUMENU lpMruMenu - pointer on MRUMENU
// WORD wItem - Number of Item to set, zero based
// BOOL fIDMBased - TRUE : wItem is based on ID menu item
// FALSE : wItem is zero-based
// LPSTR lpItem - String where the filename of the item will be
// stored by GetMenuItem()
// UINT uiSize - Size of the lpItem buffer
//
//
// Return: (BOOL)
// TRUE - Function run successfully
// FALSE - Function don't run successfully
//
//
// Comments:
// Used for saving in .INI or reg database, or when user select
// an MRU in File menu
//
// History: Date Author Comment
// 09/24/94 G. Vollant Created
//
//*************************************************************
BOOL GetMenuItem (LPMRUMENU lpMruMenu,WORD wItem,
BOOL fIDMBased,LPSTR lpItem,UINT uiSize)
{
if (fIDMBased)
wItem -= (lpMruMenu->wIdMru + 1);
if (wItem >= lpMruMenu->wNbItemFill)
return FALSE;
_fstrncpy(lpItem,(lpMruMenu->lpMRU) +
((lpMruMenu->wMaxSizeLruItem) * (UINT)(wItem)),uiSize);
*(lpItem+uiSize-1) = '\0';
return TRUE;
}
//*************************************************************
//
// AddNewItem()
//
// Purpose:
// Add an item at the begin of the list
//
// Parameters:
// LPMRUMENU lpMruMenu - pointer on MRUMENU
// LPSTR lpItem - String contain the filename to add
//
// Return: (BOOL)
// TRUE - Function run successfully
// FALSE - Function don't run successfully
//
//
// Comments:
// Used when used open a file (using File Open common
// dialog, Drag and drop or MRU)
//
// History: Date Author Comment
// 09/24/94 G. Vollant Created
//
//*************************************************************
void AddNewItem (LPMRUMENU lpMruMenu,LPSTR lpItem)
{
WORD i,j;
for (i=0;i<lpMruMenu->wNbItemFill;i++)
if (lstrcmpi(lpItem,(lpMruMenu->lpMRU) +
((lpMruMenu->wMaxSizeLruItem) * (UINT)i)) == 0)
{
// Shift the other items
for (j=i;j>0;j--)
lstrcpy((lpMruMenu->lpMRU) + (lpMruMenu->wMaxSizeLruItem * (UINT)j),
(lpMruMenu->lpMRU) + (lpMruMenu->wMaxSizeLruItem * (UINT)(j-1)));
_fstrncpy(lpMruMenu->lpMRU,lpItem,lpMruMenu->wMaxSizeLruItem-1);
return ;
}
lpMruMenu->wNbItemFill = min(lpMruMenu->wNbItemFill+1,lpMruMenu->wNbLruMenu);
for (i=lpMruMenu->wNbItemFill-1;i>0;i--)
lstrcpy(lpMruMenu->lpMRU + (lpMruMenu->wMaxSizeLruItem * (UINT)i),
lpMruMenu->lpMRU + (lpMruMenu->wMaxSizeLruItem * (UINT)(i-1)));
_fstrncpy(lpMruMenu->lpMRU,lpItem,lpMruMenu->wMaxSizeLruItem-1);
}
//*************************************************************
//
// DelMenuItem()
//
// Purpose:
// Delete an item
//
// Parameters:
// LPMRUMENU lpMruMenu - pointer on MRUMENU
// WORD wItem - Number of Item to set, zero based
// BOOL fIDMBased - TRUE : wItem is based on ID menu item
// FALSE : wItem is zero-based
//
// Return: (BOOL)
// TRUE - Function run successfully
// FALSE - Function don't run successfully
//
//
// Comments:
// Used when used open a file, using MRU, and when an error
// occured (by example, when file was deleted)
//
// History: Date Author Comment
// 09/24/94 G. Vollant Created
//
//*************************************************************
BOOL DelMenuItem(LPMRUMENU lpMruMenu,WORD wItem,BOOL fIDMBased)
{
WORD i;
if (fIDMBased)
wItem -= (lpMruMenu->wIdMru + 1);
if (lpMruMenu->wNbItemFill <= wItem)
return FALSE;
lpMruMenu->wNbItemFill--;
for (i=wItem;i<lpMruMenu->wNbItemFill;i++)
lstrcpy(lpMruMenu->lpMRU + (lpMruMenu->wMaxSizeLruItem * (UINT)i),
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?