Sign in to follow this  
Followers 0
Burgs

Cannot 'click' multiple images?

2 posts in this topic

Greetings,

I am having trouble using multiple images set on a background GUI. Refering to the attached working code I have 2 GUI's setup, a "Main" interface window and another window called "Map Selector" which sets a background image as a 'map'. On this map I have created a bunch of images called "BEACON" which are simply little 'cross/plus sign' markers. In addition to these I am creating images that are referred to as "UNITS".

Basically what the problem is that only the "BEACON" images can be 'clicked' upon, while for some strange reason the "UNITS" cannot be...I have tried using the "GUI_DISABLE" for the "BEACON" controls and 'enabling' only the "UNITS" images however this had no effect.

How is it possible to be able to click upon any/all images in the GUI? I'm sure it is probably something relatively simple however I cannot figure it...I thought I had this coded correctly for handling what I needed to do (using the 'advanced' option of the GUIGetMsg command) .

Any suggestions greatly appreciated. Thank you in advance...

#include <EditConstants.au3>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <GuiComboBoxEx.au3>
#include <GUIConstantsEx.au3>
#include <GuiButton.au3>
#include <ButtonConstants.au3>
#include <Array.au3>
#include <File.au3>
#include <GDIPlus.au3>
#include <GUIScrollBars_Size.au3>
#include <ScreenCapture.au3>

Global $BEACON[2586] ;2586 BEACONS on a 2048x2048 map...
Global $UNITS[1000] ;Maximum # of 'UNITS' is 1000...
Global $X_ROWS[1] ;set the # of "X_ROWS" on the map...this array will 'grow' with "Array_Add"...used to aid in the location of a HEX...
Global $Y_COLUMNS[1] ;set the # of "Y_COLUMNS" on the map...this array will 'grow' with "Array_Add"...used to aid in the location of a HEX...
Global $X_POSITION = 236.75
Global $Y_POSITION = 233
Global $aSB_Size_MapBack, $aSB_Size_MiniBack
Global $hGUI
Global $Z = 1
Global $_KILLER = 0 ;'force' a disable of the 'BEACONS' regardless of 'Map Selector' Window status

Global $MapFile = "C:\Program Files\EMW\Folders\Maps\LargeX.jpg" ;2048 x 2048 image
Global $MainGUI = GUICreate("Main Window", 425, 540, 450, 250)
GUISetState(@SW_SHOW)

$Detail_Button = GUICtrlCreateButton("Details", 315, 430, 100, 30, $BS_PUSHLIKE)
GUICtrlSetState($Detail_Button, $GUI_SHOW)
$Select_Button = GUICtrlCreateButton("Show Map", 315, 480, 100, 30, $BS_PUSHLIKE)
GUICtrlSetState($Select_Button, $GUI_DISABLE)

Map_Window()

GUIRegisterMsg($WM_HSCROLL, "WM_HSCROLL")
GUIRegisterMsg($WM_VSCROLL, "WM_VSCROLL")

$font = "Arial"

