Jump to content

Recommended Posts

Screenshot attached!

I have a background image where all the buildings are black. When the distribution switches in the buildings respond to a ping, the buildings turn green.

Dim $hImgMain = GUICtrlCreatePic("img\fullmap-nologo.gif",0,0,768,635)

Dim $hImgAud = GUICtrlCreatePic("",263,287,36,27)
Dim $hImgBus = GUICtrlCreatePic("",181,321,97,28)
Dim $hImgCtr = GUICtrlCreatePic("",181,239,97,82)
...
If ping($sIpAud) Then GUICtrlSetImage($hImgAud,"img\Green-Aud.gif")

I'd like each building to have a context menu:

$hMenuAud = GUICtrlCreateContextMenu($hImgAud)
$hMenuAud1 = GUICtrlCreateMenu("Switch1",$hMenuAud)
$hMenuAud1Tel = GUICtrlCreateMenuItem("Telnet",$hMenuAud1)
$hMenuAud1Web = GUICtrlCreateMenuItem("Web",$hMenuAud1)
$hMenuAud2 = GUICtrlCreateMenu("Switch2",$hMenuAud)
$hMenuAud2Tel = GUICtrlCreateMenuItem("Telnet",$hMenuAud2)
$hMenuAud2Web = GUICtrlCreateMenuItem("Web",$hMenuAud2)

but the menus don't show up. Neither do tooltips. I'm sure this is something simple, but I've never really done anything like this before.

Thanks!

post-70170-0-86163800-1363116656_thumb.p

Link to comment
Share on other sites

Example for context menu:

#include <WinAPI.au3>
#include <WindowsConstants.au3>
Opt('GUIOnEventMode', 1)

Global $hGUI = GUICreate("Test context on pic", 320, 70)
GUISetOnEvent(-3, '_Exit')

Global $nHelpContext = GUICtrlCreateContextMenu(GUICtrlCreateDummy())
Global $hHelpContext = GUICtrlGetHandle(-1)

Global $HelpWWW = GUICtrlCreateMenuItem("&Website", $nHelpContext)
GUICtrlSetOnEvent(-1, '_Website')
GUICtrlCreateMenuItem("", $nHelpContext)
Global $HelpAbout = GUICtrlCreateMenuItem("&About...", $nHelpContext)
GUICtrlSetOnEvent(-1, '_About')

GUIRegisterMsg($WM_CONTEXTMENU, "WM_CONTEXTMENU")

Global $nPic = GUICtrlCreatePic(@SystemDir & "\oobe\images\mslogo.jpg", 10, 10, 300, 50)

GUISetState()

While 1
    Sleep(100000)
WEnd

Func _Exit()
    Exit
EndFunc   ;==>_Exit

Func _About()
    MsgBox(64, "About...", "Example für context menu")
EndFunc   ;==>_About

Func _Website()
    MsgBox(64, "Website...", "www.autoit.de")
EndFunc   ;==>_Website

Func WM_CONTEXTMENU($hWnd, $iMsg, $iwParam, $ilParam)
    Local $IDCtrl = _WinAPI_GetDlgCtrlID($iwParam)
    Local $x = BitAND($ilParam, 0x0000FFFF), $y = BitShift($ilParam, 16)
    Switch $IDCtrl
        Case $nPic
            TrackPopupMenu($hWnd, $hHelpContext, $x, $y)
    EndSwitch
EndFunc   ;==>WM_CONTEXTMENU

Func TrackPopupMenu($hWnd, $hMenu, $x, $y)
    ConsoleWrite($x & @CRLF)
    ConsoleWrite($y & @CRLF)
    DllCall("user32.dll", "int", "TrackPopupMenuEx", "hwnd", $hMenu, "int", 0, "int", $x, "int", $y, "hwnd", $hWnd, "ptr", 0)
EndFunc   ;==>TrackPopupMenu

Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs, and the Universe
trying to produce bigger and better idiots.
So far, the Universe is winning.

Link to comment
Share on other sites

I'm sorry, I was asking the wrong question.

Funkey, while your example works, it didn't really help with the issue I was having. (And a bit complex for a simple menu, eh?)

I hadn't tried it, but Context menus were working fine if I attached them to my main background image ($hImgMain). After a little further reading in the help file, I realized that a background image needs to be disabled, so I just needed to add GUICtrlSetState($hImgMain,$GUI_DISABLE)

Thanks!

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

×
×
  • Create New...