Jump to content

Adding context menu on edit control (RESOLVED)


Recommended Posts

made these changes and still no luck.

#include <GuiConstantsEx.au3>
#include <GuiEdit.au3>
#include <GuiMenu.au3>
#include <WindowsConstants.au3>
#include <Constants.au3>
#include <WinAPI.au3>

Global $LineCount = 1, $LineLen = 0
Global $lastdragIP = -1
Dim $hInput_GUI[50], $Input[6]
Global Enum $idOpen = 1000, $idSave, $idInfo

$hGUI = GUICreate("Test", 300, 200)

$button = GUICtrlCreateButton("", 50, 50, 50, 20)

GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")

GUISetState()

$wProcHandle = DllCallbackRegister("_WindowProc", "ptr", "hwnd;uint;wparam;lparam")
$wProcOld = _WinAPI_SetWindowLong(GUICtrlGetHandle($Input), $GWL_WNDPROC, DllCallbackGetPtr($wProcHandle))

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $button
                If $lastdragIP < 5 Then
                    $lastdragIP += 1
                    createNextdragIP($lastdragIP)
                EndIf
        Case $GUI_EVENT_PRIMARYDOWN
            
            $aMouse_Pos = MouseGetPos()
            $sel = -1
            For $n = 0 To $lastdragIP
                GUISwitch($hInput_GUI[$n])
                $aCursorInfo = GUIGetCursorInfo()
                
                If Not IsArray($aCursorInfo) Then ContinueLoop
                If $aCursorInfo[4] = $Input[$n] Then
                    $sel = $n
                    ExitLoop
                EndIf
                
            Next
            If $sel = -1 Then ContinueLoop
            $aInputGUI_Pos = WinGetPos($hInput_GUI[$sel])
            While IsArray($aCursorInfo) And $aCursorInfo[2] = 1
                $aCursorInfo = GUIGetCursorInfo()
                $aCurrent_Mouse_Pos = MouseGetPos()

                WinMove($hInput_GUI[$sel], "", _
                $aInputGUI_Pos[0] - $aMouse_Pos[0] + $aCurrent_Mouse_Pos[0], _
                $aInputGUI_Pos[1] - $aMouse_Pos[1] + $aCurrent_Mouse_Pos[1])
            WEnd
    EndSwitch
    If _GUICtrlEdit_GetLineCount(GUICtrlGetHandle($input)) > $LineCount Then
        $LineCount = _GUICtrlEdit_GetLineCount(GUICtrlGetHandle($input))
        $aPos = ControlGetPos($hGUI, "", $input)
        GUICtrlSetPos($input, $aPos[0], $aPos[1], $aPos[2], $aPos[3] + 15)
    ElseIf _GUICtrlEdit_GetLineCount(GUICtrlGetHandle($input)) < $LineCount Then
        $LineCount = _GUICtrlEdit_GetLineCount(GUICtrlGetHandle($input))
        $aPos = ControlGetPos($hGUI, "", $input)
        GUICtrlSetPos($input, $aPos[0], $aPos[1], $aPos[2], $aPos[3] - 15)
    EndIf
WEnd

GUIDelete($hGui)
DllCallbackFree($wProcHandle)

Func createNextdragIP($nw)
    $start = WinGetPos($hgui)
    $hInput_GUI[$nw] = GUICreate("", 120, 22, 100, 100, $WS_POPUP, $WS_EX_TOOLWINDOW)
    $Input[$nw] = GUICtrlCreateEdit("", 0, 0, 120, 22, BitOR($ES_AUTOVSCROLL, $ES_AUTOHSCROLL, $ES_WANTRETURN))
    
    $hMenu = _GUICtrlMenu_CreatePopup()

    _GUICtrlMenu_AddMenuItem($hMenu, "Delete", $idOpen)
    _GUICtrlMenu_AddMenuItem($hMenu, "Save", $idSave)
    _GUICtrlMenu_AddMenuItem($hMenu, "Info", $idInfo)
    
    GUISetState()   

EndFunc