$Info_TXT1 = GUICtrlCreateLabel("", 10, 386, 100, 20, BitOr($GUI_SS_DEFAULT_LABEL, $SS_LEFT), -1)
GUICtrlSetBkColor($Info_TXT1, $GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetFont($Info_TXT1, 8.5, 400, 1, $font)
GUICtrlSetState($Info_TXT1, $GUI_HIDE)

While 1

$nMsg = GUIGetMsg(1) ;use advanced mode when using multiple GUIs
Switch $nMsg[1] ;Switch on the GUI sending the message

     Case $MapBack
         Switch $nMsg[0]

             Case $BEACON[0] To $BEACON[2585]
                 For $i = 1 To UBound($BEACON) - 1
                 if $nMsg[0] = $BEACON[$i] Then
                 MsgBox(0, "Clicked " & $i, "")
                 ExitLoop
                 EndIf
                 Next

             Case $UNITS[0] To $UNITS[999]   ;**Problem is here, this 'Case' is not functioning when UNITS are clicked
                 For $i = 1 To UBound($UNITS) - 1
                 if $nMsg[0] = $UNITS[$i] Then
                 GUISwitch($MapBack)
                 MsgBox(0, "Clicked Unit #" & $i, "")
                 if $i >= 500 Then GUICtrlSetData($Info_TXT1, "Unit is 'grouped' in the second batch ")
                GUICtrlSetState($Info_TXT1, $GUI_SHOW)
                Sleep(7000)
                GUICtrlSetState($Info_TXT1, $GUI_HIDE)
                GUISwitch($MainGUI) ;set the focus back to the Main Interface...
                ExitLoop
                EndIf
                Next
         EndSwitch

     Case $MainGUI
         Switch $nMsg[0] ; switch on the control from the GUI sending the message.

             Case $GUI_EVENT_CLOSE
                 Exit

             Case $Select_Button
             $_Map_Status = WinGetState("Map Selector") ;determine Map 'Selector' display status...
             Restore_Beacons()

                 if BitAND($_Map_Status, 2) Then
                 WinSetState("Map Selector", "", @SW_MINIMIZE)
                 Sleep(1000)    
                 WinMove("Main", "", 450, 250, 425) ;, 540, 10
                 EndIf ;$_Map_Status is 'visible')...toggle 'OFF'

                 if BitAND($_Map_Status, 16) Then
                 WinMove("Main", "", 50, 250, 425) ;, 540, 10
                 WinSetState("Map Selector", "", @SW_RESTORE)   
                 EndIf ;$_Map_Status is 'minimized')...toggle 'ON'

             Case $Detail_Button
             GUICtrlSetState($Detail_Button, $GUI_DISABLE)
             ;**LOAD/CREATE THE IMAGE TO THE MAP FOR VIEWING...
             GUISwitch($MapBack)
             $X_POSITION -= 12.5
             $Y_POSITION -= 13.5 ;'center' the unit counter in the HEX...
             $UNITS[$Z] = GUICtrlCreatePic("C:\Program Files\EMW\Counter2.gif", $X_POSITION, $Y_POSITION, 35, 35, $SS_NOTIFY) ;35 x 35 image
             GuiCtrlSetState($UNITS[$Z], $GUI_DISABLE)
             GuiCtrlSetState($UNITS[$Z], $GUI_SHOW)

             $Z += 1 ;increment for next unit creation...
             GUISwitch($MainGUI) ;set the focus back to the Main Interface...
             GUICtrlSetState($Select_Button, $GUI_ENABLE)

         EndSwitch
EndSwitch

Wend

Func Map_Window()

; get parameters for this GUI
$aSB_Size_MapBack = _GUIScrollbars_Size(2048, 2048, 768, 576)
Global $MapBack = GUICreate("Map Selector", 768, 576, 485, 250, BitOR($WS_MINIMIZE, $WS_CAPTION, $WS_EX_LAYERED), -1)

; background picture
Global $TheMap = GUICtrlCreatePic($MapFile, 9, 0, 2048, 2048, -1, -1)
GUICtrlSetState($TheMap, $GUI_DISABLE) ; you have to disable the graphic or it overlaps all controls on it

_GUIScrollBars_Init($MapBack)
_GUIScrollBars_SetScrollInfoMax($MapBack, $SB_HORZ, $aSB_Size_MapBack[1])
_GUIScrollBars_SetScrollInfoPage($MapBack, $SB_HORZ, $aSB_Size_MapBack[0])
_GUIScrollBars_SetScrollInfoMax($MapBack, $SB_VERT, $aSB_Size_MapBack[3])
_GUIScrollBars_SetScrollInfoPage($MapBack, $SB_VERT, $aSB_Size_MapBack[2])
GUISetState(@SW_SHOW)

;****PLACE 'BEACONS' (Cross.gif) ON MAP...

