Sign in to follow this  
Followers 0
nitekram

[RESOLVED] Problem with context menus - popups

2 posts in this topic

#1 ·  Posted (edited)

I am trying to allow a user to right click on either of the two input boxes and get a context menu that is different on each one to popup, but only one is popping - any ideas how I can make this happen.

In my original code the issue is different - I get both popups but after going to the first one once, it stops working. I have tried to reproduce the issue in this code but cannot even get the second input box to pop.

Any further information needed - please ask.

By the way in this example both go to the same function, but in mine it will be different.

EDIT - this code works now - so it is an issue with my code - sorry

EDIT - change the topic name - ALSO note this is not resolved

#include <WinAPI.au3>
#include <Constants.au3>
#include <GuiMenu.au3>
#include <GUIConstantsEx.au3>


Global $IDhomeP1, $GameHome1P1
$WM_CONTEXTMENU = 0x007B
$WM_SETCURSOR = 0x0020

$mainGUI = GUICreate('test')
$GameHome1P1 = GUICtrlCreateInput('adsf', 0, 50)
$IDhomeP1 = GUICtrlCreateInput('', 0, 0)



GUISetState(@SW_SHOW, $mainGUI)



$DummyMenu = GUICtrlCreateDummy()
$ContextMenu = GUICtrlCreateContextMenu($DummyMenu)
$EightONMenuItem = GUICtrlCreateMenuItem("Eight On Break", $ContextMenu)

$wProcNew = DllCallbackRegister("_MyWindowProc", "ptr", "hwnd;uint;long;ptr")
$wProcOld = _WinAPI_SetWindowLong(GUICtrlGetHandle($GameHome1P1), $GWL_WNDPROC, DllCallbackGetPtr($wProcNew))

;#cs
$DummyMenu2 = GUICtrlCreateDummy()
$ContextMenu2 = GUICtrlCreateContextMenu($DummyMenu2)
$AdminMenuItem = GUICtrlCreateMenuItem("Go to admin", $ContextMenu2)

$wProcNew2 = DllCallbackRegister("_MyWindowProc2", "ptr", "hwnd;uint;long;ptr")
$wProcOld2 = _WinAPI_SetWindowLong(GUICtrlGetHandle($IDhomeP1), $GWL_WNDPROC, DllCallbackGetPtr($wProcNew2))
;#ce

While 1
    $msg = GUIGetMsg()
    
    If $msg = $GUI_EVENT_CLOSE Then
        MsgBox('', '', 'exit')
        GUIDelete($mainGUI)
        DllCallbackFree($wProcNew)
        ;DllCallbackFree($wProcNew2)
        Exit
    EndIf
WEnd


Func ShowMenu($hWnd, $nContextID, $itype)
    Local $iSelected = _GUICtrlMenu_TrackPopupMenu(GUICtrlGetHandle($nContextID), $hWnd, -1, -1, -1, -1, 2)

    Switch $iSelected
        Case $EightONMenuItem
            If $itype = '$GameHome1P1' Then GetAdminGui(1)
    EndSwitch
    
EndFunc   ;==>ShowMenu

Func _MyWindowProc($hWnd, $uiMsg, $wParam, $lParam)
    Switch $uiMsg
        Case $WM_CONTEXTMENU
            Switch $hWnd
                ; Player 1
                Case GUICtrlGetHandle($GameHome1P1)
                    ShowMenu($mainGUI, $ContextMenu, "$GameHome1P1")
                    Return 0

            EndSwitch
            
        Case $WM_SETCURSOR
            GUICtrlSetCursor(_WinAPI_GetDlgCtrlID($hWnd), 2);; 5 set Ibeam cursor , 2 set to arrow
            Return 1;;and don't let default windowproc mess things up
    EndSwitch
    
    ;pass the unhandled messages to default WindowProc
    Return _WinAPI_CallWindowProc($wProcOld, $hWnd, $uiMsg, $wParam, $lParam)
    
EndFunc   ;==>_MyWindowProc


;#cs

Func ShowMenu2($hWnd, $nContextID2, $itype)
    Local $iSelected = _GUICtrlMenu_TrackPopupMenu(GUICtrlGetHandle($nContextID2), $hWnd, -1, -1, -1, -1, 2)
    
    Switch $iSelected
        Case $AdminMenuItem
            If $itype = "$IDhomeP1" Then GetAdminGui(GUICtrlRead($IDhomeP1))
    EndSwitch
