Skip to content

Commit

Permalink
Add an Exit item to the Natlink message window's File sub-menu
Browse files Browse the repository at this point in the history
Re: dictation-toolbox#213.

This item is grayed out (disabled) by default, for now.  I've added
a separator between it and the File>Reload item.
  • Loading branch information
drmfinlay committed Oct 17, 2024
1 parent 08f1c16 commit 04884bc
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 3 deletions.
15 changes: 14 additions & 1 deletion NatlinkSource/MessageWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ INT_PTR CALLBACK dialogProc(
case WM_INITDIALOG:
HMENU hMenu, hSubMenu;
HINSTANCE hInstance;
LPTSTR lpszBuffer;

// Save a pointer to the message window for later.
s_pSecdThrd = (MessageWindow *)lParam;
Expand All @@ -61,6 +62,17 @@ INT_PTR CALLBACK dialogProc(
hInstance = _Module.GetModuleInstance();
hMenu = LoadMenu( hInstance, MAKEINTRESOURCE( IDR_MENU ) );

// Enable the exit sub-menu item, if requested.
s_pSecdThrd = (MessageWindow *)lParam;
if ( s_pSecdThrd->getAllowUserExit() )
{
hSubMenu = GetSubMenu( hMenu, 0 );
lpszBuffer = new TCHAR[32];
GetMenuString( hMenu, IDD_EXIT, lpszBuffer, 32, MF_BYCOMMAND );
ModifyMenu( hSubMenu, IDD_EXIT, MF_BYCOMMAND | MF_ENABLED | MF_STRING,
IDD_EXIT, lpszBuffer );
}

// Assign IDR_MENU to the window and hide it.
SetMenu( hWnd, hMenu );
ShowWindow( hWnd, SW_HIDE );
Expand Down Expand Up @@ -188,11 +200,12 @@ DWORD CALLBACK threadMain( void * pArg )

//---------------------------------------------------------------------------

MessageWindow::MessageWindow()
MessageWindow::MessageWindow( BOOL bAllowUserExit )
{
// create the thread we use to display messages; we use an event to make
// sure that the thread has started before continuing

m_bAllowUserExit = bAllowUserExit;
m_hEvent = CreateEvent(
NULL, // security options
TRUE, // manual reset
Expand Down
7 changes: 6 additions & 1 deletion NatlinkSource/MessageWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class MessageWindow
{
public:
// the constructor will create the thread
MessageWindow();
MessageWindow( BOOL bAllowUserExit );

// the destructor will terminate the thread
~MessageWindow();
Expand All @@ -27,6 +27,7 @@ class MessageWindow
void setOutWnd( HWND hWnd ) { m_hOutWnd = hWnd; }
void signalEvent() { SetEvent( m_hEvent ); }
HWND getMsgWnd() { return m_hMsgWnd; }
BOOL getAllowUserExit() { return m_bAllowUserExit; }

protected:
// This is the window handle in the primarty thread where we
Expand All @@ -43,4 +44,8 @@ class MessageWindow

// This is the handle of the output window itself
HWND m_hOutWnd;

// This is the boolean member we use to enable/disable the File>Exit menu
// item.
BOOL m_bAllowUserExit;
};
3 changes: 2 additions & 1 deletion NatlinkSource/Resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@
#define IDI_UP2 211
#define IDI_NODIR 212
#define IDD_RELOAD 32768
#define IDD_EXIT 32769

// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NO_MFC 1
#define _APS_NEXT_RESOURCE_VALUE 213
#define _APS_NEXT_COMMAND_VALUE 32769
#define _APS_NEXT_COMMAND_VALUE 32770
#define _APS_NEXT_CONTROL_VALUE 202
#define _APS_NEXT_SYMED_VALUE 102
#endif
Expand Down
2 changes: 2 additions & 0 deletions NatlinkSource/natlink.rc.in
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ BEGIN
POPUP "&File"
BEGIN
MENUITEM "&Reload Everything", IDD_RELOAD
MENUITEM SEPARATOR
MENUITEM "&Exit", IDD_EXIT, GRAYED
END
END

Expand Down

0 comments on commit 04884bc

Please sign in to comment.