Sign in to follow this  
Followers 0
JohnBailey

Add Options to Rightclick menu on Input(edit) Control

6 posts in this topic

#1 ·  Posted (edited)

The Answer: (edit 09/26/2007)

#409166

The Question:(original post)

Has anyone done a script for adding options to the rightclick menu for input (and/or edit) controls or know where to start researching?

Basically, I just want to expand the typical rightclick menu (the one that contains copy, paste, etc.) for an edit or input control.

I've tried using WM_Notify_Events but that didn't seem to be the key. I already have a WM_COMMAND function setup so maybe just adapting it would be the key, but I didn't know if it could be used to detect mouse clicks.

Obviously, I'm at a loss.

I hesitate in posting my script project because I want to learn this in general. Nonetheless, here's my script without the rightclick addition. I just want to be able to right click the input control and it be able to have an option to specify whether or not to have the search be anywhere in the column or at the beginning of the columns text.

#include <GUIConstants.au3>
#include <GuiListView.au3>
#include <File.au3>
#include <Array.au3>
#include <ArrayMore.au3>
#Include <Misc.au3>
#Include <String.au3>
#include <GuiCombo.au3>

#include <ControlConstants.au3>

Opt ("GUIOnEventMode", 1)



;==== Row Entries
; Delim. 
Global $SettingsIR_delimiter = ''
; File 
Global $dbRowEntriesFile = @ScriptDir&'\LV Filter - onchange expand.txt'
; Array
Global $dbRowEntriesArray
;Array 2D
Global $dbRowEntriesArray2D
;Array 2D Column Count
Global $dbRowEntriesArray2DCount
;====

Local $LVHeaders = 'One|Two|Three'
Global $CBcurrentIndex

$AppWin = GUICreate("Search Example", 451, 623, 193, 125)
GUISetBkColor(0x716F64)
$Input = GUICtrlCreateInput("", 31, 39, 240, 22)
GUICtrlSetFont(-1, 9, 800, 0, "Rockwell")
$Label1 = GUICtrlCreateLabel("Search", 31, 20, 36, 17)
GUICtrlSetColor(-1, 0xC0C0C0)
$LV_Main = GUICtrlCreateListView($LVHeaders, 31, 65, 374, 495)
GUICtrlSendMsg($LV_Main, 0x101E, 0, 150)
GUICtrlSendMsg($LV_Main, 0x101E, 1, 110)
GUICtrlSendMsg($LV_Main, 0x101E, 2, 100)
GUICtrlSetBkColor($LV_Main, 0xD4D0C8)

Global $TotalColumns = _GUICtrlListViewGetSubItemsCount($LV_Main)
$dbRowEntriesArray2D =  _setupRowEntries()

$Label2 = GUICtrlCreateLabel("Column To Search", 278, 19, 126, 17)
GUICtrlSetColor($Label2, 0xC0C0C0)
$Combo1 = GUICtrlCreateCombo("All", 277, 39, 128, 25)
GUICtrlSetData($Combo1,$LVHeaders)
$StatusBar = GUICtrlCreateLabel("", 0, 604, 450, 17, $SS_SUNKEN)

GUIRegisterMsg($WM_COMMAND, "MY_WM_COMMAND")

GUISetOnEvent($GUI_EVENT_CLOSE, "_GUIEvents")
GUISetOnEvent($GUI_EVENT_MINIMIZE, "_GUIEvents")
GUISetOnEvent($GUI_EVENT_RESTORE, "_GUIEvents")

GUICtrlSetOnEvent($Combo1, "ButtonPressed")

GUISetState(@SW_SHOW)

_loadRowEntries($LV_Main)

While 1
   Sleep(25)
WEnd

