NetView plug-ins


Adding and using plug-in's menus in the NetView interface

Plugin can create the menu items in Plug-ins main menu, in context menu of the hostlist and in context menu of the notificaion icon in the tray area. In is possible to create hierarchical menus by specifing parent menu ID when adding new menu item. Plugin must destroy all created menuitems before exit, otherwise they disappear only after user clicks on it. Creation, changing and removing menu items is realized with using message NMPN_MENU. The Parameter wParam can be: MENUACTION_SET - creates or changes the menu element. lParam points to structure NVMENUINFO.

NVMENUINFO fields definitions:

DWORD id: the unique identifier of the menu item (practically is a pointer on VCL object TMenuItem). For creating the new element menu set this field to 0. For subsequenting modification of the element use value of id, which NetView will set in this field after processing this message.

DWORD msg: the message which NetView will send to the specified thread when user clicks on this menu item.

DWORD tid: ThreadID of the plug-ins thread, to wich msg message will be sent on user's click

HICON icon - handle of the icon to be displayed or NULL.

DWORD parentid - id of the already created parent menu item, or NULL.

char text[64] - menu text

DWORD flags - NVMENUFLAG_MAIN menu item will be created in the Plug-ins menu, NVMENUFLAG_CONTEXT - menu item will be created in the hostlist context menu, NVMENUFLAG_TRAY - menu item will be created in the menu of tray icon. Look for other flags in text of nvplugn.h

Plug-in can dynamically create and change the elements of the menu, even then when it on screen. Sample code for creation, modification and removing created of the menu item:

Создаем менюшки:

NVMENUINFO mi,mic;

void __fastcall init()

{

//создаем пункт в главном меню

ZeroMemory(&mi,sizeof(mi));
strcpy(mi.text,"Sample");
mi.tid=GetCurrentThreadId();
mi.msg=WM_USER+0x501;
mi.flags=NVMENUFLAG_MAIN;
SendMessage(plgi->nvwnd,NMPN_MENU,NVMENUACTION_SET,(DWORD)&mi);

//adding menu subitem

ZeroMemory(&miс,sizeof(miс));
strcpy(miс.text,"Sample child menu");
miс.tid=GetCurrentThreadId();
miс.msg=WM_USER+0x502;
mic.parentid=mi.id;
SendMessage(plgi->nvwnd,NMPN_MENU,NVMENUACTION_SET,(DWORD)&mic);
}

 

 

Handler of the menu messages sent by NetView, (generating MessageBox and switching off/on menu check image :

void __fastcall workmessage(DWORD msg, DWORD wp, DWORD lp)
{
if(msg==WM_USER+0x502)

{

MessageBox(0,"User clicked my menu item","Sample plug-in",0);

mic.flags^=NVMENUFLAG_CHECKED;

SendMessage(plgi->nvwnd,NMPN_MENU,NVMENUACTION_SET,(DWORD)&mic);

}
}

Following procedure correctly deletes created menus before plug-in's termination:

void __fastcall deinit()

{

SendMessage(plgi->nvwnd,NMPN_MENU,NVMENUACTION_DEL,mic.id);
SendMessage(plgi->nvwnd,NMPN_MENU,NVMENUACTION_DEL,mi.id);
}

 

On top


© 2001-2004 Killer{R}   © 2003 VoVaN