qwert Posted September 2, 2014 Share Posted September 2, 2014 I’ve been on the search for how to simplify the default context menu for edit controls (see example below). I've read dozens of posts, which address all sorts of special cases. Indeed, there's a good one that shows how to implement a completely custom menu: But all I want to do is drop some of the standard choices. So, short of the full custom approach, is there a way to disable some of the standard context menu entries? (BTW, I've never noticed these "standard entries" on any other application. Are the standard only for AU3?) Thanks in advance for any advice. Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted September 2, 2014 Moderators Share Posted September 2, 2014 (edited) My first question would be, why do you need to remove them, rather than just not using them if you don't need them? In the end, what is it you're trying to accomplish? Edited September 2, 2014 by JLogan3o13 "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
qwert Posted September 2, 2014 Author Share Posted September 2, 2014 what is it you're trying to accomplish? Simplicity for the end user. There's not one entry in the highlighted area they would ever use. Link to comment Share on other sites More sharing options...
LarsJ Posted September 3, 2014 Share Posted September 3, 2014 It's possible:expandcollapse popup#include <WindowsConstants.au3> #include <GUIConstantsEx.au3> #include <EditConstants.au3> #include <GuiMenu.au3> Opt( "MustDeclareVars", 1 ) Example() Func Example() Local $hGui = GUICreate( "Context menu in edit control" ) GUISetState( @SW_SHOW ) Local $idEdit = GUICtrlCreateEdit( "", 176, 32, 121, 97, $ES_AUTOVSCROLL + $WS_VSCROLL ) GUICtrlSetData( $idEdit, "First line" & @CRLF ) Send( "{END}" ) GUICtrlSetData( $idEdit, "Second line", 1 ) While 1 Switch GUIGetMsg() Case $GUI_EVENT_SECONDARYDOWN Local $hMessageHandler = DllCallbackRegister( "MessageHandler", "long", "int;wparam;lparam" ) Local $hMessageHook = _WinAPI_SetWindowsHookEx( $WH_MSGFILTER, DllCallbackGetPtr( $hMessageHandler ), 0, _WinAPI_GetCurrentThreadId() ) Case $GUI_EVENT_SECONDARYUP _WinAPI_UnhookWindowsHookEx( $hMessageHook ) DllCallbackFree( $hMessageHandler ) Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd GUIDelete() EndFunc Func MessageHandler( $nCode, $wParam, $lParam ) Local Static $hContextPrev = 0 Local $hContext = GetContextMenuHandle() If $hContext And $hContextPrev <> $hContext Then $hContextPrev = $hContext For $i = 14 To 8 Step -1 ;_GUICtrlMenu_DeleteMenu( $hContext, $i ) _GUICtrlMenu_SetItemGrayed( $hContext, $i ) Next EndIf EndFunc Func GetContextMenuHandle() Local $hDesktop = _WinAPI_GetDesktopWindow(), $i = 0 Local $hChild = _WinAPI_GetWindow( $hDesktop, $GW_CHILD ) While $hChild And $i < 3 If _WinAPI_GetClassName( $hChild ) = "#32768" Then ExitLoop $hChild = _WinAPI_GetWindow( $hChild, $GW_HWNDNEXT ) $i += 1 WEnd If $i = 3 Then Return 0 Local $hContext = _SendMessage( $hChild, $MN_GETHMENU ) If $hContext > 0 Then Return $hContext Return 0 EndFuncThe AutoIt edit control is based on a MicroSoft edit control. All other applications using the MicroSoft edit control, will also get this context menu on right click. Controls, File Explorer, ROT objects, UI Automation, Windows Message MonitorCompiled code: Accessing AutoIt variables, DotNet.au3 UDF, Using C# and VB codeShell menus: The Context menu, The Favorites menu. Shell related: Control Panel, System Image ListsGraphics related: Rubik's Cube, OpenGL without external libraries, Navigating in an image, Non-rectangular selectionsListView controls: Colors and fonts, Multi-line header, Multi-line items, Checkboxes and icons, Incremental searchListView controls: Virtual ListViews, Editing cells, Data display functions Link to comment Share on other sites More sharing options...
qwert Posted September 3, 2014 Author Share Posted September 3, 2014 LarsJ, thanks for your solution. Although it's more involved than I hoped was needed, it provides the right result. The only drawback is that the menu downsizing is visible for an instant ... at least on my Win7 test PC. Regarding its effect on other applications, I wasn't able to produce an example of that. The search field in AutoIt Help, for example, continues to show all entries while the test script operates. Given this as a viable alternative, I'll have to weigh against using a custom menu. The downside of custom is having to locally handle the available features. I also want to mention that your script is a clear and concise example of DllCallback and MessageHook processing, which is too often shown surrounded by other calls and variable settings which tend to disguise the fundamental operations. I appreciate your help with this. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now