;**MAP HEXES...(2048 x 2048 pixels)...
;55 HEXES 'across' ($MAP_COLUMNS)
;47 HEXES 'up/down'
;**'CROSSES'
;11 x 11 pixels (Cross.gif, Cross2.gif)...
;**


Local $MAP_COLUMNS = 0 ;COLUMNS starting at "1st" COLUMN...
Local $MARK_COUNT = 1
Local $HEX_COUNT = 0
Local $MARK_mover = 1 ;determine "odd" or "even" column...0 = EVEN, 1 = ODD
Local $MARK_MAX = 47 ;47 HEXES 'up/down'...
Local $X_adjust = 36
Local $Y_adjust = 42
Local $MARK_X_START = 56.75 ;start X PLOT for "1st" BEACON...49.75
Local $MARK_Y_START = 44 ;start Y PLOT for "1st" BEACON...44
Local $MARK_X_PLOT = $MARK_X_START
Local $MARK_Y_PLOT = $MARK_Y_START

For $x = 1 To UBound($BEACON) - 1
if $x == 1 Then
$MARK_Y_PLOT = 43
$X_ROWS[0] = $MARK_X_START ;store the "1st X_ROW" PLOT...
$Y_COLUMNS[0] = $MARK_Y_START ;store the "1st Y_COLUMN" PLOT...
EndIf ;$x is 1...make certain adjustments for "1st" PLOT...
if $x <> 1 Then
if $MARK_COUNT <= $MARK_MAX Then
$MARK_Y_PLOT += $Y_adjust
     if $MAP_COLUMNS == 4 Then _ArrayAdd($Y_COLUMNS, $MARK_Y_PLOT) ;add 'new' row to "Y_COLUMNS" array...beginning/ending only with the "4th" COLUMN sample...
EndIf ;$MARK_COUNT <= $MARK_MAX (add another Cross "below"...)
     if $MARK_COUNT > $MARK_MAX Then
     $MAP_COLUMNS += 1 ;increment
     $MARK_X_PLOT = $MARK_X_START + ($X_adjust * $MAP_COLUMNS)
     _ArrayAdd($X_ROWS, $MARK_X_PLOT) ;add 'new' row to "X_ROWS" array...
     $MARK_Y_PLOT = $MARK_Y_START
     $MARK_mover += 1
     $MARK_COUNT = 1 ;reset each COLUMN...
     if $MARK_mover > 1 Then $MARK_mover = 0
     if $MARK_mover == 0 Then $MARK_Y_PLOT += ($Y_adjust / 2)
     EndIf ;$MARK_COUNT > $MARK_MAX (begin a new column...)
EndIf ;$x NOT 1
$MARK_COUNT += 1 ;increase HEX COLUMN counter...
$HEX_COUNT += 1 ;increase total # of HEXES count...
$BEACON[$x] = GUICtrlCreatePic("C:\Program Files\EMW\System\Cross.gif", $MARK_X_PLOT, $MARK_Y_PLOT, 11, 11, $SS_NOTIFY) ;11 x 11 image
GuiCtrlSetState($BEACON[$x], $GUI_DISABLE)

Next
;****
EndFunc ;==>Map_Window

Func Restore_Beacons()

$_Map_Status = WinGetState("Map Selector")
;adjust BEACON 'enabling' based upon Map 'Selector' display...

if BitAND($_Map_Status, 2) OR $_KILLER == 1 Then
For $x = 1 To UBound($BEACON) - 1
GuiCtrlSetState($BEACON[$x], $GUI_DISABLE)
Next
EndIf ;$_Map_Status is 'visible')...OR $_KILLER is 1 ('force' a BEACON disable)...

if BitAND($_Map_Status, 2) Then
For $x = 1 To UBound($UNITS) - 1
GuiCtrlSetState($UNITS[$x], $GUI_DISABLE)
Next
EndIf ;$_Map_Status is 'visible')...