Func _FilterLV()
    Local $CBcurrent = GUICtrlRead($Combo1)

    Local $Search = GUICtrlRead($Input)
    Local $Content = ''
    Local $List1 = $dbRowEntriesArray
    _GUICtrlListViewDeleteAllItems($LV_Main)
    If $Search <> '' Then
        If $CBcurrentIndex = 0 Then
            For $a = 1 to UBound($List1)-1
                If StringInStr($List1[$a],$Search) Then
                    Local $itemLineArray = StringSplit($List1[$a],$SettingsIR_delimiter,1)
                    Local $itemLine = ''
                    For $b = 1 to $itemLineArray[0]
                        If $b = $itemLineArray[0] Then
                            $itemLine &= $itemLineArray[$b]
                        Else
                            $itemLine &= $itemLineArray[$b]&'|'
                        EndIf
                    Next
                    GUICtrlCreateListViewItem($itemLine, $LV_Main)
                EndIf
            Next
        Else
            For $a = 1 to UBound($List1)-1
                If StringInStr($dbRowEntriesArray2D[$a][$CBcurrentIndex-1],$Search) Then
                    Local $itemLineArray = StringSplit($List1[$a],$SettingsIR_delimiter,1)
                    Local $itemLine = ''
                    For $b = 1 to $itemLineArray[0]
                        If $b = $itemLineArray[0] Then
                            $itemLine &= $itemLineArray[$b]
                        Else
                            $itemLine &= $itemLineArray[$b]&'|'
                        EndIf
                    Next
                    GUICtrlCreateListViewItem($itemLine, $LV_Main)
                EndIf
            Next
        EndIf
    Else
        For $a = 1 to UBound($List1)-1
            Local $itemLineArray = StringSplit($List1[$a],$SettingsIR_delimiter,1)
            Local $itemLine = ''
            For $b = 1 to $itemLineArray[0]
                If $b = $itemLineArray[0] Then
                    $itemLine &= $itemLineArray[$b]
                Else
                    $itemLine &= $itemLineArray[$b]&'|'
                EndIf
            Next
            GUICtrlCreateListViewItem($itemLine, $LV_Main)
        Next
    EndIf
EndFunc

Func _setupRowEntries();set it up after the columns are setup
    
    _FileReadToArray($dbRowEntriesFile,$dbRowEntriesArray)
    If @error Then
        Msgbox(0,'File not read to Array',$dbRowEntriesFile&@LF&' to $dbRowEntriesArray')
    EndIf
    $dbRowEntriesArray2DCount = 3
    Local $sre_dbRowEntriesArray2D[UBound($dbRowEntriesArray)][$dbRowEntriesArray2DCount]
    
    Local $x = 1
    For $x = 1 to UBound($dbRowEntriesArray)-1
        Local $readSplitArray = StringSplit($dbRowEntriesArray[$x],$SettingsIR_delimiter,1)
        Local $xx = 0   
        For $xx = 1 to $readSplitArray[0]
            $sre_dbRowEntriesArray2D[$x][$xx-1] = $readSplitArray[$xx]
        Next
    Next
    
    Return $sre_dbRowEntriesArray2D
EndFunc

Func _loadRowEntries(ByRef $lvID)
    For $x = 1 to Ubound($dbRowEntriesArray2D)-1
        Local $itemLine = ''
        For $xx = 1 to $dbRowEntriesArray2DCount
            If $xx = $dbRowEntriesArray2DCount Then
                $itemLine &= $dbRowEntriesArray2D[$x][$xx-1]
            Else
                $itemLine &= $dbRowEntriesArray2D[$x][$xx-1]&'|'
            EndIf
        Next
        GUICtrlCreateListViewItem($itemLine, $lvID)
    Next
EndFunc


Func MY_WM_COMMAND($hWnd, $msg, $wParam, $lParam)
  ; gaFrost for monitoring inputfield change
    Local $nNotifyCode = BitShift($wParam, 16)
    Local $nID = BitAND($wParam, 0xFFFF)
    Local $hCtrl = $lParam

    Switch $nID
        Case $Input
            Switch $nNotifyCode
                Case $EN_CHANGE
                    _FilterLV()     
            EndSwitch
    EndSwitch
  ; Proceed the default Autoit3 internal message commands.
  ; You also can complete let the line out.
  ; !!! But only 'Return' (without any value) will not proceed
  ; the default Autoit3-message in the future !!!
    Return $GUI_RUNDEFMSG
EndFunc ;==>MY_WM_COMMAND