Func WM_COMMAND($hWnd, $Msg, $wParam, $lParam)
    Local $iIDFrom = BitAND($wParam, 0xFFFF)
    Local $iCode = BitShift($wParam, 16)
   
    Switch $iCode
        Case $EN_UPDATE
            Local $iLen = _GUICtrlEdit_LineLength($iIDFrom)
           
            Local $aInputPos = ControlGetPos($hWnd, "", $iIDFrom)
            Local $aWinPos = WinGetPos($hWnd)
           
            If ($aInputPos[2] / $iLen) < 6.5 Then
                WinMove($hWnd, "", $aWinPos[0], $aWinPos[1], $aWinPos[2] + 10, $aWinPos[3])
                GUICtrlSetPos($iIDFrom, $aInputPos[0], $aInputPos[1], $aInputPos[2] + 10, $aInputPos[3])
            ElseIf ($aInputPos[2] / $iLen) > 6.5 Then
                WinMove($hWnd, "", $aWinPos[0], $aWinPos[1], $aWinPos[2] - 10, $aWinPos[3])
                GUICtrlSetPos($iIDFrom, $aInputPos[0], $aInputPos[1], $aInputPos[2] - 10, $aInputPos[3])
            EndIf
    EndSwitch

    Return $GUI_RUNDEFMSG   
EndFunc

Func _WindowProc($hWnd, $Msg, $wParam, $lParam)
    Switch $hWnd
        Case GUICtrlGetHandle($Input)
            Switch $Msg
                Case $WM_CONTEXTMENU
                    _GUICtrlMenu_TrackPopupMenu($hMenu, $wParam)
                    Return 0
                Case $WM_COMMAND
                    Switch $wParam
                        Case $idOpen
                            GUICtrlDelete($Input)
                        Case $idSave
                            ConsoleWrite("-> Save" & @LF)
                        Case $idInfo
                            ConsoleWrite("-> Info" & @LF)
                    EndSwitch
            EndSwitch
    EndSwitch
   
    Local $aRet = DllCall("user32.dll", "int", "CallWindowProc", "ptr", $wProcOld, _
                          "hwnd", $hWnd, "uint", $Msg, "wparam", $wParam, "lparam", $lParam)
    Return $aRet[0]
EndFunc
Link to comment
Share on other sites

And I'm not trying to get you to tell me to answer. I'm trying to solve this myself but I have no idea what PsaltyDS meant by a local variable input...

Then you should have at least cleaned it up enough so it would pass syntax check:

Running AU3Check (1.54.13.0) from:C:\Program Files\AutoIt3

C:\temp\Test.au3(117,40) : WARNING: $hMenu: possibly used before declaration.

