Jump to content

Problem with Context menu.


DarkAqua
 Share

Recommended Posts

I am making a script to create a list of currently open windows of a specified program with program icons similar to windows preview when you point your mouse at a running program on your task bar which brings up a list of open windows for that program. Each window in this list will have a separate context menu upon right click. I have everything working great but the items in the context menu are giving me grief. When i open the context menu and try to click a menu item it does not create a message box that i have specified in the script for testing them. I thought i would have you guys take a look at the script and see what you though might be the problem. Note: This is extremely experimental script.

#include <Array.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <MsgBoxConstants.au3>

GUICreation()

Windowcheck()

Func GUICreation()
    Opt("GUIOnEventMode", 1)
    $app = 'google'
    Global $path = "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"
    $wintitle = "[REGEXPTITLE:(?i)(.*" & $app & "*)]"
    Global $list = WinList($wintitle)
    $WinNum = $list[0][0] * 20
    $GUI = GUICreate("List Windows", 300, $WinNum, -1, -1, $WS_POPUP)
    Global $end = 0
    GUISetState(@SW_SHOW)
EndFunc

Func Windowcheck()
    Switch $list[0][0]
       Case 1
          $1 = GUICtrlCreateLabel($list[1][0], 20, 5)
          GUICtrlCreateIcon($path, -1, 0, 0, 20, 20)
          GUICtrlSetCursor($1,0)
          GUICtrlSetOnEvent($1, "item1")
          $i1m = GUICtrlCreateContextMenu($1)
          Global $id1 = GUICtrlCreateMenuItem("Minimize", $i1m)
          Global $id2 = GUICtrlCreateMenuItem("Restore", $i1m)
       Case 2
          $1 = GUICtrlCreateLabel($list[1][0], 20, 5)
          GUICtrlCreateIcon($path, -1, 0, 0, 20, 20)
          GUICtrlSetCursor($1,0)
          GUICtrlSetOnEvent($1, "item1")
          $i1m = GUICtrlCreateContextMenu($1)
          Global $id1 = GUICtrlCreateMenuItem("Minimize", $i1m)
          Global $id2 = GUICtrlCreateMenuItem("Restore", $i1m)
          $2 = GUICtrlCreateLabel($list[2][0], 20, 25)
          GUICtrlCreateIcon($path, -1, 0, 20, 20, 20)
          GUICtrlSetCursor($2,0)
          GUICtrlSetOnEvent($2, "item2")
          $i2m = GUICtrlCreateContextMenu($2)
          Global $id1 = GUICtrlCreateMenuItem("2", $i2m)
    EndSwitch
EndFunc

While 1
    Switch GUIGetMsg()
       Case $id1
          MsgBox($MB_SYSTEMMODAL, "Test", "Minimize Clicked")
       Case $id2
          MsgBox($MB_SYSTEMMODAL, "Test", "Restore Clicked")
    EndSwitch
WEnd

This script is made to show google chrome windows currently.

I have looked at the example script in the function documentation for the context menu and it works great but i cant seem to decipher why the example works and mine does not. Example script provided below.

; right click on gui to bring up context Menu.
; right click on the "ok" button to bring up a controll specific context menu.

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>

Example()

Func Example()
    GUICreate("My GUI Context Menu", 300, 200)

    Local $idContextmenu = GUICtrlCreateContextMenu()

    Local $idNewsubmenu = GUICtrlCreateMenu("new", $idContextmenu)
    Local $idNewsubmenuText = GUICtrlCreateMenuItem("text", $idNewsubmenu)

    Local $idButton = GUICtrlCreateButton("OK", 100, 100, 70, 20)
    Local $idButtoncontext = GUICtrlCreateContextMenu($idButton)
    Local $idMenuAbout = GUICtrlCreateMenuItem("About button", $idButtoncontext)

    Local $idMenuOpen = GUICtrlCreateMenuItem("Open", $idContextmenu)
    Local $idMenuSave = GUICtrlCreateMenuItem("Save", $idContextmenu)
    GUICtrlCreateMenuItem("", $idContextmenu) ; separator

    Local $idMenuInfo = GUICtrlCreateMenuItem("Info", $idContextmenu)

    GUISetState(@SW_SHOW)

    ; Loop until the user exits.
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $idButton
                MsgBox($MB_SYSTEMMODAL, "Button Clicked", 'OK')
            Case $idMenuAbout
                MsgBox($MB_SYSTEMMODAL, "Menu Selected", 'About')
            Case $idMenuOpen
                MsgBox($MB_SYSTEMMODAL, "Menu Selected", 'Open')
            Case $idMenuSave
                MsgBox($MB_SYSTEMMODAL, "Menu Selected", 'Save')
            Case $idMenuInfo
                MsgBox($MB_SYSTEMMODAL, "Menu Selected", 'Info')
            Case $idNewsubmenuText
                MsgBox($MB_SYSTEMMODAL, "SubMenu Selected", 'Text')
        EndSwitch
    WEnd
    GUIDelete()
EndFunc   ;==>Example