;==>WM_Notify_Events

Func ButtonPressed()
    Switch @GUI_CTRLID
        case $Combo1
            $CBcurrentIndex = _GUICtrlComboGetCurSel ( $Combo1 )
            _FilterLV()
    EndSwitch
EndFunc

Func _GUIEvents()
    Select
        Case @GUI_CTRLID = $GUI_EVENT_CLOSE
            Exit        
            
        Case @GUI_CTRLID = $GUI_EVENT_MINIMIZE
            
        Case @GUI_CTRLID = $GUI_EVENT_RESTORE
            
    EndSelect
    
EndFunc
Edited by JohnBailey

A decision is a powerful thing

Share this post


Link to post
Share on other sites



So nobody asks ;-)

ControlConstants.au3

#include-once
;Window Events
If Not IsDeclared('WM_NOTIFY') Then         Global Const $WM_NOTIFY     = 0x004E
If Not IsDeclared('WM_COMMAND') Then        Global Const $WM_COMMAND    = 0x0111
If Not IsDeclared('WM_KEYDOWN') Then        Global Const $WM_KEYDOWN      = 0x100
If Not IsDeclared('WM_COPYDATA') Then       Global Const $WM_COPYDATA   = 0x4A
If Not IsDeclared('WM_MOVING') Then         Global Const $WM_MOVING     = 0x0216
If Not IsDeclared('WM_MOVE') Then           Global Const $WM_MOVE       = 0x0003
If Not IsDeclared('WM_KILLFOCUS') Then      Global Const $WM_KILLFOCUS  = 0x0008
If Not IsDeclared('WM_SETFOCUS') Then       Global Const $WM_SETFOCUS   = 0x0007
If Not IsDeclared('WM_ACTIVATE') Then       Global Const $WM_ACTIVATE   = 0x0006
If Not IsDeclared('WM_CAPTURECHANGED') Then Global Const $WM_CAPTURECHANGED = 0x0215

