如何即时地释放动态创建的菜单?(50分)

  • 主题发起人 主题发起人 阿权
  • 开始时间 开始时间

阿权

Unregistered / Unconfirmed
GUEST, unregistred user!
我想在光标离开动态菜单时,释放它。不知可不可以捕获菜单窗口关闭消息?
 
? So easy?

TrackPopupMenu返回之后, 直接DestroyMenu啦!
 
能否给点例子。
 
Here is some C++ code pieces from my program, which will popup
a menu while user click the tray icon of the program.
Hope it will also help in Delphi Programming.

POINT pt;
CMenu menu;
CMenu *pPopupMenu;

// Popup Menu
::GetCursorPos((LPPOINT)&pt);
if (menu.LoadMenu(IDR_MENU_COLLECTION)) {
pPopupMenu = menu.GetSubMenu(0);
if (pPopupMenu!=NULL) {
SetForegroundWindow(); // This is learned from Books online,
pPopupMenu->TrackPopupMenu(TPM_LEFTALIGN | TPM_LEFTBUTTON | TPM_RIGHTBUTTON, pt.x, pt.y, this, NULL);
PostMessage(WM_USER, 0, 0); // d.o. "This is the problem of design" -- Microsoft PSS said
}
menu.DestroyMenu();
}
 
有Delphi的吗?
 
上面的代码基本上可以用于Delphi, 只是你必须用HMENU代替
CMenu类, 相应的LoadMenu, TrackPopupMenu和DestroyMenu必须改为针对HMENU
 
在Borland/Delphi 3/Source/Vcl/menus.pas文件中有TrackPopupMenu和DestroyMenu的例子。
 
try destructor procedure to free it
 
try destructor procedure to free it
 
阿权啊,好久没来了,问题结束了吧
 

Similar threads

D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
后退
顶部