I have also attached the scripts for you guys to download and run directly.

List Windows.au3

Context Menu Example.au3

Link to comment
Share on other sites

Yur script is not running Global must not be declared in Func

Func Item1 and Item2 are missing , ...

 

I have added the changes you gave me but i am still unable to get the context menu items to work properly. New script below.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <MsgBoxConstants.au3>

Opt("GUIOnEventMode", 1)
$app = 'google'
$path = "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"
$wintitle = "[REGEXPTITLE:(?i)(.*" & $app & "*)]"
$list = WinList($wintitle)
$WinNum = $list[0][0] * 20
$GUI = GUICreate("List Windows", 300, $WinNum, -1, -1, $WS_POPUP)
$end = 0
GUISetState(@SW_SHOW)

Switch $list[0][0]
    Case 1
       $1 = GUICtrlCreateLabel($list[1][0], 20, 5)
       GUICtrlCreateIcon($path, -1, 0, 0, 20, 20)
       $m1 = GUICtrlCreateContextMenu($1)
       $m1i1 = GUICtrlCreateMenuItem("Minimize", $m1)
       $m1i2 = GUICtrlCreateMenuItem("Restore", $m1)
    Case 2
       $1 = GUICtrlCreateLabel($list[1][0], 20, 5)
       GUICtrlCreateIcon($path, -1, 0, 0, 20, 20)
       $m1 = GUICtrlCreateContextMenu($1)
       $m1i1 = GUICtrlCreateMenuItem("Minimize", $m1)
       $m1i2 = GUICtrlCreateMenuItem("Restore", $m1)
       $2 = GUICtrlCreateLabel($list[2][0], 20, 25)
       GUICtrlCreateIcon($path, -1, 0, 20, 20, 20)
       $m2 = GUICtrlCreateContextMenu($2)
       $m2i1 = GUICtrlCreateMenuItem("Minimize2", $m2)
       $m2i2 = GUICtrlCreateMenuItem("Restore2", $m2)
EndSwitch

While 1
    Switch GUIGetMsg()
       Case $m1i1
          MsgBox($MB_SYSTEMMODAL, "Test", "Minimize Clicked")
       Case $m1i2
          MsgBox($MB_SYSTEMMODAL, "Test", "Restore Clicked")
       Case $m2i1
          MsgBox($MB_SYSTEMMODAL, "Test", "Minimize2 Clicked")
       Case $m2i2
          MsgBox($MB_SYSTEMMODAL, "Test", "Restore2 Clicked")
    EndSwitch
WEnd
Edited by DarkAqua
Link to comment
Share on other sites

 

 

I have added the changes you gave me but i am still unable to get the context menu items to work properly. New script below.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <MsgBoxConstants.au3>

Opt("GUIOnEventMode", 1)
$app = 'google'
$path = "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"
$wintitle = "[REGEXPTITLE:(?i)(.*" & $app & "*)]"
$list = WinList($wintitle)
$WinNum = $list[0][0] * 20
$GUI = GUICreate("List Windows", 300, $WinNum, -1, -1, $WS_POPUP)
$end = 0
GUISetState(@SW_SHOW)

Switch $list[0][0]
    Case 1
       $1 = GUICtrlCreateLabel($list[1][0], 20, 5)
       GUICtrlCreateIcon($path, -1, 0, 0, 20, 20)
       $m1 = GUICtrlCreateContextMenu($1)
       $m1i1 = GUICtrlCreateMenuItem("Minimize", $m1)
       $m1i2 = GUICtrlCreateMenuItem("Restore", $m1)
    Case 2
       $1 = GUICtrlCreateLabel($list[1][0], 20, 5)
       GUICtrlCreateIcon($path, -1, 0, 0, 20, 20)
       $m1 = GUICtrlCreateContextMenu($1)
       $m1i1 = GUICtrlCreateMenuItem("Minimize", $m1)
       $m1i2 = GUICtrlCreateMenuItem("Restore", $m1)
       $2 = GUICtrlCreateLabel($list[2][0], 20, 25)
       GUICtrlCreateIcon($path, -1, 0, 20, 20, 20)
       $m2 = GUICtrlCreateContextMenu($2)
       $m2i1 = GUICtrlCreateMenuItem("Minimize2", $m2)
       $m2i2 = GUICtrlCreateMenuItem("Restore2", $m2)
EndSwitch

While 1
    Switch GUIGetMsg()
       Case $m1i1
          MsgBox($MB_SYSTEMMODAL, "Test", "Minimize Clicked")
       Case $m1i2
          MsgBox($MB_SYSTEMMODAL, "Test", "Restore Clicked")
       Case $m2i1
          MsgBox($MB_SYSTEMMODAL, "Test", "Minimize2 Clicked")
       Case $m2i2
          MsgBox($MB_SYSTEMMODAL, "Test", "Restore2 Clicked")
    EndSwitch
WEnd

After Deleting certain parts of the script to try too find the problem i have discovered the statement Opt("GUIOnEventMode", 1) was causing the issue.

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...