;ListView Events
If Not IsDeclared('NM_FIRST') Then          Global Const $NM_FIRST              = 0
If Not IsDeclared('NM_LAST') Then           Global Const $NM_LAST               = (-99)
If Not IsDeclared('NM_OUTOFMEMORY') Then    Global Const $NM_OUTOFMEMORY        = ($NM_FIRST - 1)
If Not IsDeclared('NM_CLICK') Then          Global Const $NM_CLICK              = ($NM_FIRST - 2)
If Not IsDeclared('NM_DBLCLK') Then         Global Const $NM_DBLCLK             = ($NM_FIRST - 3)
If Not IsDeclared('NM_RETURN') Then         Global Const $NM_RETURN             = ($NM_FIRST - 4)
If Not IsDeclared('NM_RCLICK') Then         Global Const $NM_RCLICK             = ($NM_FIRST - 5)
If Not IsDeclared('NM_RDBLCLK') Then        Global Const $NM_RDBLCLK            = ($NM_FIRST - 6)
If Not IsDeclared('NM_SETFOCUS') Then       Global Const $NM_SETFOCUS           = ($NM_FIRST - 7)
If Not IsDeclared('NM_KILLFOCUS') Then      Global Const $NM_KILLFOCUS          = ($NM_FIRST - 8)
If Not IsDeclared('NM_CUSTOMDRAW') Then     Global Const $NM_CUSTOMDRAW         = ($NM_FIRST - 12)
If Not IsDeclared('NM_HOVER') Then          Global Const $NM_HOVER              = ($NM_FIRST - 13)
If Not IsDeclared('NM_NCHITTEST') Then      Global Const $NM_NCHITTEST          = ($NM_FIRST - 14)
If Not IsDeclared('NM_KEYDOWN') Then        Global Const $NM_KEYDOWN            = ($NM_FIRST - 15)
If Not IsDeclared('NM_RELEASEDCAPTURE') Then Global Const $NM_RELEASEDCAPTURE   = ($NM_FIRST - 16)
If Not IsDeclared('NM_SETCURSOR') Then      Global Const $NM_SETCURSOR          = ($NM_FIRST - 17)
If Not IsDeclared('NM_CHAR') Then           Global Const $NM_CHAR               = ($NM_FIRST - 18)
If Not IsDeclared('NM_TOOLTIPSCREATED') Then Global Const $NM_TOOLTIPSCREATED   = ($NM_FIRST - 19)
If Not IsDeclared('LVS_SHAREIMAGELISTS') Then Global Const $LVS_SHAREIMAGELISTS = 0x0040
If Not IsDeclared('LVN_FIRST') Then         Global Const $LVN_FIRST             = -100
If Not IsDeclared('LVN_ENDLABELEDITA') Then Global Const $LVN_ENDLABELEDITA     = (-106)
If Not IsDeclared('LVN_ITEMCHANGING') Then  Global Const $LVN_ITEMCHANGING      = ($LVN_FIRST - 0)
If Not IsDeclared('LVN_ITEMCHANGED') Then   Global Const $LVN_ITEMCHANGED       = ($LVN_FIRST - 1)
If Not IsDeclared('LVN_INSERTITEM') Then    Global Const $LVN_INSERTITEM        = ($LVN_FIRST - 2)
If Not IsDeclared('LVN_DELETEITEM') Then    Global Const $LVN_DELETEITEM        = ($LVN_FIRST - 3)
If Not IsDeclared('LVN_DELETEALLITEMS') Then Global Const $LVN_DELETEALLITEMS   = ($LVN_FIRST - 4)
If Not IsDeclared('LVN_COLUMNCLICK') Then   Global Const $LVN_COLUMNCLICK       = ($LVN_FIRST - 8)
If Not IsDeclared('LVN_BEGINDRAG') Then     Global Const $LVN_BEGINDRAG         = ($LVN_FIRST - 9)
If Not IsDeclared('LVN_BEGINRDRAG') Then    Global Const $LVN_BEGINRDRAG        = ($LVN_FIRST - 11)
If Not IsDeclared('LVN_ODCACHEHINT') Then   Global Const $LVN_ODCACHEHINT       = ($LVN_FIRST - 13)   
If Not IsDeclared('LVN_ITEMACTIVATE') Then  Global Const $LVN_ITEMACTIVATE      = ($LVN_FIRST - 14)
If Not IsDeclared('LVN_ODSTATECHANGED') Then Global Const $LVN_ODSTATECHANGED   = ($LVN_FIRST - 15)
If Not IsDeclared('LVN_HOTTRACK') Then      Global Const $LVN_HOTTRACK          = ($LVN_FIRST - 21)
If Not IsDeclared('LVN_KEYDOWN ') Then      Global Const $LVN_KEYDOWN           = ($LVN_FIRST - 55)
If Not IsDeclared('LVN_MARQUEEBEGIN') Then  Global Const $LVN_MARQUEEBEGIN      = ($LVN_FIRST - 56) 

;Edit Events
If Not IsDeclared('EN_CHANGE') Then     Global Const $EN_CHANGE = 0x300
If Not IsDeclared('EN_SETFOCUS') Then   Global Const $EN_SETFOCUS = 0x100
If Not IsDeclared('EN_KILLFOCUS') Then  Global Const $EN_KILLFOCUS = 0x200
If Not IsDeclared('EN_UPDATE') Then     Global Const $EN_UPDATE =0x0400

;ComboBox Events
If Not IsDeclared('CBN_EDITCHANGE') Then    Global Const $CBN_EDITCHANGE    = 5
If Not IsDeclared('CBN_SELCHANGE') Then     Global Const $CBN_SELCHANGE     = 1
If Not IsDeclared('CBN_EDITUPDATE') Then    Global Const $CBN_EDITUPDATE    = 6
If Not IsDeclared('CBN_KILLFOCUS') Then     Global Const $CBN_KILLFOCUS     = 4
If Not IsDeclared('CBN_SETFOCUS') Then      Global Const $CBN_SETFOCUS      = 3
If Not IsDeclared('CBN_DBLCLK ') Then       Global Const $CBN_DBLCLK        = 2;
If Not IsDeclared('CBN_DROPDOWN ') Then     Global Const $CBN_DROPDOWN    = 7;
If Not IsDeclared('CBN_CLOSEUP') Then       Global Const $CBN_CLOSEUP      = 8;
If Not IsDeclared('CBN_SELENDOK') Then      Global Const $CBN_SELENDOK    = 9;
If Not IsDeclared('CBN_SELENDCANCEL') Then  Global Const $CBN_SELENDCANCEL  = 10;

