Discussion:
Disable Console Window Context Menu
(too old to reply)
Michael
2010-03-12 07:26:01 UTC
Permalink
Hi,

I am trying to find out whether it is possible to disable the default
context menu that appears when a user right clicks in a console window. It
appears that when the console context menu is active it prevents writes to
the console window.

We have a Win32 multithreaded console application running on Windows XP.
The application regularly updates information in the console window. However
if someone has accidently right clicks in the console window the application
basically freezes because it's unable to write to the console.

Regards
Dee Earley
2010-03-12 10:24:57 UTC
Permalink
Post by Michael
Hi,
I am trying to find out whether it is possible to disable the default
context menu that appears when a user right clicks in a console window. It
appears that when the console context menu is active it prevents writes to
the console window.
We have a Win32 multithreaded console application running on Windows XP.
The application regularly updates information in the console window. However
if someone has accidently right clicks in the console window the application
basically freezes because it's unable to write to the console.
It does this to allow text selection and clipboard operations.
If you are in quick edit mode, it pauses on a left click.

I can't see any way to disable this.
--
Dee Earley (***@icode.co.uk)
i-Catcher Development Team

iCode Systems
Uwe Sieber
2010-03-15 11:31:46 UTC
Permalink
Post by Michael
Hi,
I am trying to find out whether it is possible to disable the default
context menu that appears when a user right clicks in a console window. It
appears that when the console context menu is active it prevents writes to
the console window.
We have a Win32 multithreaded console application running on Windows XP.
The application regularly updates information in the console window. However
if someone has accidently right clicks in the console window the application
basically freezes because it's unable to write to the console.
You can remove all menu items of the console window's
system menu. The popup menu is a sub menu of the console
window's system menu, so it is gone then too.

This is what my tool ConsoleNoClose does when it's started
with param /all.
http://www.uwe-sieber.de/files/consolenoclose.zip

Here is the VB code, h is the hwnd of the console window:

'----------------------------------------------------
Sub DisableAllMenus(h As Long)

Dim hMenu As Long

hMenu = GetSystemMenu(h, 0)

Call EnableMenuItem(hMenu, SC_CLOSE, MF_BYCOMMAND Or MF_GRAYED Or MF_DISABLED)
Call DeleteMenu(hMenu, SC_CLOSE, MF_BYCOMMAND)

Dim l As Long, hSub As Long
For l = 20 To 0 Step -1

hSub = GetSubMenu(hMenu, l)

If hSub Then
Dim l2 As Long
For l2 = 10 To 0 Step -1
Call EnableMenuItem(hSub, l2, MF_BYPOSITION Or MF_GRAYED Or MF_DISABLED)
Call DeleteMenu(hSub, l2, MF_BYPOSITION)
Next l2
End If
Call EnableMenuItem(hMenu, l, MF_BYPOSITION Or MF_GRAYED Or MF_DISABLED)
Call DeleteMenu(hMenu, l, MF_BYPOSITION)
Next l

End Sub
'----------------------------------------------------



Uwe

Loading...