NX Open Programmer's Guide > Execution Methods > Programs, Journals, or Callbacks from New Menu Items > Callback Registration for NX Open for C++
Callback Registration for NX Open for C++
The AddMenuAction method (on MenuBar::MenuBarManager) registers a callback with NX. The name passed to AddMenuAction must match the string used as the ACTIONS value in the menu file (e.g. "my_app_hello", "my_app_goodbye").
The example (hello_goodbye.h / hello_goodbye.cpp) registers two callbacks in an InitializeCallbacks() method. After compiling/linking, the resulting hello_goodbye.dll is placed in the startup folder alongside one of the example menu files (see "Executing Callbacks (Menu Event Handlers)").
Header (hello_goodbye.h) — key structure
#include <uf_def.h>
#include <uf.h>
#include <NXOpen/Session.hxx>
#include <NXOpen/MenuBar_MenuBarManager.hxx>
#include <NXOpen/MenuBar_MenuButton.hxx>
#include <NXOpen/MenuBar_MenuButtonEvent.hxx>
#include <NXOpen/UI.hxx>
#include <NXOpen/Callback.hxx>
#include <NXOpen/NXException.hxx>
using namespace NXOpen;
class HelloGoodbye
{
public:
static Session* theSession;
static UI* theUI;
static ListingWindow* lw;
static int registered;
HelloGoodbye();
~HelloGoodbye();
MenuBar::MenuBarManager::CallbackStatus HelloCB(MenuBar::MenuButtonEvent* buttonEvent);
MenuBar::MenuBarManager::CallbackStatus GoodbyeCB(MenuBar::MenuButtonEvent* buttonEvent);
private:
void InitializeCallbacks();
};
Source (hello_goodbye.cpp) — registration pattern
void HelloGoodbye::InitializeCallbacks()
{
try
{
if (registered == 0)
{
theUI->MenuBarManager()->AddMenuAction("my_app_hello", make_callback(...));
// similarly register "my_app_goodbye"
registered = 1;
}
}
catch (...) { /* handle NXException */ }
}
HelloCB and GoodbyeCB implement the actual button-click behavior, receiving a MenuBar::MenuButtonEvent* and returning a MenuBar::MenuBarManager::CallbackStatus.
Related Topics
- Programs, Journals, or Callbacks from New Menu Items — Overview
- Introduction to Menu Files
- Executing Programs
- Executing Journals
- Executing Callbacks (Menu Event Handlers)
- Callback Registration for NX Open for .NET
- Callback Registration for NX Open for Java
Source: https://docs.sw.siemens.com/en-US/doc/209349590/PL20220512394070742.nxopen_prog_guide/new_menu_cpp_callbacks · retrieved Tue Jul 07 2026 00:00:00 GMT+0000 (Coordinated Universal Time)