home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
DP Tool Club 19
/
CD_ASCQ_19_010295.iso
/
win
/
prg
/
cenviw
/
menuctrl.lib
< prev
next >
Wrap
Text File
|
1994-08-19
|
11KB
|
265 lines
// MenuCtrl.lib - Functions for controlling window menus.
// ver.4
//
gSubmenuBranch = "##"; // string to separate submenus in finding menu strings
//
//**** MenuCommand(): Send a menu command to window
// SYNTAX: int MenuCommand(int WindowHandle,int MenuItem[,bool Post])
// int MenuCommand(int WindowHandle,string MenuItem[,bool Post[,bool FullStringLength]])
// WHERE: WindowHandle: Handle of frame window, if 0 or not supplied
// default to active window
// MenuItem: if integer then it is the menu ID for this item, if string
// then will search through menu items for string with case
// insensitive match to start of string and ignoring the
// '&' character. Wherever string contains this gSubmenuBranchivision
// then parse down through menus.
// Post: Optional, True to PostMessage(), else SendMessage(); default True
// FullStringLength: If True then match full string length, else only
// partial. Default is False
// RETURN: Return value of the SendMessage() or PostMessage() call
// NOTE: This function does not report back the MenuItem was not found, but
// only returns FALSE in that case. If you want to be sure about
// finding the item then use GetMenu() and FindMenuString() first.
//
//
//**** SystemMenuCommand(): Send a menu command to window
// SYNTAX: bool SystemMenuCommand(int WindowHandle,int MenuItem[,bool Post])
// bool SystemMenuCommand(int WindowHandle,string MenuItem[,bool Post[,bool FullStringLength]])
// WHERE: WindowHandle: Handle of frame window, if 0 or not supplied
// default to active window
// MenuItem: if integer then it is the menu ID for this item, if string
// then will search through menu items for string with case
// insensitive match to start of string and ignoring the
// '&' character. Wherever string contains this gSubmenuBranch
// then parse down through menus.
// Post: Optional, True to PostMessage(), else SendMessage(); default True
// FullStringLength: If True then match full string length, else only
// partial. Default is False
// RETURN: Return value of the SendMessage() or PostMessage() call
// NOTE: See MenuCommand().
//
//
//**** FindMenuString(): Among menus and submenus, find ID for string
// SYNTAX: int FindMenuString(int MenuHandle,string PartialString[,bool FullStringLength])
// WHERE: MenuHandle: as retrieved by GetMenu()
// PartialString: string to match menu (case-insensitive) up up to length
// of this string. Use the gSubmenuBranch to divide
// different names down submenu tree
// FullStringLength: If True then match full string length, else only
// partial. Default is False
// RETURN: 0 if not found, else ID of matching menu item
// NOTE: This compares menu item string without the special & character, and
// so this is not very fast
//
//
//**** GetMenu(): Retrieve handle to menu of window
// SYNTAX: int GetMenu([int WindowHandle])
// WHERE: WindowHandle: Handle of frame window, if 0 or not supplied
// default to active window
// RETURN: Return handle to menu for this window, or NULL if no menu
// NOTE: If WindowHandle is a child window then return value is undefined
//
//
//**** GetSystemMenu(): Retrieve handle for system menu
// SYNTAX: int GetMenu([int WindowHandle])
// WHERE: WindowHandle: Handle of frame window, if 0 or not supplied
// default to active window
// RETURN: Return handle to menu for this window, or NULL if no menu
// NOTE: If WindowHandle is a child window then return value is undefined
//
//
//**** GetMenuString(): Get string of a menu item
// SYNTAX: string GetMenuString(int MenuHandle,int id,int Flag)
// WHERE: MenuHandle: as retrieved by GetMenu()
// id: integer ID of menu item, or offset depending on Flag
// Flag: indicate use of id; one of the following
#define MF_BYCOMMAND 0x0000 // use the item ID
#define MF_BYPOSITION 0x0400 // zero-based position
// RETURN: Return string for this menu item, will not be NULL but may be ""
//
//
//**** GetMenuItemID(): Get Menu item ID based on ordinal position
// SYNTAX: int GetMenuItemID(int MenuHandle,int Pos)
// WHERE: MenuHandle: as retrieved by GetMenu()
// Pos: ordinal position of this menu item
// RETURN: Return item ID, or -1 if MenuHandle is 0 or the specified
// item is a pop-up menu item
//
//
//**** GetMenuItemCount()
// SYNTAX: int GetMenuItemCount(int MenuHandle)
// WHERE: MenuHandle: as retrieved by GetMenu()
// RETURN: Return number of items in menu; -1 if error
//
//
//**** GetSubMenu()
// SYNTAX: int GetSubMenu(int MenuHandle,int Pos)
// WHERE: MenuHandle: as retrieved by GetMenu()
// Pos: Ordinal position in parent menu
// RETURN: Return menu handle or NULL
//
//
//**** GetMenuState()
// SYNTAX: int GetMenuState(int MenuHandle,int ItemID,int Flags)
// WHERE: MenuHandle: as retrieved by GetMenu()
// ItemID: menu-item by ordinal or ID depending on Flags containing
// MF_BYPOSITION or MF_BYCOMMAND (see GetMenuString())
// Flag: indicate use of ItemID, ordinal or ID (see GetMenuString())
// RETURN: -1 if item does not exist. If ItemID by position is a sub-menu
// item, then returns number of menu items in high-order byte and
// following flags in low order; else if menu item then returns flags
// integer which is Boolean OR of these values:
#define MF_BITMAP 0x04 // item is a bitmap
#define MF_CHECKED 0x08 // checkmark is next to item
#define MF_DISABLED 0x02 // Item is disabled
#define MF_GRAYED 0x01 // Item is disabled and grayed
#define MF_POPUP 0x10 // popup menu item
#define MF_MENUBREAK 0x40 // new line or new column sith separator
#define MF_MENUBARBREAK 0x20 // same as MF_MENUBREAK with vertical line for popup menus
#define MF_HILITE 0x80 // hilite menu item
#define MF_SEPARATOR 0x800 // Horizontal dividing line in popup menu
//
//
#include <Message.lib>
_GetActiveWindow()
{
return DynamicLink("USER","GETACTIVEWINDOW",SWORD16,PASCAL);
}
GetMenu(pWindowHandle)
{
return DynamicLink( "USER","GETMENU",UWORD16,PASCAL,
va_arg() && pWindowHandle ? pWindowHandle : _GetActiveWindow() );
}
GetSystemMenu(pWindowHandle)
{
return DynamicLink( "USER","GETSYSTEMMENU",UWORD16,PASCAL,
va_arg() && pWindowHandle ? pWindowHandle : _GetActiveWindow(), 0 );
}
GetMenuItemCount(pMenu)
{
return DynamicLink("USER","GETMENUITEMCOUNT",UWORD16,PASCAL,pMenu);
}
GetMenuString(pMenu,pID,pFlag)
{
lString[400] = '\0';
lString[DynamicLink("USER","GETMENUSTRING",SWORD16,PASCAL,pMenu,pID,lString,399,pFlag)] = 0;
return lString;
}
GetMenuState(pMenu,pItemID,pFlags)
{
lRet = DynamicLink("USER","GETMENUSTATE",UWORD16,PASCAL,pMenu,pItemID,pFlags);
if ( 0xFFFF == (lRet & 0xFFFF) )
return -1;
return lRet;
}
GetMenuItemID(pMenu,pPos)
{
lID = DynamicLink("USER","GETMENUITEMID",UWORD16,PASCAL,pMenu,pPos)
return ( 0xFFFF == (lID & 0xFFFF) ) ? -1 : lID ;
}
GetSubMenu(pMenu,pPos)
{
return DynamicLink("USER","GETSUBMENU",UWORD16,PASCAL,pMenu,pPos);
}
MenuMenuCommand(pHwnd,pMenu,pItem,pPost,pMessage,pFullStringLength)
{
if ( 0 == DataDimension(pItem) ) {
// EASY! Just send item message
lItem = pItem;
} else {
// pItem is a string, so must check all menus items and submenus to find
// pItem
lItem = FindMenuString(pMenu,pItem,pFullStringLength);
}
if ( !lItem )
return FALSE;
return ( pPost )
? PostMessage(pHwnd,pMessage,lItem,0)
: SendMessage(pHwnd,pMessage,lItem,0) ;
}
MenuCommand(pWindowHandle,pItem,pPost,pFullStringLength)
{
lPost = ( va_arg() < 3 ) ? True : pPost ;
lHwnd = ( pWindowHandle ) ? pWindowHandle : _GetActiveWindow();
lFullStringLength = 3 < va_arg() ? pFullStringLength : False ;
return ( lHwnd && (lMenu = GetMenu(lHwnd)) )
? MenuMenuCommand(lHwnd,lMenu,pItem,lPost,WM_COMMAND,lFullStringLength)
: FALSE ;
}
SystemMenuCommand(pWindowHandle,pItem,pPost,pFullStringLength)
{
lPost = ( va_arg() < 3 ) ? True : pPost ;
lHwnd = ( pWindowHandle ) ? pWindowHandle : _GetActiveWindow();
lFullStringLength = 3 < va_arg() ? pFullStringLength : False ;
return ( lHwnd && (lMenu = GetSystemMenu(lHwnd)) )
? MenuMenuCommand(lHwnd,lMenu,pItem,lPost,WM_SYSCOMMAND,lFullStringLength)
: FALSE ;
}
MenuStringICompare(pMenu,pOrd,pString,pCompareLen,pFullStringLength)
{ // return True if i-compare, else false
lMenuString = GetMenuString(pMenu,pOrd,MF_BYPOSITION);
if ( lMenuString[0] ) {
// remove all '&' characters
lFindAmper = lMenuString;
while ( lFindAmper = strchr(lFindAmper,'&') )
strcpy(lFindAmper,lFindAmper+1);
// compare new found string against our source
if ( !strnicmp(lMenuString,pString,pCompareLen)
&& (!pFullStringLength || '\0'==lMenuString[pCompareLen]) ) {
// YEA!!!! it is found
return True;
}
}
return False;
}
FindMenuString(pMenu,pPartialString,pFullStringLength)
{
lFullStringLength = 2 < va_arg() ? pFullStringLength : False ;
// check if looking just for a menu or parsing down sub menus
if ( lNextMenuString = strstr(pPartialString,gSubmenuBranch) ) {
lCompareLen = lNextMenuString - pPartialString;
lNextMenuString += strlen(gSubmenuBranch);
} else {
lCompareLen = strlen(pPartialString);
}
if ( -1 == (lCount = GetMenuItemCount(pMenu)) )
return 0;
for ( lOrd = 0; lOrd < lCount; lOrd++ ) {
if ( -1 == (lMenuID = GetMenuItemID(pMenu,lOrd)) ) {
// this is a submenu, so check down this submenu
if ( (lSubMenu = GetSubMenu(pMenu,lOrd)) ) {
if ( lNextMenuString ) {
// go down in menus only if this matches
if ( MenuStringICompare(pMenu,lOrd,pPartialString,lCompareLen,lFullStringLength) ) {
if ( lMenuID = FindMenuString(lSubMenu,lNextMenuString,lFullStringLength) )
return lMenuID;
}
} else {
if ( lMenuID = FindMenuString(lSubMenu,pPartialString,lFullStringLength) )
return lMenuID;
}
}
} else if ( !lNextMenuString ) {
if ( MenuStringICompare(pMenu,lOrd,pPartialString,lCompareLen,lFullStringLength) )
// YEA!!!! it is found
return GetMenuItemID(pMenu,lOrd);
}
}
return 0;
}