EndFunc   ;==>ShowMenu2


Func _MyWindowProc2($hWnd, $uiMsg, $wParam, $lParam)
    Switch $uiMsg
        Case $WM_CONTEXTMENU
            Switch $hWnd
                Case GUICtrlGetHandle($IDhomeP1)
                    ShowMenu2($mainGUI, $ContextMenu2, "$IDhomeP1")
                    Return 0
            EndSwitch
        Case $WM_SETCURSOR
            GUICtrlSetCursor(_WinAPI_GetDlgCtrlID($hWnd), 2);; 5 set Ibeam cursor , 2 set to arrow
            Return 1;;and don't let default windowproc mess things up
    EndSwitch
    
    ;pass the unhandled messages to default WindowProc
    Return _WinAPI_CallWindowProc($wProcOld2, $hWnd, $uiMsg, $wParam, $lParam)
    
EndFunc   ;==>_MyWindowProc2

;#ce

Func GetAdminGui($iid)
    MsgBox('', '$iid', $iid)
EndFunc   ;==>GetAdminGui
Edited by nitekram

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Rather than start a new topic - I thought I would hijack this one.

I am trying to have a context menu appear in another gui (not the main gui) and I keep getting errors when autoit closes.

Any ideas as to where the error is located? Or maybe I am not able to use context menus on other GUIs?

Here is my working code - that errors when it exits

#include <WinAPI.au3>
#include <Constants.au3>
#include <GuiMenu.au3>
#include <GUIConstantsEx.au3>


Global $IDhomeP1, $GameHome1P1, $WinsInputAdmin
$WM_CONTEXTMENU = 0x007B
$WM_SETCURSOR = 0x0020

$mainGUI = GUICreate('test')
$GameHome1P1 = GUICtrlCreateInput('adsf', 0, 50)
$IDhomeP1 = GUICtrlCreateInput('', 0, 0)



GUISetState(@SW_SHOW, $mainGUI)

$adminGUI = GUICreate('test2')
$WinsInputAdmin = GUICtrlCreateInput('', 0, 0)
GUISetState(@SW_HIDE, $adminGUI)

$DummyMenu = GUICtrlCreateDummy()
$ContextMenu = GUICtrlCreateContextMenu($DummyMenu)
$EightONMenuItem = GUICtrlCreateMenuItem("Eight On Break", $ContextMenu)

$wProcNew = DllCallbackRegister("_MyWindowProc", "ptr", "hwnd;uint;long;ptr")
$wProcOld = _WinAPI_SetWindowLong(GUICtrlGetHandle($GameHome1P1), $GWL_WNDPROC, DllCallbackGetPtr($wProcNew))

;#cs
$DummyMenu2 = GUICtrlCreateDummy()
$ContextMenu2 = GUICtrlCreateContextMenu($DummyMenu2)
$AdminMenuItem = GUICtrlCreateMenuItem("Go to admin", $ContextMenu2)

$wProcNew2 = DllCallbackRegister("_MyWindowProc2", "ptr", "hwnd;uint;long;ptr")
$wProcOld2 = _WinAPI_SetWindowLong(GUICtrlGetHandle($IDhomeP1), $GWL_WNDPROC, DllCallbackGetPtr($wProcNew2))
;#ce

$DummyMenu3 = GUICtrlCreateDummy()
$ContextMenu3 = GUICtrlCreateContextMenu($DummyMenu3)
$AdminMenuItemChange = GUICtrlCreateMenuItem("Change Score", $ContextMenu3)

;#cs
$wProcNew3 = DllCallbackRegister("_MyWindowProc3", "ptr", "hwnd;uint;long;ptr")
$wProcOld3 = _WinAPI_SetWindowLong(GUICtrlGetHandle($WinsInputAdmin), $GWL_WNDPROC, DllCallbackGetPtr($wProcNew3))


While 1
    $msg = GUIGetMsg()
    
    If $msg = $GUI_EVENT_CLOSE Then
        MsgBox('', '', 'exit')
        GUIDelete($mainGUI)
        DllCallbackFree($wProcNew)
        DllCallbackFree($wProcNew2)
        DllCallbackFree($wProcNew3)
        Exit
    EndIf
WEnd