if BitAND($_Map_Status, 16) AND $_KILLER <> 1 Then
For $x = 1 To UBound($BEACON) - 1
GuiCtrlSetState($BEACON[$x], $GUI_ENABLE)
Next
EndIf ;$_Map_Status is 'minimized')...AND $_KILLER NOT 1

if BitAND($_Map_Status, 16) Then
For $x = 1 To UBound($UNITS) - 1
GuiCtrlSetState($UNITS[$x], $GUI_ENABLE)
Next
EndIf ;$_Map_Status is 'minimized')...

EndFunc

;/////////////////
Func WM_HSCROLL($hWnd, $Msg, $wParam, $lParam)
#forceref $Msg, $lParam
Local $nScrollCode = BitAND($wParam, 0x0000FFFF)
Local $iIndex = -1, $xChar, $xPos
Local $Page, $Pos, $TrackPos
For $x = 0 To UBound($aSB_WindowInfo) - 1
     If $aSB_WindowInfo[$x][0] = $hWnd Then
         $iIndex = $x
         $xChar = $aSB_WindowInfo[$iIndex][2]
         ExitLoop
     EndIf
Next
If $iIndex = -1 Then Return 0
Local $tSCROLLINFO = _GUIScrollBars_GetScrollInfoEx($hWnd, $SB_HORZ)
$Page = DllStructGetData($tSCROLLINFO, "nPage")
$xPos = DllStructGetData($tSCROLLINFO, "nPos")
$Pos = $xPos
$TrackPos = DllStructGetData($tSCROLLINFO, "nTrackPos")
Switch $nScrollCode
     Case $SB_LINELEFT
         DllStructSetData($tSCROLLINFO, "nPos", $Pos - 1)
     Case $SB_LINERIGHT
         DllStructSetData($tSCROLLINFO, "nPos", $Pos + 1)
     Case $SB_PAGELEFT
         DllStructSetData($tSCROLLINFO, "nPos", $Pos - $Page)
     Case $SB_PAGERIGHT
         DllStructSetData($tSCROLLINFO, "nPos", $Pos + $Page)
     Case $SB_THUMBTRACK
         DllStructSetData($tSCROLLINFO, "nPos", $TrackPos)
EndSwitch
DllStructSetData($tSCROLLINFO, "fMask", $SIF_POS)
_GUIScrollBars_SetScrollInfo($hWnd, $SB_HORZ, $tSCROLLINFO)
_GUIScrollBars_GetScrollInfo($hWnd, $SB_HORZ, $tSCROLLINFO)
; Move the scrollbar
$Pos = DllStructGetData($tSCROLLINFO, "nPos")
If ($Pos <> $xPos) Then _GUIScrollBars_ScrollWindow($hWnd, $xChar * ($xPos - $Pos), 0)
; Now move other scrollbar
Switch $hWnd
     Case $MapBack
         ; get fractional position of scrollbar in moved GUI
         $nPos_HORZ = _GUIScrollBars_GetScrollInfoPos($MapBack, $SB_HORZ)
         $nFraction_HORZ = $nPos_HORZ / ($aSB_Size_MapBack[1] - $aSB_Size_MapBack[0])
         ; And set other scrollbar to same fraction
         ;_GUIScrollBars_SetScrollInfoPos($MiniBack, $SB_HORZ, ($aSB_Size_MiniBack[1] - $aSB_Size_MiniBack[0]) * $nFraction_HORZ)
     ;Case $MiniBack
     ; $nPos_HORZ = _GUIScrollBars_GetScrollInfoPos($MiniBack, $SB_HORZ)
     ; $nFraction_HORZ = $nPos_HORZ / ($aSB_Size_MiniBack[1] - $aSB_Size_MiniBack[0])
     ; _GUIScrollBars_SetScrollInfoPos($MapBack, $SB_HORZ, ($aSB_Size_MapBack[1] - $aSB_Size_MapBack[0]) * $nFraction_HORZ)
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_HSCROLL

