#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <GUIMenu.au3>
#include <Constants.au3>
#include <WinAPI.au3>
;
Global Enum $idCopy = 1000, $idExit
Global $hGUI, $hMenu, $iExit = 0, $aCM_Edits[1][1]
Global $wProcHandle = DllCallbackRegister("_WindowProc", "ptr", "hwnd;uint;wparam;lparam")
$hGUI = GUICreate("_SetEditContextMenu", 300, 350)
$Edit1 = GUICtrlCreateEdit("", 10, 10, 280, 150, BitOR($WS_HSCROLL, $WS_VSCROLL, $ES_MULTILINE))
_SetEditContextMenu($Edit1)
$Edit2 = GUICtrlCreateEdit("", 10, 180, 280, 150, BitOR($WS_HSCROLL, $WS_VSCROLL, $ES_MULTILINE))
_SetEditContextMenu($Edit2)
$hMenu = _GUICtrlMenu_CreatePopup()
_GUICtrlMenu_AddMenuItem($hMenu, "Copy", $idCopy)
_GUICtrlMenu_AddMenuItem($hMenu, "", 0)
_GUICtrlMenu_AddMenuItem($hMenu, "Exit", $idExit)
GUISetState()
While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
ExitLoop
EndSwitch
If $iExit Then ExitLoop
WEnd
GUIDelete($hGui)
DllCallbackFree($wProcHandle)
Func _SetEditContextMenu($nEdit)
Local $wProcOld = _WinAPI_SetWindowLong(GUICtrlGetHandle($nEdit), $GWL_WNDPROC, DllCallbackGetPtr($wProcHandle))
$aCM_Edits[0][0] += 1
ReDim $aCM_Edits[$aCM_Edits[0][0]+1][2]
$aCM_Edits[$aCM_Edits[0][0]][0] = $nEdit
$aCM_Edits[$aCM_Edits[0][0]][1] = $wProcOld
EndFunc
Func _WindowProc($hWnd, $nMsg, $wParam, $lParam)
Local $wProcOld, $aRet
For $i = 1 To UBound($aCM_Edits)-1
If $hWnd = GUICtrlGetHandle($aCM_Edits[$i][0]) Then
Switch $nMsg
Case $WM_CONTEXTMENU
_GUICtrlMenu_TrackPopupMenu($hMenu, $wParam)
Return 0
Case $WM_COMMAND
Switch $wParam
Case $idCopy
$sSelected = ControlCommand($hGUI, "", $aCM_Edits[$i][0], "GetSelected")
If Not @error Then ClipPut($sSelected)
Case $idExit
$iExit = 1
ExitLoop
EndSwitch
EndSwitch
$wProcOld = $aCM_Edits[$i][1]
ExitLoop
EndIf
Next
If $wProcOld Then
$aRet = DllCall("user32.dll", "int", "CallWindowProc", "ptr", $wProcOld, _
"hwnd", $hWnd, "uint", $nMsg, "wparam", $wParam, "lparam", $lParam)
Return $aRet[0]
EndIf
EndFunc