; Date/Time Events
If Not IsDeclared('DTN_FIRST') Then             Global Const $DTN_FIRST         = -760
If Not IsDeclared('DTN_DATETIMECHANGE') Then    Global Const $DTN_DATETIMECHANGE = $DTN_FIRST + 1; the systemtime has changed
If Not IsDeclared('DTN_USERSTRINGA') Then       Global Const $DTN_USERSTRINGA   = $DTN_FIRST + 2 ; the user has entered a string
If Not IsDeclared('DTN_WMKEYDOWNA') Then        Global Const $DTN_WMKEYDOWNA    = $DTN_FIRST + 3 ; modify keydown on app format field (X)
If Not IsDeclared('DTN_FORMATA') Then           Global Const $DTN_FORMATA       = $DTN_FIRST + 4 ; query display for app format field (X)
If Not IsDeclared('DTN_FORMATQUERYA') Then      Global Const $DTN_FORMATQUERYA  = $DTN_FIRST + 5 ; query formatting info for app format field (X)
If Not IsDeclared('DTN_DROPDOWN') Then          Global Const $DTN_DROPDOWN      = $DTN_FIRST + 6 ; MonthCal has dropped down
If Not IsDeclared('DTN_CLOSEUP') Then           Global Const $DTN_CLOSEUP       = $DTN_FIRST + 7 ; MonthCal is popping up


; unknown group
If Not IsDeclared('HDN_FIRST') Then     Global Const $HDN_FIRST     = -300
If Not IsDeclared('HDN_TRACK') Then     Global Const $HDN_TRACK     = ($HDN_FIRST - 8)
If Not IsDeclared('HDN_TRACKW') Then    Global Const $HDN_TRACKW    = ($HDN_FIRST - 28)

If Not IsDeclared('LBN_SELCHANGE') Then Global Const $LBN_SELCHANGE = 1
If Not IsDeclared('LBN_DBLCLK') Then    Global Const $LBN_DBLCLK    = 2
If Not IsDeclared('LBN_SETFOCUS') Then  Global Const $LBN_SETFOCUS  = 4
If Not IsDeclared('LBN_KILLFOCUS') Then Global Const $LBN_KILLFOCUS = 5

There is a specific reason why I use this entire include file during testing.


A decision is a powerful thing

Share this post


Link to post
Share on other sites

Um, still that's not enough to run your code, ArrayMore.au3 and that LV filter file is missing.

Anyway.

You can start with one of the recent topics, here http://www.autoitscript.com/forum/index.php?showtopic=46923

And forum search with keywords "edit control" "contextmenu" etc. would probably net you some further thoughts on this matter.


"be smart, drink your wine"

Share this post


Link to post
Share on other sites

Um, still that's not enough to run your code, ArrayMore.au3 and that LV filter file is missing.

Anyway.

You can start with one of the recent topics, here http://www.autoitscript.com/forum/index.php?showtopic=46923

And forum search with keywords "edit control" "contextmenu" etc. would probably net you some further thoughts on this matter.

my bad about the ArrayMore.au3. Actually just mark that out or totally remove it. It's not being used. *That and the ControlConstants.au3 are two files I typically always include. My bad. Just mark it out or remove it.

As for the topic search suggestions. I'll look into that. thank you


A decision is a powerful thing

Share this post


Link to post
Share on other sites

So basically...

I want to Apend Item(s) to Contextmenu for Input and Edit Controls using Subclassing

haha but how!?! :-D :laughs:

Thanks! I'll keep researching (food should be obtained for brain fuel first)


A decision is a powerful thing

Share this post


Link to post
Share on other sites

The Answer:

#409166


A decision is a powerful thing

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0