Func WM_VSCROLL($hWnd, $Msg, $wParam, $lParam)
#forceref $Msg, $lParam
Local $nScrollCode = BitAND($wParam, 0x0000FFFF)
Local $iIndex = -1, $yChar, $yPos
Local $Page, $Pos, $TrackPos
For $x = 0 To UBound($aSB_WindowInfo) - 1
     If $aSB_WindowInfo[$x][0] = $hWnd Then
         $iIndex = $x
         $yChar = $aSB_WindowInfo[$iIndex][3]
         ExitLoop
     EndIf
Next
If $iIndex = -1 Then Return 0
Local $tSCROLLINFO = _GUIScrollBars_GetScrollInfoEx($hWnd, $SB_VERT)
$Page = DllStructGetData($tSCROLLINFO, "nPage")
$yPos = DllStructGetData($tSCROLLINFO, "nPos")
$Pos = $yPos
$TrackPos = DllStructGetData($tSCROLLINFO, "nTrackPos")
Switch $nScrollCode
     Case $SB_LINEUP
         DllStructSetData($tSCROLLINFO, "nPos", $Pos - 1)
     Case $SB_LINEDOWN
         DllStructSetData($tSCROLLINFO, "nPos", $Pos + 1)
     Case $SB_PAGEUP
         DllStructSetData($tSCROLLINFO, "nPos", $Pos - $Page)
     Case $SB_PAGEDOWN
         DllStructSetData($tSCROLLINFO, "nPos", $Pos + $Page)
     Case $SB_THUMBTRACK
         DllStructSetData($tSCROLLINFO, "nPos", $TrackPos)
EndSwitch
DllStructSetData($tSCROLLINFO, "fMask", $SIF_POS)
_GUIScrollBars_SetScrollInfo($hWnd, $SB_VERT, $tSCROLLINFO)
_GUIScrollBars_GetScrollInfo($hWnd, $SB_VERT, $tSCROLLINFO)
; Move the scrollbar
$Pos = DllStructGetData($tSCROLLINFO, "nPos")
If ($Pos <> $yPos) Then _GUIScrollBars_ScrollWindow($hWnd, 0, $yChar * ($yPos - $Pos))
; Now move other scrollbar
Switch $hWnd
     Case $MapBack
         ; get fractional position of scrollbar in moved GUI
         $nPos_VERT = _GUIScrollBars_GetScrollInfoPos($MapBack, $SB_VERT)
         $nFraction_VERT = $nPos_VERT / ($aSB_Size_MapBack[1] - $aSB_Size_MapBack[0])
         ; And set other scrollbar to same fraction
         ;_GUIScrollBars_SetScrollInfoPos($MiniBack, $SB_VERT, ($aSB_Size_MiniBack[1] - $aSB_Size_MiniBack[0]) * $nFraction_VERT)
     ;Case $MiniBack
     ; $nPos_VERT = _GUIScrollBars_GetScrollInfoPos($MiniBack, $SB_VERT)
     ; $nFraction_VERT = $nPos_VERT / ($aSB_Size_MiniBack[1] - $aSB_Size_MiniBack[0])
     ; _GUIScrollBars_SetScrollInfoPos($MapBack, $SB_VERT, ($aSB_Size_MapBack[1] - $aSB_Size_MapBack[0]) * $nFraction_VERT)
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_VSCROLL

Share this post


Link to post
Share on other sites



Hello,

Can somebody please explain how it is possible to 'click through' an image to another 'underneath' it? For example if I have 'Image A' that is loaded into the GUI using the 'GUICtrlCreatePic' command and it is placed to completely cover another 'image B' (because 'Image B' is smaller than 'Image A') how is it possible that I can click on 'Image B' and not 'Image A'? If I could find an answer to that it is probably related to my problem...

Alternatively can somebody direct me to an AutoIT script that is handling multiple images from multiple GUI's...I'd like to take a look at that. Thanks in advance.

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