Pop-up菜单就是在表格上用鼠标的右键点击而弹出的菜单。
第1步 激活 Pop-up 菜单
要使用Pop-up菜单得先激活,只需在OnSetup()函数中执行EnableMenu()即可。
请把下面的这一句添加到MyCug::OnSetup内:
/**************************************************************************************/
EnableMenu(TRUE);
第2步 处理 OnMenuStart() 函数
在OnMenuStart()函数内可以添加Pop-up菜单项,下面演示添加三个Pop-up菜单项 "Cut", "Copy", "Paste"。
在MyCug类的OnMenuStart()函数内添加如下代码:
1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
|
int MyCug::OnMenuStart(int col, long row, int section)
{ UNREFERENCED_PARAMETER(col); UNREFERENCED_PARAMETER(row); UNREFERENCED_PARAMETER(section); if (section == UG_GRID) { //****** Empty the Menu!! EmptyMenu(); //******* Add the Menu Items AddMenuItem(1000, "Cut"); AddMenuItem(2000, "Copy"); AddMenuItem(3000, "Paste"); } return TRUE; } |
第3步 处理 OnMenuCommand()函数
当用户在表格上点击鼠标右键弹出Pop-up菜单项后,选择了其中的一个菜单,OnMenuCommand()函数即刻被执行,此时可以在函数内编码对用户的选择做出处理。
1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
|
void MyCug::OnMenuCommand(int col, long row, int section, int item)
{ UNREFERENCED_PARAMETER(col); UNREFERENCED_PARAMETER(row); UNREFERENCED_PARAMETER(section); UNREFERENCED_PARAMETER(item); if (section == UG_GRID) { //****** The user has selected the 'Cut' option if (item == 1000) CutSelected(); //****** The user has selected the 'Copy' option if (item == 2000) CopySelected(); //****** The user has selected the 'Paste' option if (item == 3000) Paste(); } } |