Skip to content

Commit

Permalink
Adjust and fix the message window changes a little
Browse files Browse the repository at this point in the history
  • Loading branch information
drmfinlay committed Oct 22, 2024
1 parent 984076b commit 4ec7075
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 24 deletions.
37 changes: 25 additions & 12 deletions NatlinkSource/DragonCode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1235,18 +1235,28 @@ void CDragonCode::onMenuCommand( WPARAM wParam )
break;

case IDD_EXIT:
// nothing special to do here
break;

default:
return;
}

// invoke the message window callback for menu commands handled
// above
makeCallback(
m_pMessageWindowCallback,
Py_BuildValue( "(i)", nMenuItem ) );
// invoke the message window callback, if one is set
if( m_pMessageWindowCallback )
{
makeCallback(
m_pMessageWindowCallback,
Py_BuildValue( "(i)", nMenuItem ) );
}

// do any post-callback work
switch ( nMenuItem )
{
case IDD_EXIT:
// kill the message window
setMessageWindow( Py_None );
break;
}
}

//---------------------------------------------------------------------------
Expand Down Expand Up @@ -3707,21 +3717,24 @@ BOOL CDragonCode::setMessageWindow(
}
else
{
NOTBEFORE_INIT( "setMessageWindow" );

// ignore this check if the menu is to be disabled
if( !(dwFlags & 0x04) )
{
NOTBEFORE_INIT( "setMessageWindow" );
}
Py_XINCREF( pCallback );
Py_XDECREF( m_pMessageWindowCallback );
m_pMessageWindowCallback = pCallback;

// start the second thread for displaying messages, if
// necessary. Otherwise, pass on the second parameter
// start the second thread for displaying messages
// and tell it about our message window
if( !m_pSecdThrd )
{
m_pSecdThrd = new MessageWindow( dwFlags );

// tell the thread about our message window
m_pSecdThrd->setMsgWnd( m_hMsgWnd );
}

// otherwise, update the window
else
{
m_pSecdThrd->updateWindow( dwFlags );
Expand Down
46 changes: 34 additions & 12 deletions NatlinkSource/MessageWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@
#define WM_UPDATEWINDOW (WM_USER+364)

// WPARAM flags for the WM_UPDATEWINDOW message.
#define IDR_MENU_ALLOW_USER_EXIT 0x01
#define IDR_MENU_ENABLE_IDD_EXIT 0x01
#define IDR_MENU_DISABLE_IDD_RELOAD 0x02
#define IDR_MENU_DISABLE 0x04

// The color for error messages
#define DARKRED RGB( 128, 0, 0 )
Expand Down Expand Up @@ -67,23 +69,43 @@ INT_PTR CALLBACK dialogProc(
case WM_UPDATEWINDOW:
HINSTANCE hInstance;
HMENU hMenu, hSubMenu;
UINT uFlags; // for ModifyMenu()
LPTSTR lpszBuffer;
UINT uFlags, uIDItem;

// destroy the current menu
hMenu = GetMenu( hWnd );
if( hMenu )
{
DestroyMenu( hMenu );
}

// load the pop-up menu
hInstance = _Module.GetModuleInstance();
hMenu = LoadMenu( hInstance, MAKEINTRESOURCE( IDR_MENU ) );

// enable/disable the exit sub-menu item
uFlags = MF_BYCOMMAND | MF_STRING;
if( wParam & IDR_MENU_ALLOW_USER_EXIT )
uFlags |= MF_ENABLED;
else
uFlags |= MF_GRAYED;
hSubMenu = GetSubMenu( hMenu, 0 );
lpszBuffer = new TCHAR[32];
GetMenuString( hMenu, IDD_EXIT, lpszBuffer, 32, MF_BYCOMMAND );
ModifyMenu( hSubMenu, IDD_EXIT, uFlags, IDD_EXIT, lpszBuffer );

// disable all menu items, if specified
if( wParam & IDR_MENU_DISABLE )
{
wParam &= ~IDR_MENU_ENABLE_IDD_EXIT;
wParam |= IDR_MENU_DISABLE_IDD_RELOAD;
}

// enable the exit sub-menu item, if appropriate
if( wParam & IDR_MENU_ENABLE_IDD_EXIT )
{
uFlags = MF_BYCOMMAND | MF_ENABLED;
uIDItem = IDD_EXIT;
EnableMenuItem( hSubMenu, uIDItem, uFlags );
}

// disable the reload sub-menu item, if appropriate
if( wParam & IDR_MENU_DISABLE_IDD_RELOAD )
{
uFlags = MF_BYCOMMAND | MF_GRAYED;
uIDItem = IDD_RELOAD;
EnableMenuItem( hSubMenu, uIDItem, uFlags );
}

// assign the modified menu to the window
SetMenu( hWnd, hMenu );
Expand Down
2 changes: 2 additions & 0 deletions NatlinkSource/natlink.txt
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,8 @@ setMessageWindow( callback, flags )
The second parameter is optional. It is a combination of one or more
of the following flags:
0x01 # enable the window's File>Exit menu item
0x02 # disable the window's File>Reload menu item
0x04 # disable the window's menu. Allows pre-natConnect() use

Note: The idd_reload event occurs when the File>Reload menu item is
activated. Before this function's callback is invoked, Natlink will
Expand Down

0 comments on commit 4ec7075

Please sign in to comment.