Books
in black and white
Main menu
Share a book About us Home
Books
Biology Business Chemistry Computers Culture Economics Fiction Games Guide History Management Mathematical Medicine Mental Fitnes Physics Psychology Scince Sport Technics
Ads

Excel add in development in C++ Aplications in finance - Dalton S.

Dalton S. Excel add in development in C++ Aplications in finance - Wiley publishing , 2005. - 425 p.
ISBN 0-470-02469-0
Download (direct link): exceladdindevelopmentincand2005.pdf
Previous << 1 .. 100 101 102 103 104 105 < 106 > 107 108 109 110 111 112 .. 168 >> Next

If MenuRef is simply the name of a built-in menu, the remaining arguments are not required and the function restores the menu to its original default state, returning the position number of the restored menu. To restore it to its original position, you need to specify this in MenuPosition, otherwise it is placed at the right of the menu bar.
If not simply the name of a menu, MenuRef is an array that describes the menu to be added or extended as shown in Table 8.24.
Table 8.24 Custom menu definition array
Required columns Optional columns
Menu text (blank) (blank) (blank) (blank)
Commandl text Commandl Name (not used) Status bar text Help reference
Command2 text Commandl Name (not used) Status bar text Help reference

Notes:
• The first two columns and at least two rows are required.
• The second column contains the command name as passed to Excel in the 4th argument to xlfRegister or the name of some other command macro VB function.
• If the command is not a recognised name Excel will not complain until the user attempts to run the command, at which point an alert dialog with the message “The macro ' command _name' cannot be found.” is displayed.
• The third column would contain a short-cut key for Macintosh systems and is therefore not used in Windows DLLs.
• The fifth column contains a help reference in the form HelpFile!TopicNum where HelpFile is a standard Windows help file.
• The third, fourth and fifth columns are all optional.
• This table can be passed to the function as either an xloper of type xltypeMulti or as a reference to range of cells on a worksheet.
If MenuPosition is omitted, commands in the MenuRef are placed at the end of the list of existing menu items and the function returns the position number of the first new command.
If argument SubMenuPosition is given, the function adds a sub-menu (or adds commands if the sub-menu already exists) to the menu specified by the position in MenuPosition. SubMenuPosition specifies the position on the sub-menu at which to place the commands. Again, this can be a number or text specifying the line before which the commands will be placed. If SubMenuPosition is omitted, then the commands are placed at the end of the menu, not the sub-menu.
256
Excel Add-in Development in C/C++
Example 1
The following code fragment adds a new menu, with two commands separated by a line, at the right of the worksheet menu bar and records the position number so that it can be modified or deleted. (Note: Referring to the menu by its text “&XLL test” is better as
the position number could be altered by other menu changes.)
The code creates an array of strings for the MenuRef parameter in an xltypeMulti
xloper, as shown in this table, using the cpp_xloper class.
"&XLL test" M M
"&XLL command 1" "XLL_CMD1"
M _ M M !t
"X&LL command 2" "XLL_CMD2"
char *menu_txt[8] = {"&XLL test", "&XLL command 1", "XLL_CMD1",
"", "X&LL command 2", "XLL_CMD2"};
cpp_xloper BarNum(10); // the worksheet menu bar
cpp_xloper MenuRef(menu_txt, (WORD)4, (WORD)2); // 4 rows, 2 columns cpp_xloper RetVal;
int xl4 = Excel4(xlfAddMenu, &RetVal, 2, &BarNum, &MenuRef);
if(xl4 == 0 && !RetVal.IsType(xltypeErr)) int test_menu_position = (int)RetVal;
Example 2
The following code fragment inserts the same new menu as in Example 1, to the immediate left of the Help menu on the worksheet menu bar.
char *menu_txt[8] = {"&XLL test", "", "&XLL command 1", "XLL_CMD1", "-", "", "X&LL command 2", "XLL_CMD2"};
cpp_xloper BarNum(10); // the worksheet menu bar
cpp_xloper MenuRef(menu_txt, (WORD)4, (WORD)2); // 4 rows, 2 columns cpp_xloper MenuPos("Help"); cpp_xloper RetVal;
int xl4 = Excel4(xlfAddMenu, &RetVal, 3, &BarNum, &MenuRef, &MenuPos);
if(xl4 == 0 && IRetVal.IsType(xltypeErr)) int test_menu_position = (int)RetVal;
Example 3
The following code fragment inserts the same menu as in Example 1 as a sub-menu just before the Table... command on the Data menu on the worksheet menu bar.
Accessing Excel Functionality Using the C API
257
char *menu_txt[8] = {"&XLL test", "&XLL command 1", "XLL_CMD1",
"", "X&LL command 2", "XLL_CMD2"};
cpp_xloper BarNum(10); // the worksheet menu bar
cpp_xloper MenuRef(menu_txt, (WORD)4, (WORD)2); // 4 rows, 2 columns cpp_xloper MenuPos("Data"); cpp_xloper SubMenuPos("Table..."); cpp_xloper RetVal;
int xl4 = Excel4(xlfAddMenu, &RetVal, 4, &BarNum, &MenuRef, &MenuPos, &SubMenuPos);
Example 4
The following code fragment restores the Data menu to the worksheet menu bar in its default position (just left of the Window menu). This presupposes that the menu was deleted with the xlfDeleteMenu command. Note that the menu will be restored in the same state in which it was deleted which may not be the Excel’s default. (To restore a menu to its default state use the xlfAddCommand function.) Note also that this code assumes that the Window menu has not itself been deleted.
cpp_xloper BarNum(10); // the worksheet menu bar cpp_xloper MenuRef("Data"); // Just the menu name!
Previous << 1 .. 100 101 102 103 104 105 < 106 > 107 108 109 110 111 112 .. 168 >> Next