_GUICtrlMenu_TrackPopupMenu($hMenu,

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

What I meant was the variables are declared inside functions, so they are local to those functions. You were then trying to access those same variables in another function, where it doesn't exist. The second attempt cleaned up $nw, but $hMenu is still the same. This could be fixed by just putting "Global $hMenu" near the top of your script, but you still have a pretty strange GUI, and I don't understand at all what it's supposed to do.

:P

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Still need help with my problem a few posts back

Edit: When you said adding Global $hMenu would fix my problem it didn't. The custom context menu still doesn't show...

Let me clarify:

This could be fixed by just putting "Global $hMenu" near the top of your script, ...

"This" only meant the syntax check failure, which should have been corrected before posting it.

The operative part is this:

...but you still have a pretty strange GUI, and I don't understand at all what it's supposed to do.

This has not changed, so I can't help you.

:P

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Me having a strange GUI shouldnt matter. Its not strange at all, its simple.

All there is to it is you click a button which makes a draggable input. Then you can click the button and it will make ANOTHER draggable input. You can move all of them around anywhere. What I need to do is to be able to right click on any of them and have the custom menu pop-up. Pretty simple I think.

Tell me if I didn't explain it well enough.

Link to comment
Share on other sites

Mate, some advice. Stop shooting the other that try to help you. The only way you're going to get help, is if you are nice, courteous, and except the examples being given. Also, you've got to put an ounce of effort in. That way we can see you are at least attempting to take on board what we are showing you.

And one other thing, no one will do it for you, and serve it on a silver platter... :P

Cheers,

Brett

Link to comment
Share on other sites

I will not enter into any argument. But since you asked, 2 posts which stick out...

I'm a dumbass with this. I still dont get it...

How does that have to do with my problem?

What was the point of that?

Edit: And who would want default menu entries? Let's try to stay far away form that otherwise this great example is useless. Whoever wants default menu entries can stay with the system context menu.

Many examples are done specifically for the OP's needs... Many examples I would do, would be done just for them.

Link to comment
Share on other sites

  • 4 weeks later...

This:

#include <GuiConstantsEx.au3>
#include <GuiEdit.au3>
#include <WindowsConstants.au3>
#include <GUIMenu.au3>
#include <WindowsConstants.au3>
#include <Constants.au3>
#include <EditConstants.au3>
#include <WinAPI.au3>

Dim $hInput_GUI[6], $Input[6]

Global $lastdragIP = -1
Global Enum $idOpen = 1000, $idSave, $idInfo

$GUI = GUICreate("Test", 300, 300)

$button5 = GUICtrlCreateButton("", 100, 200, 40, 25)
GUICtrlSetState(-1, $GUI_DEFBUTTON)

GUISetState()

$wProcHandle = DllCallbackRegister("_WindowProc", "ptr", "hwnd;uint;wparam;lparam")

$wProcOld = _WinAPI_SetWindowLong(GUICtrlGetHandle($Input), $GWL_WNDPROC, DllCallbackGetPtr($wProcHandle))

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            Exit
        Case $msg = $button5
            If $lastdragIP < 5 Then
                $lastdragIP += 1
                createNextdragIP($lastdragIP)
            EndIf
        Case $msg = $GUI_EVENT_PRIMARYDOWN
            $aMouse_Pos = MouseGetPos()
            $sel = -1
           
            For $n = 0 To $lastdragIP
                GUISwitch($hInput_GUI[$n])
                $aCursorInfo = GUIGetCursorInfo()
               
                If Not IsArray($aCursorInfo) Then ContinueLoop
                If $aCursorInfo[4] = $Input[$n] Then
                    $sel = $n
                    ExitLoop
                EndIf
            Next
           
            If $sel = -1 Then ContinueLoop
            $aInputGUI_Pos = WinGetPos($hInput_GUI[$sel])
           
           While IsArray($aCursorInfo) And $aCursorInfo[2] = 1
                $aCursorInfo = GUIGetCursorInfo()
                $aCurrent_Mouse_Pos = MouseGetPos()

                WinMove($hInput_GUI[$sel], "", _
                $aInputGUI_Pos[0] - $aMouse_Pos[0] + $aCurrent_Mouse_Pos[0], _
                $aInputGUI_Pos[1] - $aMouse_Pos[1] + $aCurrent_Mouse_Pos[1])
            WEnd
        EndSelect
WEnd

Func createNextdragIP($nw)
    $start = WinGetPos($GUI)
    $hInput_GUI[$nw] = GUICreate("", 120, 22, $start[0]+30, $start[1]+200, $WS_POPUP, $WS_EX_TOOLWINDOW)
    $Input[$nw] = GUICtrlCreateEdit("", 0, 0, 120, 22, BitOR($ES_AUTOVSCROLL,$ES_AUTOHSCROLL,$ES_WANTRETURN))
   
    $hMenu = _GUICtrlMenu_CreatePopup()

    _GUICtrlMenu_AddMenuItem($hMenu, "Delete", $idOpen)
    _GUICtrlMenu_AddMenuItem($hMenu, "Save", $idSave)
    _GUICtrlMenu_AddMenuItem($hMenu, "Info", $idInfo)
   
    GUISetState()
    WinSetOnTop($hInput_GUI[$nw], "", 1)
EndFunc  ;==>createNextdragIP

Func _WindowProc($hWnd, $Msg, $wParam, $lParam)
    Switch $hWnd
        Case GUICtrlGetHandle($Input)
            Switch $Msg
                Case $WM_CONTEXTMENU
                    _GUICtrlMenu_TrackPopupMenu($hMenu, $wParam)
                    Return 0
                Case $WM_COMMAND
                    Switch $wParam
                        Case $idOpen
                            GUICtrlDelete($Input)
                        Case $idSave
                            ConsoleWrite("-> Save" & @LF)
                        Case $idInfo
                            ConsoleWrite("-> Info" & @LF)
                    EndSwitch
            EndSwitch
    EndSwitch
   
    Local $aRet = DllCall("user32.dll", "int", "CallWindowProc", "ptr", $wProcOld, _
                          "hwnd", $hWnd, "uint", $Msg, "wparam", $wParam, "lparam", $lParam)
    Return $aRet[0]
EndFunc
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...