Func ShowMenu($hWnd, $nContextID, $itype)
    Local $iSelected = _GUICtrlMenu_TrackPopupMenu(GUICtrlGetHandle($nContextID), $hWnd, -1, -1, -1, -1, 2)

    Switch $iSelected
        Case $EightONMenuItem
            If $itype = '$GameHome1P1' Then GetAdminGui(1)
    EndSwitch
    
EndFunc   ;==>ShowMenu

Func _MyWindowProc($hWnd, $uiMsg, $wParam, $lParam)
    Switch $uiMsg
        Case $WM_CONTEXTMENU
            Switch $hWnd
                ; Player 1
                Case GUICtrlGetHandle($GameHome1P1)
                    ShowMenu($mainGUI, $ContextMenu, "$GameHome1P1")
                    Return 0

            EndSwitch
            
        Case $WM_SETCURSOR
            GUICtrlSetCursor(_WinAPI_GetDlgCtrlID($hWnd), 2);; 5 set Ibeam cursor , 2 set to arrow
            Return 1;;and don't let default windowproc mess things up
    EndSwitch
    
    ;pass the unhandled messages to default WindowProc
    Return _WinAPI_CallWindowProc($wProcOld, $hWnd, $uiMsg, $wParam, $lParam)
    
EndFunc   ;==>_MyWindowProc


;#cs

Func ShowMenu2($hWnd, $nContextID2, $itype)
    Local $iSelected = _GUICtrlMenu_TrackPopupMenu(GUICtrlGetHandle($nContextID2), $hWnd, -1, -1, -1, -1, 2)
    
    Switch $iSelected
        Case $AdminMenuItem
            If $itype = "$IDhomeP1" Then GetAdminGui2(GUICtrlRead($IDhomeP1))
    EndSwitch
EndFunc   ;==>ShowMenu2


Func _MyWindowProc2($hWnd, $uiMsg, $wParam, $lParam)
    Switch $uiMsg
        Case $WM_CONTEXTMENU
            Switch $hWnd
                Case GUICtrlGetHandle($IDhomeP1)
                    ShowMenu2($mainGUI, $ContextMenu2, "$IDhomeP1")
                    Return 0
            EndSwitch
        Case $WM_SETCURSOR
            GUICtrlSetCursor(_WinAPI_GetDlgCtrlID($hWnd), 2)
            Return 1
    EndSwitch
    
    ;pass the unhandled messages to default WindowProc
    Return _WinAPI_CallWindowProc($wProcOld2, $hWnd, $uiMsg, $wParam, $lParam)
    
EndFunc   ;==>_MyWindowProc2

Func ShowMenu3($hWnd, $nContextID3)
    Local $iSelected = _GUICtrlMenu_TrackPopupMenu(GUICtrlGetHandle($nContextID3), $hWnd, -1, -1, -1, -1, 2)

    Switch $iSelected
        Case $AdminMenuItemChange
            MsgBox('', '', 'in showmenu3')
    EndSwitch
EndFunc   ;==>ShowMenu3

Func _MyWindowProc3($hWnd, $uiMsg, $wParam, $lParam)
    Switch $uiMsg
        Case $WM_CONTEXTMENU
            Switch $hWnd

                Case GUICtrlGetHandle($WinsInputAdmin)
                    ;MsgBox('','','')
                    ShowMenu3($mainGUI, $ContextMenu3)
                    Return 0

            EndSwitch
        Case $WM_SETCURSOR
            GUICtrlSetCursor(_WinAPI_GetDlgCtrlID($hWnd), 2);; 5 set Ibeam cursor , 2 set to arrow
            Return 1;;and don't let default windowproc mess things up
    EndSwitch

    ;pass the unhandled messages to default WindowProc
    Return _WinAPI_CallWindowProc($wProcOld3, $hWnd, $uiMsg, $wParam, $lParam)
EndFunc   ;==>_MyWindowProc3

Func GetAdminGui($iid)
    GUISetState(@SW_SHOW, $adminGUI)
    ;#cs
    While 1
        $msg_admin = GUIGetMsg()
        
        If $msg_admin = $GUI_EVENT_CLOSE Then
            GUISetState(@SW_HIDE, $adminGUI)
            GUIDelete($adminGUI)
        EndIf

    WEnd
    ;#ce
    ;MsgBox('', '$iid', $iid)
EndFunc   ;==>GetAdminGui

Func GetAdminGui2($iid)
    MsgBox('', '$iid', $iid)
    GetAdminGui($iid)
EndFunc   ;==>GetAdminGui2
Edited by nitekram

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

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